Class: Gem::Commands::CanCommand

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

Instance Method Summary collapse

Constructor Details

#initializeCanCommand

Returns a new instance of CanCommand.



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/rubygems/commands/can_command.rb', line 10

def initialize
  super 'can', 'Can an installed gem into a .jar file',
        :version => Gem::Requirement.default,
        :target  => Dir.pwd

  add_option('--target DIR', 'target directory for the .jar') do |value, options|
    options[:target] = value
  end

  add_version_option
end

Instance Method Details

#argumentsObject

:nodoc:



22
23
24
# File 'lib/rubygems/commands/can_command.rb', line 22

def arguments # :nodoc:
  "GEMNAME       name of gem to unpack"
end

#defaults_strObject

:nodoc:



26
27
28
# File 'lib/rubygems/commands/can_command.rb', line 26

def defaults_str # :nodoc:
  "--version '#{Gem::Requirement.default}'"
end

#executeObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/rubygems/commands/can_command.rb', line 34

def execute
  get_all_gem_names.each do |name|
    path = get_path name, options[:version]

    if path then
      basename = File.basename(path).sub(/\.gem$/, '')
      tmpgem_dir = File.expand_path File.join(Dir.tmpdir, 'cannery', basename)
      target_dir = File.expand_path File.join(options[:target])
      FileUtils.mkdir_p tmpgem_dir
      FileUtils.mkdir_p target_dir
      Gem::Installer.new(path, :unpack => true).unpack tmpgem_dir
      sh "jar -cf #{target_dir}/#{basename}.jar -C #{tmpgem_dir}/lib ."
      FileUtils.rm_rf tmpgem_dir
      say "Gem has been canned: '#{target_dir}/#{basename}.jar'"
    else
      alert_error "Gem '#{name}' not installed."
    end
  end
end

#usageObject

:nodoc:



30
31
32
# File 'lib/rubygems/commands/can_command.rb', line 30

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