PageRenderTime 158ms CodeModel.GetById 151ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/tools/Ruby/lib/ruby/site_ruby/1.8/rubygems/commands/build_command.rb

http://github.com/agross/netopenspace
Ruby | 53 lines | 45 code | 7 blank | 1 comment | 3 complexity | 06d86f73b22469145808dbc241363151 MD5 | raw file
 1require 'rubygems/command'
 2require 'rubygems/builder'
 3
 4class Gem::Commands::BuildCommand < Gem::Command
 5
 6  def initialize
 7    super('build', 'Build a gem from a gemspec')
 8  end
 9
10  def arguments # :nodoc:
11    "GEMSPEC_FILE  gemspec file name to build a gem for"
12  end
13
14  def usage # :nodoc:
15    "#{program_name} GEMSPEC_FILE"
16  end
17
18  def execute
19    gemspec = get_one_gem_name
20    if File.exist?(gemspec)
21      specs = load_gemspecs(gemspec)
22      specs.each do |spec|
23        Gem::Builder.new(spec).build
24      end
25    else
26      alert_error "Gemspec file not found: #{gemspec}"
27    end
28  end
29
30  def load_gemspecs(filename)
31    if yaml?(filename)
32      result = []
33      open(filename) do |f|
34        begin
35          while not f.eof? and spec = Gem::Specification.from_yaml(f)
36            result << spec
37          end
38        rescue Gem::EndOfYAMLException
39          # OK
40        end
41      end
42    else
43      result = [Gem::Specification.load(filename)]
44    end
45    result
46  end
47
48  def yaml?(filename)
49    line = open(filename) { |f| line = f.gets }
50    result = line =~ %r{!ruby/object:Gem::Specification}
51    result
52  end
53end