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 Gem::Exception, 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::Specification.load spec_path(full_name)
 80: 
 81:       if spec.nil? then
 82:         complain "Could not find gem #{full_name}, try using the full name"
 83:         next
 84:       end
 85: 
 86:       say "gem '#{spec.name}', '= #{spec.version}'" unless locked[spec.name]
 87:       locked[spec.name] = true
 88: 
 89:       spec.runtime_dependencies.each do |dep|
 90:         next if locked[dep.name]
 91:         candidates = dep.matching_specs
 92: 
 93:         if candidates.empty? then
 94:           complain "Unable to satisfy '#{dep}' from currently installed gems"
 95:         else
 96:           pending << candidates.last.full_name
 97:         end
 98:       end
 99:     end
100:   end

[Source]

     # File lib/rubygems/commands/lock_command.rb, line 102
102:   def spec_path(gem_full_name)
103:     gemspecs = Gem.path.map { |path|
104:       File.join path, "specifications", "#{gem_full_name}.gemspec"
105:     }
106: 
107:     gemspecs.find { |path| File.exist? path }
108:   end

[Validate]