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: :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
# 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: dep = Gem::Dependency.new gem, options[:version] 67: 68: field = get_one_optional_argument 69: 70: if field then 71: field = field.intern 72: 73: if options[:format] == :ruby then 74: raise Gem::CommandLineError, "--ruby and FIELD are mutually exclusive" 75: end 76: 77: unless Gem::Specification.attribute_names.include? field then 78: raise Gem::CommandLineError, 79: "no field %p on Gem::Specification" % field.to_s 80: end 81: end 82: 83: if local? then 84: if File.exist? gem then 85: specs << Gem::Format.from_file_by_path(gem).spec rescue nil 86: end 87: 88: if specs.empty? then 89: specs.push(*Gem.source_index.search(dep)) 90: end 91: end 92: 93: if remote? then 94: found = Gem::SpecFetcher.fetcher.fetch dep 95: 96: specs.push(*found.map { |spec,| spec }) 97: end 98: 99: if specs.empty? then 100: alert_error "Unknown gem '#{gem}'" 101: terminate_interaction 1 102: end 103: 104: output = lambda do |s| 105: s = s.send field if field 106: 107: say case options[:format] 108: when :ruby then s.to_ruby 109: when :marshal then Marshal.dump s 110: else s.to_yaml 111: end 112: 113: say "\n" 114: end 115: 116: if options[:all] then 117: specs.each(&output) 118: else 119: spec = specs.sort_by { |s| s.version }.last 120: output[spec] 121: end 122: end