Class: Gem::Commands::InstallCommand
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
::Gem::Command
|
|
Instance Chain:
|
|
Inherits: |
Gem::Command
|
Defined in: | lib/rubygems/commands/install_command.rb |
Overview
::Gem installer command line tool
See gem help install
Constant Summary
::Gem::Command - Inherited
Class Attribute Summary
::Gem::Command - Inherited
.build_args | Arguments used when building gems. |
.build_args=, .extra_args, .extra_args= |
Class Method Summary
- .new ⇒ InstallCommand constructor
::Gem::Command - Inherited
.add_common_option, | |
.add_specific_extra_args | Add a list of extra arguments for the given command. |
.common_options, | |
.new | Initializes a generic gem command named |
.specific_extra_args | Return an array of extra arguments for the command. |
.specific_extra_args_hash | Accessor for the specific extra args hash (self initializing). |
Instance Attribute Summary
- #installed_specs readonly Internal use only
::Gem::LocalRemoteOptions - Included
#both? | Is fetching of local and remote information enabled? |
#local? | Is local fetching enabled? |
#remote? | Is remote fetching enabled? |
::Gem::Command - Inherited
#command | The name of the command. |
#defaults | The default options for the command. |
#options | The options for the command. |
#program_name | The name of the command for command-line invocation. |
#summary | A short description of the command. |
::Gem::DefaultUserInteraction - Included
Instance Method Summary
- #execute
- #arguments Internal use only
- #check_install_dir Internal use only
- #check_version Internal use only
- #defaults_str Internal use only
- #description Internal use only
- #install_from_gemdeps Internal use only
- #install_gem(name, version) Internal use only
- #install_gem_without_dependencies(name, req) Internal use only
- #install_gems Internal use only
-
#load_hooks
Internal use only
Loads post-install hooks.
- #show_install_errors(errors) Internal use only
- #show_installed Internal use only
- #usage Internal use only
::Gem::InstallUpdateOptions - Included
#add_install_update_options | Add the install/update options to the option parser. |
#install_update_defaults_str | Default options for the gem install command. |
::Gem::SecurityOption - Included
::Gem::LocalRemoteOptions - Included
#accept_uri_http | Allows OptionParser to handle HTTP URIs. |
#add_bulk_threshold_option | Add the –bulk-threshold option. |
#add_clear_sources_option | Add the –clear-sources option. |
#add_local_remote_options | Add local/remote options to the command line parser. |
#add_proxy_option | Add the –http-proxy option. |
#add_source_option | Add the –source option. |
#add_update_sources_option | Add the –update-sources option. |
::Gem::VersionOption - Included
#add_platform_option | Add the –platform option to the option parser. |
#add_prerelease_option | Add the –prerelease option to the option parser. |
#add_version_option | Add the –version option to the option parser. |
::Gem::Command - Inherited
#add_extra_args | Adds extra args from ~/.gemrc. |
#add_option | Add a command-line option and handler to the command. |
#arguments | Override to provide details of the arguments a command takes. |
#begins? | True if |
#defaults_str | Override to display the default values of the command options. |
#description | Override to display a longer description of what this command does. |
#execute | Override to provide command handling. |
#get_all_gem_names | Get all gem names from the command line. |
#get_all_gem_names_and_versions | Get all [gem, version] from the command line. |
#get_one_gem_name | Get a single gem name from the command line. |
#get_one_optional_argument | Get a single optional argument from the command line. |
#handle_options | Handle the given list of arguments by parsing them and recording the results. |
#handles? | True if the command handles the given argument list. |
#invoke | Invoke the command with the given list of arguments. |
#invoke_with_build_args | Invoke the command with the given list of normal arguments and additional build arguments. |
#merge_options | Merge a set of command options with the set of default options (without modifying the default option hash). |
#remove_option | Remove previously defined command-line argument |
#show_help | Display the help message for the command. |
#show_lookup_failure | Display to the user that a gem couldn't be found and reasons why. |
#usage | Override to display the usage for an individual gem command. |
#when_invoked | Call the given block when invoked. |
#add_parser_run_info | Adds a section with |
#configure_options, | |
#create_option_parser | Creates an option parser and fills it in with the help info for the command. |
#parser | Create on demand parser. |
#wrap | Wraps |
#add_parser_description, #add_parser_options, #add_parser_summary |
::Gem::UserInteraction - Included
#alert | Displays an alert |
#alert_error | Displays an error |
#alert_warning | Displays a warning |
#ask | Asks a |
#ask_for_password | Asks for a password with a |
#ask_yes_no | Asks a yes or no |
#choose_from_list | Asks the user to answer |
#say | Displays the given |
#terminate_interaction | Terminates the RubyGems process with the given |
#verbose | Calls |
::Gem::DefaultUserInteraction - Included
::Gem::Text - Included
#clean_text | Remove any non-printable characters and make the text suitable for printing. |
#format_text | Wraps |
#levenshtein_distance | This code is based directly on the ::Gem::Text gem implementation Returns a value representing the “cost” of transforming str1 into str2. |
#truncate_text, #min3 |
Constructor Details
.new ⇒ InstallCommand
# File 'lib/rubygems/commands/install_command.rb', line 22
def initialize defaults = Gem::DependencyInstaller::DEFAULT_OPTIONS.merge({ :format_executable => false, :lock => true, :suggest_alternate => true, :version => Gem::Requirement.default, :without_groups => [], }) super 'install', 'Install a gem into the local repository', defaults add_platform_option add_version_option add_prerelease_option "to be installed. (Only for listed gems)" @installed_specs = [] end
Instance Attribute Details
#installed_specs (readonly)
# File 'lib/rubygems/commands/install_command.rb', line 16
attr_reader :installed_specs # :nodoc:
Instance Method Details
#arguments
# File 'lib/rubygems/commands/install_command.rb', line 42
def arguments # :nodoc: "GEMNAME name of gem to install" end
#check_install_dir
# File 'lib/rubygems/commands/install_command.rb', line 127
def check_install_dir # :nodoc: if [:install_dir] and [:user_install] then alert_error "Use --install-dir or --user-install but not both" terminate_interaction 1 end end
#check_version
# File 'lib/rubygems/commands/install_command.rb', line 134
def check_version # :nodoc: if [:version] != Gem::Requirement.default and get_all_gem_names.size > 1 then alert_error "Can't use --version w/ multiple gems. Use name:ver instead." terminate_interaction 1 end end
#defaults_str
# File 'lib/rubygems/commands/install_command.rb', line 46
def defaults_str # :nodoc: "--both --version '#{Gem::Requirement.default}' --document --no-force\n" + "--install-dir #{Gem.dir} --lock" end
#description
# File 'lib/rubygems/commands/install_command.rb', line 51
def description # :nodoc: <<-EOF The install command installs local or remote gem into a gem repository. For gems with executables ruby installs a wrapper file into the executable directory by default. This can be overridden with the --no-wrappers option. The wrapper allows you to choose among alternate gem versions using _version_. For example `rake _0.7.3_ --version` will run rake version 0.7.3 if a newer version is also installed. Gem Dependency Files ==================== RubyGems can install a consistent set of gems across multiple environments using `gem install -g` when a gem dependencies file (gem.deps.rb, Gemfile or Isolate) is present. If no explicit file is given RubyGems attempts to find one in the current directory. When the RUBYGEMS_GEMDEPS environment variable is set to a gem dependencies file the gems from that file will be activated at startup time. Set it to a specific filename or to "-" to have RubyGems automatically discover the gem dependencies file by walking up from the current directory. NOTE: Enabling automatic discovery on multiuser systems can lead to execution of arbitrary code when used from directories outside your control. Extension Install Failures ========================== If an extension fails to compile during gem installation the gem specification is not written out, but the gem remains unpacked in the repository. You may need to specify the path to the library's headers and libraries to continue. You can do this by adding a -- between RubyGems' options and the extension's build options: $ gem install some_extension_gem [build fails] Gem files will remain installed in \\ /path/to/gems/some_extension_gem-1.0 for inspection. Results logged to /path/to/gems/some_extension_gem-1.0/gem_make.out $ gem install some_extension_gem -- --with-extension-lib=/path/to/lib [build succeeds] $ gem list some_extension_gem *** LOCAL GEMS *** some_extension_gem (1.0) $ If you correct the compilation errors by editing the gem files you will need to write the specification by hand. For example: $ gem install some_extension_gem [build fails] Gem files will remain installed in \\ /path/to/gems/some_extension_gem-1.0 for inspection. Results logged to /path/to/gems/some_extension_gem-1.0/gem_make.out $ [cd /path/to/gems/some_extension_gem-1.0] $ [edit files or what-have-you and run make] $ gem spec ../../cache/some_extension_gem-1.0.gem --ruby > \\ #../../specifications/some_extension_gem-1.0.gemspec $ gem list some_extension_gem *** LOCAL GEMS *** some_extension_gem (1.0) $ EOF end
#execute
[ GitHub ]# File 'lib/rubygems/commands/install_command.rb', line 142
def execute if .include? :gemdeps then install_from_gemdeps return # not reached end @installed_specs = [] ENV.delete 'GEM_PATH' if [:install_dir].nil? and RUBY_VERSION > '1.9' check_install_dir check_version load_hooks exit_code = install_gems show_installed terminate_interaction exit_code end
#install_from_gemdeps
# File 'lib/rubygems/commands/install_command.rb', line 165
def install_from_gemdeps # :nodoc: require 'rubygems/request_set' rs = Gem::RequestSet.new specs = rs.install_from_gemdeps do |req, inst| s = req.full_spec if inst say "Installing #{s.name} (#{s.version})" else say "Using #{s.name} (#{s.version})" end end @installed_specs = specs terminate_interaction end
#install_gem(name, version)
# File 'lib/rubygems/commands/install_command.rb', line 184
def install_gem name, version # :nodoc: return if [:conservative] and not Gem::Dependency.new(name, version).matching_specs.empty? req = Gem::Requirement.create(version) if [:ignore_dependencies] then install_gem_without_dependencies name, req else inst = Gem::DependencyInstaller.new request_set = inst.resolve_dependencies name, req if [:explain] puts "Gems to install:" request_set.sorted_requests.each do |s| puts " #{s.full_name}" end return else @installed_specs.concat request_set.install end show_install_errors inst.errors end end
#install_gem_without_dependencies(name, req)
# File 'lib/rubygems/commands/install_command.rb', line 212
def install_gem_without_dependencies name, req # :nodoc: gem = nil if local? then if name =~ /\.gem$/ and File.file? name then source = Gem::Source::SpecificFile.new name spec = source.spec else source = Gem::Source::Local.new spec = source.find_gem name, req end gem = source.download spec if spec end if remote? and not gem then dependency = Gem::Dependency.new name, req dependency.prerelease = [:prerelease] fetcher = Gem::RemoteFetcher.fetcher gem = fetcher.download_to_cache dependency end inst = Gem::Installer.at gem, inst.install require 'rubygems/dependency_installer' dinst = Gem::DependencyInstaller.new dinst.installed_gems.replace [inst.spec] Gem.done_installing_hooks.each do |hook| hook.call dinst, [inst.spec] end unless Gem.done_installing_hooks.empty? @installed_specs.push(inst.spec) end
#install_gems
# File 'lib/rubygems/commands/install_command.rb', line 248
def install_gems # :nodoc: exit_code = 0 get_all_gem_names_and_versions.each do |gem_name, gem_version| gem_version ||= [:version] begin install_gem gem_name, gem_version rescue Gem::InstallError => e alert_error "Error installing #{gem_name}:\n\t#{e.}" exit_code |= 1 rescue Gem::GemNotFoundException, Gem::UnsatisfiableDependencyError => e domain = [:domain] domain = :local unless [:suggest_alternate] show_lookup_failure e.name, e.version, e.errors, domain exit_code |= 2 end end exit_code end
#load_hooks
Loads post-install hooks
# File 'lib/rubygems/commands/install_command.rb', line 274
def load_hooks # :nodoc: if [:install_as_default] require 'rubygems/install_default_message' else require 'rubygems/install_message' end require 'rubygems/rdoc' end
#show_install_errors(errors)
# File 'lib/rubygems/commands/install_command.rb', line 283
def show_install_errors errors # :nodoc: return unless errors errors.each do |x| return unless Gem::SourceFetchProblem === x msg = "Unable to pull data from '#{x.source.uri}': #{x.error.}" alert_warning msg end end
#show_installed
# File 'lib/rubygems/commands/install_command.rb', line 295
def show_installed # :nodoc: return if @installed_specs.empty? gems = @installed_specs.length == 1 ? 'gem' : 'gems' say "#{@installed_specs.length} #{gems} installed" end
#usage
# File 'lib/rubygems/commands/install_command.rb', line 123
def usage # :nodoc: "#{program_name} GEMNAME [GEMNAME ...] [options] -- --build-flags" end