| Class | Gem::Commands::SpecificationCommand |
| In: |
lib/rubygems/commands/specification_command.rb
|
| Parent: | Gem::Command |
# File lib/rubygems/commands/specification_command.rb, line 13
13: def initialize
14: super 'specification', 'Display gem specification (in yaml)',
15: :domain => :local, :version => Gem::Requirement.default
16:
17: add_version_option('examine')
18: add_platform_option
19:
20: add_option('--all', 'Output specifications for all versions of',
21: 'the gem') do |value, options|
22: options[:all] = true
23: end
24:
25: add_local_remote_options
26: end
# File lib/rubygems/commands/specification_command.rb, line 40
40: def execute
41: specs = []
42: gem = get_one_gem_name
43:
44: if local? then
45: if File.exist? gem then
46: specs << Gem::Format.from_file_by_path(gem).spec rescue nil
47: end
48:
49: if specs.empty? then
50: specs.push(*Gem.source_index.search(/\A#{gem}\z/, options[:version]))
51: end
52: end
53:
54: if remote? then
55: dep = Gem::Dependency.new gem, options[:version]
56: found = Gem::SpecFetcher.fetcher.fetch dep
57:
58: specs.push(*found.map { |spec,| spec })
59: end
60:
61: if specs.empty? then
62: alert_error "Unknown gem '#{gem}'"
63: terminate_interaction 1
64: end
65:
66: output = lambda { |s| say s.to_yaml; say "\n" }
67:
68: if options[:all] then
69: specs.each(&output)
70: else
71: spec = specs.sort_by { |s| s.version }.last
72: output[spec]
73: end
74: end