Class: Gem::Commands::RequireCommand

Inherits:
Gem::Command
  • Object
show all
Includes:
InstallUpdateOptions, LocalRemoteOptions, VersionOption
Defined in:
lib/rubygems/commands/require_command.rb

Instance Method Summary collapse

Constructor Details

#initializeRequireCommand

Returns a new instance of RequireCommand.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rubygems/commands/require_command.rb', line 14

def initialize
  defaults = Gem::DependencyInstaller::DEFAULT_OPTIONS.merge(
  {
    :generate_rdoc     => true,
    :generate_ri       => true,
    :format_executable => false,
    :test              => false,
    :version           => Gem::Requirement.default,
    :latest            => false,
  }
  )

  super 'require', 'Install or update a gem', defaults

  add_option('--latest',
             'Get the latest matching version') do |value, options|
    options[:latest] = true
  end

  add_install_update_options
  add_local_remote_options

  add_version_option
  add_platform_option
  add_prerelease_option

end

Instance Method Details

#argumentsObject

:nodoc:



42
43
44
# File 'lib/rubygems/commands/require_command.rb', line 42

def arguments # :nodoc:
  "GEMNAME       name of required gem"
end

#defaults_strObject

:nodoc:



46
47
48
49
# File 'lib/rubygems/commands/require_command.rb', line 46

def defaults_str # :nodoc:
  "--version '#{Gem::Requirement.default}' --rdoc --ri --no-force\n" \
  "--no-test --install-dir #{Gem.dir}"
end

#descriptionObject

:nodoc:



51
52
53
54
55
56
# File 'lib/rubygems/commands/require_command.rb', line 51

def description # :nodoc:
  <<-EOF
The require command checks whether the specified gems are installed,
and installs them if necessary.
  EOF
end

#executeObject



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/rubygems/commands/require_command.rb', line 62

def execute
  exit_code = 0

  version = options[:version]
  get_all_gem_names.each do |name|
    begin
      require_gem(name, version, options)
    rescue Gem::InstallError => e
      alert_error "Error installing #{name}:\n\t#{e.message}"
      exit_code |= 1
    rescue Gem::GemNotFoundException => e
      show_lookup_failure e.name, e.version, e.errors, options[:domain]
      exit_code |= 2
    end
  end

  exit(exit_code)

end

#usageObject

:nodoc:



58
59
60
# File 'lib/rubygems/commands/require_command.rb', line 58

def usage # :nodoc:
  "#{program_name} GEMNAME [GEMNAME ...] [options]"
end