class PoiseRuby::Resources::RubyGem::Provider

The default provider for `ruby_gem`.

@see Resource @provides ruby_gem

Public Instance Methods

action_install() click to toggle source
Calls superclass method
# File lib/poise_ruby/resources/ruby_gem.rb, line 70
def action_install
  patch_environment { super }
end
action_purge() click to toggle source
Calls superclass method
# File lib/poise_ruby/resources/ruby_gem.rb, line 82
def action_purge
  patch_environment { super }
end
action_reconfig() click to toggle source
Calls superclass method
# File lib/poise_ruby/resources/ruby_gem.rb, line 86
def action_reconfig
  patch_environment { super }
end
action_remove() click to toggle source
Calls superclass method
# File lib/poise_ruby/resources/ruby_gem.rb, line 78
def action_remove
  patch_environment { super }
end
action_upgrade() click to toggle source
Calls superclass method
# File lib/poise_ruby/resources/ruby_gem.rb, line 74
def action_upgrade
  patch_environment { super }
end
define_resource_requirements() click to toggle source
Calls superclass method
# File lib/poise_ruby/resources/ruby_gem.rb, line 66
def define_resource_requirements
  patch_environment { super }
end
load_current_resource() click to toggle source
Calls superclass method
# File lib/poise_ruby/resources/ruby_gem.rb, line 62
def load_current_resource
  patch_environment { super }
end

Private Instance Methods

patch_environment(&block) click to toggle source
# File lib/poise_ruby/resources/ruby_gem.rb, line 92
def patch_environment(&block)
  environment_to_add = if new_resource.parent_ruby
    new_resource.parent_ruby.ruby_environment
  else
    {}
  end

  begin
    if ENV['GEM_HOME'] && !ENV['GEM_HOME'].empty?
      Chef::Log.warn("[#{new_resource}] $GEM_HOME is set in Chef's environment, this will likely interfere with gem installation")
    end
    if ENV['GEM_PATH'] && !ENV['GEM_PATH'].empty?
      Chef::Log.warn("[#{new_resource}] $GEM_PATH is set in Chef's environment, this will likely interfere with gem installation")
    end
    old_vars = environment_to_add.inject({}) do |memo, (key, value)|
      memo[key] = ENV[key]
      ENV[key] = value
      memo
    end
    block.call
  ensure
    old_vars.each do |key, value|
      if value.nil?
        ENV.delete(key)
      else
        ENV[key] = value
      end
    end
  end
end