Class: Chef::Provider::Package::Rubygems
- Inherits:
-
Chef::Provider::Package
- Object
- Chef::Provider
- Chef::Provider::Package
- Chef::Provider::Package::Rubygems
- Defined in:
- lib/chef/provider/package/rubygems.rb
Instance Attribute Summary
Attributes inherited from Chef::Provider
#current_resource, #new_resource, #node
Instance Method Summary collapse
- #candidate_version ⇒ Object
- #gem_binary_path ⇒ Object
- #gem_list_parse(line) ⇒ Object
- #install_package(name, version) ⇒ Object
- #load_current_resource ⇒ Object
- #purge_package(name, version) ⇒ Object
- #remove_package(name, version) ⇒ Object
- #upgrade_package(name, version) ⇒ Object
Methods inherited from Chef::Provider::Package
#action_install, #action_purge, #action_remove, #action_upgrade, #expand_options, #get_preseed_file, #initialize, #preseed_package, #should_remove_package
Methods included from Mixin::Command
chdir_or_tmpdir, handle_command_failures, not_if, only_if, output_of_command, popen4, run_command, run_command_with_systems_locale
Methods inherited from Chef::Provider
#action_nothing, build_from_file, #initialize
Methods included from Mixin::ConvertToClassName
#convert_to_class_name, #convert_to_snake_case, #filename_to_qualified_string, #snake_case_basename
Methods included from Mixin::RecipeDefinitionDSLCore
Methods included from Mixin::Language
#data_bag, #data_bag_item, #platform?, #search, #value_for_platform
Constructor Details
This class inherits a constructor from Chef::Provider::Package
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Chef::Mixin::RecipeDefinitionDSLCore
Instance Method Details
#candidate_version ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/chef/provider/package/rubygems.rb', line 72 def candidate_version return @candidate_version if @candidate_version status = popen4("#{gem_binary_path} list --remote #{@new_resource.package_name}#{' --source=' + @new_resource.source if @new_resource.source}") do |pid, stdin, stdout, stderr| stdout.each_line do |line| next unless installed_versions = gem_list_parse(line) Chef::Log.debug("candidate_version: remote rubygem(s) available: #{installed_versions.inspect}") unless installed_versions.empty? Chef::Log.debug("candidate_version: setting install candidate version to #{installed_versions.first}") @candidate_version = installed_versions.first end end end unless status.exitstatus == 0 raise Chef::Exceptions::Package, "#{gem_binary_path} list --remote failed - #{status.inspect}!" end @candidate_version end |
#gem_binary_path ⇒ Object
37 38 39 40 |
# File 'lib/chef/provider/package/rubygems.rb', line 37 def gem_binary_path path = @new_resource.gem_binary path ? path : 'gem' end |
#gem_list_parse(line) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/chef/provider/package/rubygems.rb', line 28 def gem_list_parse(line) installed_versions = Array.new if md = line.match(/^#{@new_resource.package_name} \((.+?)(?: [^\)\.]+)?\)$/) md.captures.first.split(/, /) else nil end end |
#install_package(name, version) ⇒ Object
94 95 96 97 98 99 100 101 102 |
# File 'lib/chef/provider/package/rubygems.rb', line 94 def install_package(name, version) src = nil if @new_resource.source src = " --source=#{@new_resource.source} --source=http://rubygems.org" end run_command_with_systems_locale( :command => "#{gem_binary_path} install #{name} -q --no-rdoc --no-ri -v \"#{version}\"#{src}#{opts}" ) end |
#load_current_resource ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/chef/provider/package/rubygems.rb', line 42 def load_current_resource @current_resource = Chef::Resource::Package.new(@new_resource.name) @current_resource.package_name(@new_resource.package_name) @current_resource.version(nil) # First, we need to look up whether we have the local gem installed or not status = popen4("#{gem_binary_path} list --local #{@new_resource.package_name}") do |pid, stdin, stdout, stderr| stdout.each_line do |line| next unless installed_versions = gem_list_parse(line) # If the version we are asking for is installed, make that our current # version. Otherwise, go ahead and use the highest one, which # happens to come first in the array. if installed_versions.detect { |v| v == @new_resource.version } Chef::Log.debug("#{@new_resource.package_name} at version #{@new_resource.version}") @current_resource.version(@new_resource.version) else iv = installed_versions.first Chef::Log.debug("#{@new_resource.package_name} at version #{iv}") @current_resource.version(iv) end end end unless status.exitstatus == 0 raise Chef::Exceptions::Package, "#{gem_binary_path} list --local failed - #{status.inspect}!" end @current_resource end |
#purge_package(name, version) ⇒ Object
120 121 122 |
# File 'lib/chef/provider/package/rubygems.rb', line 120 def purge_package(name, version) remove_package(name, version) end |
#remove_package(name, version) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/chef/provider/package/rubygems.rb', line 108 def remove_package(name, version) if version run_command_with_systems_locale( :command => "#{gem_binary_path} uninstall #{name} -q -v \"#{version}\"" ) else run_command_with_systems_locale( :command => "#{gem_binary_path} uninstall #{name} -q -a" ) end end |
#upgrade_package(name, version) ⇒ Object
104 105 106 |
# File 'lib/chef/provider/package/rubygems.rb', line 104 def upgrade_package(name, version) install_package(name, version) end |