Class Gem::Commands::LockCommand
In: lib/rubygems/commands/lock_command.rb
Parent: Gem::Command

Methods

complain   execute   new   spec_path  

Public Class methods

[Source]

    # File lib/rubygems/commands/lock_command.rb, line 5
 5:   def initialize
 6:     super 'lock', 'Generate a lockdown list of gems',
 7:           :strict => false
 8: 
 9:     add_option '-s', '--[no-]strict',
10:                'fail if unable to satisfy a dependency' do |strict, options|
11:       options[:strict] = strict
12:     end
13:   end

Public Instance methods

[Source]

    # File lib/rubygems/commands/lock_command.rb, line 61
61:   def complain(message)
62:     if options.strict then
63:       raise message
64:     else
65:       say "# #{message}"
66:     end
67:   end

[Source]

    # File lib/rubygems/commands/lock_command.rb, line 69
69:   def execute
70:     say 'require "rubygems"'
71: 
72:     locked = {}
73: 
74:     pending = options[:args]
75: 
76:     until pending.empty? do
77:       full_name = pending.shift
78: 
79:       spec = Gem::SourceIndex.load_specification spec_path(full_name)
80: 
81:       say "gem '#{spec.name}', '= #{spec.version}'" unless locked[spec.name]
82:       locked[spec.name] = true
83: 
84:       spec.runtime_dependencies.each do |dep|
85:         next if locked[dep.name]
86:         candidates = Gem.source_index.search dep.name, dep.requirement_list
87: 
88:         if candidates.empty? then
89:           complain "Unable to satisfy '#{dep}' from currently installed gems."
90:         else
91:           pending << candidates.last.full_name
92:         end
93:       end
94:     end
95:   end

[Source]

    # File lib/rubygems/commands/lock_command.rb, line 97
97:   def spec_path(gem_full_name)
98:     File.join Gem.path, "specifications", "#{gem_full_name }.gemspec"
99:   end

[Validate]