Class: Gem::Commands::InstallCommand
- Inherits:
-
Gem::Command
- Object
- Gem::Command
- Gem::Commands::InstallCommand
- Includes:
- InstallUpdateOptions, LocalRemoteOptions, VersionOption
- Defined in:
- lib/rubygems/commands/install_command.rb
Overview
Gem installer command line tool
See ‘gem help install`
Instance Attribute Summary collapse
-
#installed_specs ⇒ Object
readonly
:nodoc:.
Attributes inherited from Gem::Command
#command, #defaults, #options, #program_name, #summary
Instance Method Summary collapse
-
#arguments ⇒ Object
:nodoc:.
-
#check_install_dir ⇒ Object
:nodoc:.
-
#check_version ⇒ Object
:nodoc:.
-
#defaults_str ⇒ Object
:nodoc:.
-
#description ⇒ Object
:nodoc:.
- #execute ⇒ Object
-
#initialize ⇒ InstallCommand
constructor
A new instance of InstallCommand.
-
#install_from_gemdeps ⇒ Object
:nodoc:.
-
#install_gem(name, version) ⇒ Object
:nodoc:.
-
#install_gem_without_dependencies(name, req) ⇒ Object
:nodoc:.
-
#install_gems ⇒ Object
:nodoc:.
-
#load_hooks ⇒ Object
Loads post-install hooks.
-
#show_install_errors(errors) ⇒ Object
:nodoc:.
-
#show_installed ⇒ Object
:nodoc:.
-
#usage ⇒ Object
:nodoc:.
Methods included from InstallUpdateOptions
#add_install_update_options, #install_update_defaults_str
Methods included from LocalRemoteOptions
#accept_uri_http, #add_bulk_threshold_option, #add_clear_sources_option, #add_local_remote_options, #add_proxy_option, #add_source_option, #add_update_sources_option, #both?, #local?, #remote?
Methods included from VersionOption
#add_platform_option, #add_prerelease_option, #add_version_option
Methods inherited from Gem::Command
add_common_option, #add_extra_args, #add_option, add_specific_extra_args, #begins?, build_args, build_args=, common_options, extra_args, extra_args=, #get_all_gem_names, #get_all_gem_names_and_versions, #get_one_gem_name, #get_one_optional_argument, #handle_options, #handles?, #invoke, #invoke_with_build_args, #merge_options, #remove_option, #show_help, #show_lookup_failure, specific_extra_args, specific_extra_args_hash, #when_invoked
Methods included from UserInteraction
#alert, #alert_error, #alert_warning, #ask, #ask_for_password, #ask_yes_no, #choose_from_list, #say, #terminate_interaction, #verbose
Methods included from DefaultUserInteraction
ui, #ui, ui=, #ui=, use_ui, #use_ui
Constructor Details
#initialize ⇒ InstallCommand
Returns a new instance of InstallCommand.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# 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)" add_option(:"Install/Update", '-g', '--file [FILE]', 'Read from a gem dependencies API file and', 'install the listed gems') do |v,o| v = Gem::GEM_DEP_FILES.find do |file| File.exist? file end unless v unless v then = v ? v : "(tried #{Gem::GEM_DEP_FILES.join ', '})" raise OptionParser::InvalidArgument, "cannot find gem dependencies file #{message}" end o[:gemdeps] = v end add_option(:"Install/Update", '--without GROUPS', Array, 'Omit the named groups (comma separated)', 'when installing from a gem dependencies', 'file') do |v,o| o[:without_groups].concat v.map { |without| without.intern } end add_option(:"Install/Update", '--default', 'Add the gem\'s full specification to', 'specifications/default and extract only its bin') do |v,o| o[:install_as_default] = v end add_option(:"Install/Update", '--explain', 'Rather than install the gems, indicate which would', 'be installed') do |v,o| o[:explain] = v end add_option(:"Install/Update", '--[no-]lock', 'Create a lock file (when used with -g/--file)') do |v,o| o[:lock] = v end add_option(:"Install/Update", '--[no-]suggestions', 'Suggest alternates when gems are not found') do |v,o| o[:suggest_alternate] = v end @installed_specs = [] end |
Instance Attribute Details
#installed_specs ⇒ Object (readonly)
:nodoc:
16 17 18 |
# File 'lib/rubygems/commands/install_command.rb', line 16 def installed_specs @installed_specs end |
Instance Method Details
#arguments ⇒ Object
:nodoc:
88 89 90 |
# File 'lib/rubygems/commands/install_command.rb', line 88 def arguments # :nodoc: "GEMNAME name of gem to install" end |
#check_install_dir ⇒ Object
:nodoc:
173 174 175 176 177 178 |
# File 'lib/rubygems/commands/install_command.rb', line 173 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 ⇒ Object
:nodoc:
180 181 182 183 184 185 186 |
# File 'lib/rubygems/commands/install_command.rb', line 180 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 ⇒ Object
:nodoc:
92 93 94 95 |
# File 'lib/rubygems/commands/install_command.rb', line 92 def defaults_str # :nodoc: "--both --version '#{Gem::Requirement.default}' --document --no-force\n" + "--install-dir #{Gem.dir} --lock" end |
#description ⇒ Object
:nodoc:
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/rubygems/commands/install_command.rb', line 97 def description # :nodoc: "The install command installs local or remote gem into a gem repository.\n\nFor gems with executables ruby installs a wrapper file into the executable\ndirectory by default. This can be overridden with the --no-wrappers option.\nThe wrapper allows you to choose among alternate gem versions using _version_.\n\nFor example `rake _0.7.3_ --version` will run rake version 0.7.3 if a newer\nversion is also installed.\n\nGem Dependency Files\n====================\n\nRubyGems can install a consistent set of gems across multiple environments\nusing `gem install -g` when a gem dependencies file (gem.deps.rb, Gemfile or\nIsolate) is present. If no explicit file is given RubyGems attempts to find\none in the current directory.\n\nWhen the RUBYGEMS_GEMDEPS environment variable is set to a gem dependencies\nfile the gems from that file will be activated at startup time. Set it to a\nspecific filename or to \"-\" to have RubyGems automatically discover the gem\ndependencies file by walking up from the current directory.\n\nNOTE: Enabling automatic discovery on multiuser systems can lead to\nexecution of arbitrary code when used from directories outside your control.\n\nExtension Install Failures\n==========================\n\nIf an extension fails to compile during gem installation the gem\nspecification is not written out, but the gem remains unpacked in the\nrepository. You may need to specify the path to the library's headers and\nlibraries to continue. You can do this by adding a -- between RubyGems'\noptions and the extension's build options:\n\n$ gem install some_extension_gem\n[build fails]\nGem files will remain installed in \\\\\n/path/to/gems/some_extension_gem-1.0 for inspection.\nResults logged to /path/to/gems/some_extension_gem-1.0/gem_make.out\n$ gem install some_extension_gem -- --with-extension-lib=/path/to/lib\n[build succeeds]\n$ gem list some_extension_gem\n\n*** LOCAL GEMS ***\n\nsome_extension_gem (1.0)\n$\n\nIf you correct the compilation errors by editing the gem files you will need\nto write the specification by hand. For example:\n\n$ gem install some_extension_gem\n[build fails]\nGem files will remain installed in \\\\\n/path/to/gems/some_extension_gem-1.0 for inspection.\nResults logged to /path/to/gems/some_extension_gem-1.0/gem_make.out\n$ [cd /path/to/gems/some_extension_gem-1.0]\n$ [edit files or what-have-you and run make]\n$ gem spec ../../cache/some_extension_gem-1.0.gem --ruby > \\\\\n ../../specifications/some_extension_gem-1.0.gemspec\n$ gem list some_extension_gem\n\n*** LOCAL GEMS ***\n\nsome_extension_gem (1.0)\n$\n\n EOF\nend\n" |
#execute ⇒ Object
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/rubygems/commands/install_command.rb', line 188 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 ⇒ Object
:nodoc:
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/rubygems/commands/install_command.rb', line 210 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) ⇒ Object
:nodoc:
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 |
# File 'lib/rubygems/commands/install_command.rb', line 229 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) ⇒ Object
:nodoc:
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 |
# File 'lib/rubygems/commands/install_command.rb', line 257 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 ⇒ Object
:nodoc:
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 |
# File 'lib/rubygems/commands/install_command.rb', line 293 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.message}" 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 ⇒ Object
Loads post-install hooks
319 320 321 322 323 324 325 326 |
# File 'lib/rubygems/commands/install_command.rb', line 319 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) ⇒ Object
:nodoc:
328 329 330 331 332 333 334 335 336 337 338 |
# File 'lib/rubygems/commands/install_command.rb', line 328 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.message}" alert_warning msg end end |
#show_installed ⇒ Object
:nodoc:
340 341 342 343 344 345 |
# File 'lib/rubygems/commands/install_command.rb', line 340 def show_installed # :nodoc: return if @installed_specs.empty? gems = @installed_specs.length == 1 ? 'gem' : 'gems' say "#{@installed_specs.length} #{gems} installed" end |
#usage ⇒ Object
:nodoc:
169 170 171 |
# File 'lib/rubygems/commands/install_command.rb', line 169 def usage # :nodoc: "#{program_name} GEMNAME [GEMNAME ...] [options] -- --build-flags" end |