Class: Gem::Commands::BuildCommand

Inherits:
Gem::Command show all
Includes:
GemspecHelpers, VersionOption
Defined in:
lib/rubygems/commands/build_command.rb

Instance Attribute Summary

Attributes inherited from Gem::Command

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

Instance Method Summary collapse

Methods included from GemspecHelpers

#find_gemspec

Methods included from VersionOption

#add_platform_option, #add_prerelease_option, #add_version_option, #get_platform_from_requirements

Methods inherited from Gem::Command

add_common_option, #add_extra_args, #add_option, add_specific_extra_args, #begins?, build_args, build_args=, #check_deprecated_options, common_options, #defaults_str, #deprecate_option, #deprecated?, extra_args, extra_args=, #extract_gem_name_and_version, #get_all_gem_names, #get_all_gem_names_and_versions, #get_one_gem_name, #get_one_optional_argument, #handle_options, #handles?, #invoke, #invoke_with_build_args, #merge_options, #remove_option, #show_help, #show_lookup_failure, specific_extra_args, specific_extra_args_hash, #when_invoked

Methods included from UserInteraction

#alert, #alert_error, #alert_warning, #ask, #ask_for_password, #ask_yes_no, #choose_from_list, #say, #terminate_interaction, #verbose

Methods included from DefaultUserInteraction

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

Methods included from Text

#clean_text, #format_text, #levenshtein_distance, #min3, #truncate_text

Constructor Details

#initializeBuildCommand

Returns a new instance of BuildCommand.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rubygems/commands/build_command.rb', line 12

def initialize
  super "build", "Build a gem from a gemspec"

  add_platform_option

  add_option "--force", "skip validation of the spec" do |_value, options|
    options[:force] = true
  end

  add_option "--strict", "consider warnings as errors when validating the spec" do |_value, options|
    options[:strict] = true
  end

  add_option "-o", "--output FILE", "output gem with the given filename" do |value, options|
    options[:output] = value
  end

  add_option "-C PATH", "Run as if gem build was started in <PATH> instead of the current working directory." do |value, options|
    options[:build_path] = value
  end
  deprecate_option "-C",
                   version: "4.0",
                   extra_msg: "-C is a global flag now. Use `gem -C PATH build GEMSPEC_FILE [options]` instead"
end

Instance Method Details

#argumentsObject

:nodoc:



37
38
39
# File 'lib/rubygems/commands/build_command.rb', line 37

def arguments # :nodoc:
  "GEMSPEC_FILE  gemspec file name to build a gem for"
end

#descriptionObject

:nodoc:



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/rubygems/commands/build_command.rb', line 41

def description # :nodoc:
  <<-EOF
The build command allows you to create a gem from a ruby gemspec.

The best way to build a gem is to use a Rakefile and the Gem::PackageTask
which ships with RubyGems.

The gemspec can either be created by hand or extracted from an existing gem
with gem spec:

$ gem unpack my_gem-1.0.gem
Unpacked gem: '.../my_gem-1.0'
$ gem spec my_gem-1.0.gem --ruby > my_gem-1.0/my_gem-1.0.gemspec
$ cd my_gem-1.0
[edit gem contents]
$ gem build my_gem-1.0.gemspec

Gems can be saved to a specified filename with the output option:

$ gem build my_gem-1.0.gemspec --output=release.gem

  EOF
end

#executeObject



69
70
71
72
73
74
75
76
# File 'lib/rubygems/commands/build_command.rb', line 69

def execute
  if build_path = options[:build_path]
    Dir.chdir(build_path) { build_gem }
    return
  end

  build_gem
end

#usageObject

:nodoc:



65
66
67
# File 'lib/rubygems/commands/build_command.rb', line 65

def usage # :nodoc:
  "#{program_name} GEMSPEC_FILE"
end