Class Gem::Commands::SpecificationCommand
In: lib/rubygems/commands/specification_command.rb
Parent: Gem::Command

Methods

execute   new  

Included Modules

Gem::LocalRemoteOptions Gem::VersionOption

Public Class methods

[Source]

    # File lib/rubygems/commands/specification_command.rb, line 11
11:   def initialize
12:     Gem.load_yaml
13: 
14:     super 'specification', 'Display gem specification (in yaml)',
15:           :domain => :local, :version => Gem::Requirement.default,
16:           :format => :yaml
17: 
18:     add_version_option('examine')
19:     add_platform_option
20: 
21:     add_option('--all', 'Output specifications for all versions of',
22:                'the gem') do |value, options|
23:       options[:all] = true
24:     end
25: 
26:     add_option('--ruby', 'Output ruby format') do |value, options|
27:       options[:format] = :ruby
28:     end
29: 
30:     add_option('--yaml', 'Output RUBY format') do |value, options|
31:       options[:format] = :yaml
32:     end
33: 
34:     add_option('--marshal', 'Output Marshal format') do |value, options|
35:       options[:format] = :marshal
36:     end
37: 
38:     add_local_remote_options
39:   end

Public Instance methods

[Source]

     # File lib/rubygems/commands/specification_command.rb, line 57
 57:   def execute
 58:     specs = []
 59:     gem = options[:args].shift
 60: 
 61:     unless gem then
 62:       raise Gem::CommandLineError,
 63:             "Please specify a gem name or file on the command line"
 64:     end
 65: 
 66:     case options[:version]
 67:     when String
 68:       req = Gem::Requirement.parse options[:version]
 69:     when Gem::Requirement
 70:       req = options[:version]
 71:     else
 72:       raise Gem::CommandLineError, "Unsupported version type: #{options[:version]}"
 73:     end
 74: 
 75:     if !req.none? and options[:all]
 76:       alert_error "Specify --all or -v, not both"
 77:       terminate_interaction 1
 78:     end
 79: 
 80:     if options[:all]
 81:       dep = Gem::Dependency.new gem
 82:     else
 83:       dep = Gem::Dependency.new gem, options[:version]
 84:     end
 85: 
 86:     field = get_one_optional_argument
 87: 
 88:     raise Gem::CommandLineError, "--ruby and FIELD are mutually exclusive" if
 89:       field and options[:format] == :ruby
 90: 
 91:     if local? then
 92:       if File.exist? gem then
 93:         specs << Gem::Format.from_file_by_path(gem).spec rescue nil
 94:       end
 95: 
 96:       if specs.empty? then
 97:         specs.push(*dep.matching_specs)
 98:       end
 99:     end
100: 
101:     if remote? then
102:       found = Gem::SpecFetcher.fetcher.fetch dep, true
103: 
104:       if dep.prerelease? or options[:prerelease]
105:         found += Gem::SpecFetcher.fetcher.fetch dep, false, true, true
106:       end
107: 
108:       specs.push(*found.map { |spec,| spec })
109:     end
110: 
111:     if specs.empty? then
112:       alert_error "Unknown gem '#{gem}'"
113:       terminate_interaction 1
114:     end
115: 
116:     unless options[:all] then
117:       specs = [specs.sort_by { |s| s.version }.last]
118:     end
119: 
120:     specs.each do |s|
121:       s = s.send field if field
122: 
123:       say case options[:format]
124:           when :ruby then s.to_ruby
125:           when :marshal then Marshal.dump s
126:           else s.to_yaml
127:           end
128: 
129:       say "\n"
130:     end
131:   end

[Validate]