Class: Chef::Provider::Package::Rubygems
Defined Under Namespace
Classes: AlternateGemEnvironment, CurrentGemEnvironment, GemEnvironment
Instance Attribute Summary collapse
#current_resource, #new_resource, #run_context
Instance Method Summary
collapse
#shell_out, #shell_out!
#action_install, #action_purge, #action_remove, #action_upgrade, #expand_options, #get_preseed_file, #preseed_package, #preseed_resource, #removing_package?
#chdir_or_tmpdir, #handle_command_failures, #not_if, #only_if, #output_of_command, #run_command, #run_command_with_systems_locale
#popen4
#popen4
#action_nothing, build_from_file, #cookbook_name, #node, #resource_collection
#convert_to_class_name, #convert_to_snake_case, #filename_to_qualified_string, #snake_case_basename
#method_missing
#data_bag, #data_bag_item, #platform?, #search, #value_for_platform
Constructor Details
#initialize(new_resource, run_context = nil) ⇒ Rubygems
Returns a new instance of Rubygems.
309
310
311
312
313
314
315
316
317
318
319
320
321
|
# File 'lib/chef/provider/package/rubygems.rb', line 309
def initialize(new_resource, run_context=nil)
super
if new_resource.gem_binary
if new_resource.options && new_resource.options.kind_of?(Hash)
msg = "options cannot be given as a hash when using an explicit gem_binary\n"
msg << "in #{new_resource} from #{new_resource.source_line}"
raise ArgumentError, msg
end
@gem_env = AlternateGemEnvironment.new(new_resource.gem_binary)
else
@gem_env = CurrentGemEnvironment.new
end
end
|
Instance Attribute Details
#gem_env ⇒ Object
Returns the value of attribute gem_env.
303
304
305
|
# File 'lib/chef/provider/package/rubygems.rb', line 303
def gem_env
@gem_env
end
|
Instance Method Details
#all_installed_versions ⇒ Object
356
357
358
359
360
|
# File 'lib/chef/provider/package/rubygems.rb', line 356
def all_installed_versions
@all_installed_versions ||= begin
@gem_env.installed_versions(Gem::Dependency.new(gem_dependency.name, '>= 0'))
end
end
|
#candidate_version ⇒ Object
375
376
377
378
379
380
381
382
383
384
385
|
# File 'lib/chef/provider/package/rubygems.rb', line 375
def candidate_version
@candidate_version ||= begin
if target_version_already_installed?
nil
elsif source_is_remote?
@gem_env.candidate_version_from_remote(gem_dependency, *gem_sources).to_s
else
@gem_env.candidate_version_from_file(gem_dependency, @new_resource.source).to_s
end
end
end
|
#current_version ⇒ Object
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
|
# File 'lib/chef/provider/package/rubygems.rb', line 332
def current_version
if !matching_installed_versions.empty?
gemspec = matching_installed_versions.last
logger.debug { "Found installed gem #{gemspec.name} version #{gemspec.version} matching #{gem_dependency}"}
gemspec
elsif !all_installed_versions.empty?
gemspec = all_installed_versions.last
logger.debug { "Newest installed version of gem #{gemspec.name} is #{gemspec.version}" }
gemspec
else
logger.debug { "No installed version found for #{gem_dependency.to_s}"}
nil
end
end
|
#gem_binary_path ⇒ Object
421
422
423
|
# File 'lib/chef/provider/package/rubygems.rb', line 421
def gem_binary_path
@new_resource.gem_binary || 'gem'
end
|
#gem_dependency ⇒ Object
323
324
325
|
# File 'lib/chef/provider/package/rubygems.rb', line 323
def gem_dependency
Gem::Dependency.new(@new_resource.package_name, @new_resource.version)
end
|
#gem_sources ⇒ Object
362
363
364
|
# File 'lib/chef/provider/package/rubygems.rb', line 362
def gem_sources
@new_resource.source ? [@new_resource.source, 'http://rubygems.org'] : nil
end
|
#install_package(name, version) ⇒ Object
Installs the gem, using either the gems API or shelling out to ‘gem` according to the following criteria:
-
Use gems API (Gem::DependencyInstaller) by default
-
shell out to ‘gem install` when a String of options is given
-
use gems API with options if a hash of options is given
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
|
# File 'lib/chef/provider/package/rubygems.rb', line 402
def install_package(name, version)
if source_is_remote? && @new_resource.gem_binary.nil?
if @new_resource.options.nil?
@gem_env.install(gem_dependency, :sources => gem_sources)
elsif @new_resource.options.kind_of?(Hash)
options = @new_resource.options
options[:sources] = gem_sources
@gem_env.install(gem_dependency, options)
else
install_via_gem_command(name, version)
end
elsif @new_resource.gem_binary.nil?
@gem_env.install(@new_resource.source)
else
install_via_gem_command(name,version)
end
true
end
|
#install_via_gem_command(name, version) ⇒ Object
425
426
427
428
|
# File 'lib/chef/provider/package/rubygems.rb', line 425
def install_via_gem_command(name, version)
src = @new_resource.source && " --source=#{@new_resource.source} --source=http://rubygems.org"
shell_out!("#{gem_binary_path} install #{name} -q --no-rdoc --no-ri -v \"#{version}\"#{src}#{opts}", :env=>nil)
end
|
#load_current_resource ⇒ Object
366
367
368
369
370
371
372
373
|
# File 'lib/chef/provider/package/rubygems.rb', line 366
def load_current_resource
@current_resource = Chef::Resource::Package::GemPackage.new(@new_resource.name)
@current_resource.package_name(@new_resource.package_name)
if current_spec = current_version
@current_resource.version(current_spec.version.to_s)
end
@current_resource
end
|
#logger ⇒ Object
305
306
307
|
# File 'lib/chef/provider/package/rubygems.rb', line 305
def logger
Chef::Log.logger
end
|
#matching_installed_versions ⇒ Object
352
353
354
|
# File 'lib/chef/provider/package/rubygems.rb', line 352
def matching_installed_versions
@matching_installed_versions ||= @gem_env.installed_versions(gem_dependency)
end
|
#purge_package(name, version) ⇒ Object
456
457
458
|
# File 'lib/chef/provider/package/rubygems.rb', line 456
def purge_package(name, version)
remove_package(name, version)
end
|
#remove_package(name, version) ⇒ Object
434
435
436
437
438
439
440
441
442
443
444
445
446
|
# File 'lib/chef/provider/package/rubygems.rb', line 434
def remove_package(name, version)
if @new_resource.gem_binary.nil?
if @new_resource.options.nil?
@gem_env.uninstall(name, version)
elsif @new_resource.options.kind_of?(Hash)
@gem_env.uninstall(name, version, @new_resource.options)
else
uninstall_via_gem_command(name, version)
end
else
uninstall_via_gem_command(name, version)
end
end
|
#source_is_remote? ⇒ Boolean
327
328
329
330
|
# File 'lib/chef/provider/package/rubygems.rb', line 327
def source_is_remote?
return true if @new_resource.source.nil?
URI.parse(@new_resource.source).absolute?
end
|
#target_version_already_installed? ⇒ Boolean
387
388
389
390
391
392
393
394
|
# File 'lib/chef/provider/package/rubygems.rb', line 387
def target_version_already_installed?
return false unless @current_resource && @current_resource.version
return false if @current_resource.version.nil?
Gem::Requirement.new(@new_resource.version).satisfied_by?(Gem::Version.new(@current_resource.version))
end
|
#uninstall_via_gem_command(name, version) ⇒ Object
448
449
450
451
452
453
454
|
# File 'lib/chef/provider/package/rubygems.rb', line 448
def uninstall_via_gem_command(name, version)
if version
shell_out!("#{gem_binary_path} uninstall #{name} -q -x -I -v \"#{version}\"#{opts}", :env=>nil)
else
shell_out!("#{gem_binary_path} uninstall #{name} -q -x -I -a#{opts}", :env=>nil)
end
end
|
#upgrade_package(name, version) ⇒ Object
430
431
432
|
# File 'lib/chef/provider/package/rubygems.rb', line 430
def upgrade_package(name, version)
install_package(name, version)
end
|