Skip to content

Commit

Permalink
Added custom ENV for project resource
Browse files Browse the repository at this point in the history
Resource now receives a new attribute env, in order to specify additional
shell environment variables
  • Loading branch information
pbanderas committed Feb 3, 2016
1 parent 45bcbd5 commit 5cbd114
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
9 changes: 6 additions & 3 deletions providers/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,12 @@ def make_execute(cmd)
optimize = new_resource.optimize_autoloader ? optimize_flag(cmd) : ''
prefer_dist = new_resource.prefer_dist ? '--prefer-dist' : ''
prefer_source = new_resource.prefer_source ? '--prefer-source' : ''
environment = { 'COMPOSER_HOME' => Composer.home_dir(node) }.merge(new_resource.env)

execute "#{cmd}-composer-for-project" do
cwd new_resource.project_dir
command "#{node['composer']['bin']} #{cmd} --no-interaction --no-ansi #{quiet} #{dev} #{optimize} #{prefer_dist} #{prefer_source}"
environment 'COMPOSER_HOME' => Composer.home_dir(node)
environment environment
action :run
only_if 'which composer'
user new_resource.user
Expand All @@ -57,11 +58,12 @@ def make_require
dev = new_resource.dev ? '--dev' : '--update-no-dev'
vendor = new_resource.vendor
prefer_dist = new_resource.prefer_dist ? '--prefer-dist' : ''
environment = { 'COMPOSER_HOME' => Composer.home_dir(node) }.merge(new_resource.env)

execute 'Install-composer-for-single-project' do
cwd new_resource.project_dir
command "#{node['composer']['bin']} require #{vendor} #{dev} #{prefer_dist}"
environment 'COMPOSER_HOME' => Composer.home_dir(node)
environment environment
action :run
only_if 'which composer'
user new_resource.user
Expand All @@ -72,11 +74,12 @@ def make_require

def remove_vendor(cmd)
vendor = new_resource.vendor
environment = { 'COMPOSER_HOME' => Composer.home_dir(node) }.merge(new_resource.env)

execute "#{cmd}-composer-for-project" do
cwd new_resource.project_dir
command "#{node['composer']['bin']} remove #{vendor}"
environment 'COMPOSER_HOME' => Composer.home_dir(node)
environment environment
action :run
only_if 'which composer'
end
Expand Down
1 change: 1 addition & 0 deletions resources/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
attribute :user, :kind_of => String, :default => 'root'
attribute :group, :kind_of => String, :default => 'root'
attribute :umask, :kind_of => [String, Fixnum], :default => 0002
attribute :env, :kind_of => [Hash], :default => {}

def initialize(*args)
super
Expand Down

0 comments on commit 5cbd114

Please sign in to comment.