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.
305
306
307
308
309
310
311
312
313
314
315
316
317
|
# File 'lib/chef/provider/package/rubygems.rb', line 305
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
Returns the value of attribute gem_env.
297
298
299
|
# File 'lib/chef/provider/package/rubygems.rb', line 297
def gem_env
@gem_env
end
|
Instance Method Details
#all_installed_versions ⇒ Object
352
353
354
355
356
|
# File 'lib/chef/provider/package/rubygems.rb', line 352
def all_installed_versions
@all_installed_versions ||= begin
@gem_env.installed_versions(Gem::Dependency.new(gem_dependency.name, '>= 0'))
end
end
|
#candidate_version ⇒ Object
371
372
373
374
375
376
377
378
379
380
381
|
# File 'lib/chef/provider/package/rubygems.rb', line 371
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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
|
# File 'lib/chef/provider/package/rubygems.rb', line 328
def current_version
if !matching_installed_versions.empty?
gemspec = matching_installed_versions.last
logger.debug { "#{@new_resource} found installed gem #{gemspec.name} version #{gemspec.version} matching #{gem_dependency}"}
gemspec
elsif !all_installed_versions.empty?
gemspec = all_installed_versions.last
logger.debug { "#{@new_resource} newest installed version of gem #{gemspec.name} is #{gemspec.version}" }
gemspec
else
logger.debug { "#{@new_resource} no installed version found for #{gem_dependency.to_s}"}
nil
end
end
|
#gem_binary_path ⇒ Object
417
418
419
|
# File 'lib/chef/provider/package/rubygems.rb', line 417
def gem_binary_path
@new_resource.gem_binary || 'gem'
end
|
#gem_dependency ⇒ Object
319
320
321
|
# File 'lib/chef/provider/package/rubygems.rb', line 319
def gem_dependency
Gem::Dependency.new(@new_resource.package_name, @new_resource.version)
end
|
#gem_sources ⇒ Object
358
359
360
|
# File 'lib/chef/provider/package/rubygems.rb', line 358
def gem_sources
@new_resource.source ? Array(@new_resource.source) : 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
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
|
# File 'lib/chef/provider/package/rubygems.rb', line 398
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
421
422
423
424
|
# File 'lib/chef/provider/package/rubygems.rb', line 421
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
362
363
364
365
366
367
368
369
|
# File 'lib/chef/provider/package/rubygems.rb', line 362
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
|
299
300
301
|
# File 'lib/chef/provider/package/rubygems.rb', line 299
def logger
Chef::Log.logger
end
|
#matching_installed_versions ⇒ Object
348
349
350
|
# File 'lib/chef/provider/package/rubygems.rb', line 348
def matching_installed_versions
@matching_installed_versions ||= @gem_env.installed_versions(gem_dependency)
end
|
#purge_package(name, version) ⇒ Object
452
453
454
|
# File 'lib/chef/provider/package/rubygems.rb', line 452
def purge_package(name, version)
remove_package(name, version)
end
|
#remove_package(name, version) ⇒ Object
430
431
432
433
434
435
436
437
438
439
440
441
442
|
# File 'lib/chef/provider/package/rubygems.rb', line 430
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
323
324
325
326
|
# File 'lib/chef/provider/package/rubygems.rb', line 323
def source_is_remote?
return true if @new_resource.source.nil?
URI.parse(@new_resource.source).absolute?
end
|
#target_version_already_installed? ⇒ Boolean
383
384
385
386
387
388
389
390
|
# File 'lib/chef/provider/package/rubygems.rb', line 383
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
444
445
446
447
448
449
450
|
# File 'lib/chef/provider/package/rubygems.rb', line 444
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
426
427
428
|
# File 'lib/chef/provider/package/rubygems.rb', line 426
def upgrade_package(name, version)
install_package(name, version)
end
|