Class: Gem::BuildCommand

Inherits:
Command show all
Includes:
CommandAids
Defined in:
lib/rubygems/gem_commands.rb

Instance Attribute Summary

Attributes inherited from Command

#command, #defaults, #options, #program_name, #summary

Instance Method Summary collapse

Methods included from CommandAids

#begins?, #get_all_gem_names, #get_one_gem_name, #get_one_optional_argument

Methods inherited from Command

add_common_option, #add_option, add_specific_extra_args, common_options, #defaults_str, extra_args, extra_args=, #handles?, #invoke, #merge_options, #remove_option, #show_help, specific_extra_args, specific_extra_args_hash, #when_invoked

Methods included from DefaultUserInteraction

#ui, ui, #ui=, ui=, #use_ui, use_ui

Constructor Details

#initializeBuildCommand

Returns a new instance of BuildCommand.



723
724
725
# File 'lib/rubygems/gem_commands.rb', line 723

def initialize
  super('build', 'Build a gem from a gemspec')
end

Instance Method Details

#argumentsObject



731
732
733
# File 'lib/rubygems/gem_commands.rb', line 731

def arguments
  "GEMSPEC_FILE      name of gemspec file used to build the gem"
end

#executeObject



735
736
737
738
739
740
741
742
743
744
745
746
# File 'lib/rubygems/gem_commands.rb', line 735

def execute
  gemspec = get_one_gem_name
  if File.exist?(gemspec)
    specs = load_gemspecs(gemspec)
    specs.each do |spec|
      Gem::Builder.new(spec).build
    end
    return
  else
    alert_error "Gemspec file not found: #{gemspec}"
  end
end

#load_gemspecs(filename) ⇒ Object



748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
# File 'lib/rubygems/gem_commands.rb', line 748

def load_gemspecs(filename)
  if yaml?(filename)
    require 'yaml'
    result = []
    open(filename) do |f|
      begin
        while spec = Gem::Specification.from_yaml(f)
          result << spec
        end
      rescue EndOfYAMLException => e
        # OK
      end
    end
  else
    result = [Gem::Specification.load(filename)]
  end
  result
end

#usageObject



727
728
729
# File 'lib/rubygems/gem_commands.rb', line 727

def usage
  "#{program_name} GEMSPEC_FILE"
end

#yaml?(filename) ⇒ Boolean

Returns:

  • (Boolean)


767
768
769
770
771
# File 'lib/rubygems/gem_commands.rb', line 767

def yaml?(filename)
  line = open(filename) { |f| line = f.gets }
  result = line =~ %r{^--- *!ruby/object:Gem::Specification}
  result
end