Class: Gem::Commands::PrecompileCommand

Inherits:
Gem::Command
  • Object
show all
Defined in:
lib/rubygems/commands/precompile_command.rb

Instance Method Summary collapse

Constructor Details

#initializePrecompileCommand

Returns a new instance of PrecompileCommand.



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/rubygems/commands/precompile_command.rb', line 4

def initialize
  super "precompile", "Create a bundle containing the compiled artifacts for this platform", :output => Dir.pwd, :arch => false

  add_option('-o PATH', '--output=PATH', 'The output directory for the generated bundle. Defaults to the current directory') do |path,options|
    options[:output] = path
  end

  add_option('-a','--arch-dirs','Adds the architecture sub-folders to the output directory before writing') do |arch, options|
    options[:arch] = true
  end
end

Instance Method Details

#argumentsObject



16
17
18
# File 'lib/rubygems/commands/precompile_command.rb', line 16

def arguments
  "GEMFILE       path to the gem file to compile"
end

#executeObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/rubygems/commands/precompile_command.rb', line 24

def execute
  gemfiles = options[:args]

  # no gem, no binary
  if gemfiles.empty?
    raise Gem::CommandLineError, "Please specify a gem file on the command line, e.g. #{program_name} foo-0.1.0.gem"
  end

  require "rubygems/precompiler"

  gemfiles.each do |gemfile|
    compiler = Gem::Precompiler.new(gemfile, options)
    if compiler.has_extension?
      $stderr.puts "Compiling '#{compiler.gem_name}'... "
      compiler.compile
      $stderr.puts "done."
    else
      $stderr.puts "The gem '#{compiler.gem_name}' doesn't contain a compiled extension"
    end
  end
end

#usageObject



20
21
22
# File 'lib/rubygems/commands/precompile_command.rb', line 20

def usage
  "#{program_name} GEMFILE"
end