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
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::UpdateSuggestion
- Included
#ci?, | |
#eglible_for_update? | Determines if current environment is eglible for update suggestion. |
::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. |
#deprecated?, | |
#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_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::UpdateSuggestion
- Included
#update_suggestion | Message to promote available RubyGems update with related gem update command. |
::Gem::InstallUpdateOptions
- Included
#add_install_update_options | Add the install/update options to the option parser. |
#install_update_defaults_str | Default description for the gem install and update commands. |
#install_update_options | Default options for the gem install and update commands. |
::Gem::SecurityOption
- Included
::Gem::LocalRemoteOptions
- Included
#accept_uri_http | Allows |
#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. |
#get_platform_from_requirements | Extract platform given on the command line. |
::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 |
#check_deprecated_options, | |
#defaults_str | Override to display the default values of the command options. |
#deprecate_option | Mark a command-line option as deprecated, and optionally specify a deprecation horizon. |
#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. |
#option_is_deprecated?, | |
#parser | Create on demand parser. |
#wrap | Wraps |
#extract_gem_name_and_version, #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 | Returns a value representing the “cost” of transforming str1 into str2 Vendored version of |
#truncate_text, #min3 |
Constructor Details
.new ⇒ InstallCommand
# File 'lib/rubygems/commands/install_command.rb', line 24
def initialize defaults = Gem::DependencyInstaller::DEFAULT_OPTIONS.merge({ :format_executable => false, :lock => true, :suggest_alternate => true, :version => Gem::Requirement.default, :without_groups => [], }) defaults.merge!( ) 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 17
attr_reader :installed_specs # :nodoc:
Instance Method Details
#arguments
# File 'lib/rubygems/commands/install_command.rb', line 46
def arguments # :nodoc: "GEMNAME name of gem to install" end
#check_install_dir
# File 'lib/rubygems/commands/install_command.rb', line 139
def check_install_dir # :nodoc: if [:install_dir] && [:user_install] 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 146
def check_version # :nodoc: if [:version] != Gem::Requirement.default && get_all_gem_names.size > 1 alert_error "Can't use --version with multiple gems. You can specify multiple gems with" \ " version requirements using `gem install 'my_gem:1.0.0' 'my_other_gem:~>2.0.0'`" terminate_interaction 1 end end
#defaults_str
# File 'lib/rubygems/commands/install_command.rb', line 50
def defaults_str # :nodoc: "--both --version '#{Gem::Requirement.default}' --no-force\n" + "--install-dir #{Gem.dir} --lock\n" + install_update_defaults_str end
#description
# File 'lib/rubygems/commands/install_command.rb', line 56
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) $ Command Alias ========================== You can use `i` command instead of `install`. $ gem i GEMNAME EOF end
#execute
[ GitHub ]# File 'lib/rubygems/commands/install_command.rb', line 155
def execute if .include? :gemdeps install_from_gemdeps return # not reached end @installed_specs = [] ENV.delete "GEM_PATH" if [:install_dir].nil? check_install_dir check_version load_hooks exit_code = install_gems show_installed say update_suggestion if eglible_for_update? terminate_interaction exit_code end
#install_from_gemdeps
# File 'lib/rubygems/commands/install_command.rb', line 179
def install_from_gemdeps # :nodoc: require_relative "../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 198
def install_gem(name, version) # :nodoc: return if [:conservative] && !Gem::Dependency.new(name, version).matching_specs.empty? req = Gem::Requirement.create(version) dinst = Gem::DependencyInstaller.new request_set = dinst.resolve_dependencies name, req if [:explain] say "Gems to install:" request_set.sorted_requests.each do |activation_request| say " #{activation_request.full_name}" end else @installed_specs.concat request_set.install end show_install_errors dinst.errors end
#install_gems
# File 'lib/rubygems/commands/install_command.rb', line 221
def install_gems # :nodoc: exit_code = 0 get_all_gem_names_and_versions.each do |gem_name, gem_version| gem_version ||= [:version] domain = [:domain] domain = :local unless [:suggest_alternate] suppress_suggestions = (domain == :local) 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 => e show_lookup_failure e.name, e.version, e.errors, suppress_suggestions exit_code |= 2 rescue Gem::UnsatisfiableDependencyError => e show_lookup_failure e.name, e.version, e.errors, suppress_suggestions, "'#{gem_name}' (#{gem_version})" exit_code |= 2 end end exit_code end
#load_hooks
Loads post-install hooks
# File 'lib/rubygems/commands/install_command.rb', line 253
def load_hooks # :nodoc: if [:install_as_default] require_relative "../install_default_message" else require_relative "../install_message" end require_relative "../rdoc" end
#show_install_errors(errors)
# File 'lib/rubygems/commands/install_command.rb', line 262
def show_install_errors(errors) # :nodoc: return unless errors errors.each do |x| return unless Gem::SourceFetchProblem === x require_relative "../uri" msg = "Unable to pull data from '#{Gem::Uri.redact(x.source.uri)}': #{x.error.}" alert_warning msg end end
#show_installed
# File 'lib/rubygems/commands/install_command.rb', line 275
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 135
def usage # :nodoc: "#{program_name} [options] GEMNAME [GEMNAME ...] -- --build-flags" end