Class: GemInstaller::GemCommandManager
- Inherits:
-
Object
- Object
- GemInstaller::GemCommandManager
- Defined in:
- lib/geminstaller/gem_command_manager.rb
Instance Attribute Summary collapse
-
#gem_interaction_handler ⇒ Object
writeonly
Sets the attribute gem_interaction_handler.
-
#gem_runner_proxy ⇒ Object
writeonly
Sets the attribute gem_runner_proxy.
-
#gem_spec_manager ⇒ Object
writeonly
Sets the attribute gem_spec_manager.
Instance Method Summary collapse
- #dependency(name, version, additional_options = []) ⇒ Object
- #init_gem_interaction_handler(gem) ⇒ Object
- #install_gem(gem, force_reinstall = false) ⇒ Object
- #list_remote_gem(gem, additional_options) ⇒ Object
- #run_gem_command(gem_command, gem, options) ⇒ Object
- #uninstall_gem(gem) ⇒ Object
Instance Attribute Details
#gem_interaction_handler=(value) ⇒ Object (writeonly)
Sets the attribute gem_interaction_handler
4 5 6 |
# File 'lib/geminstaller/gem_command_manager.rb', line 4 def gem_interaction_handler=(value) @gem_interaction_handler = value end |
#gem_runner_proxy=(value) ⇒ Object (writeonly)
Sets the attribute gem_runner_proxy
3 4 5 |
# File 'lib/geminstaller/gem_command_manager.rb', line 3 def gem_runner_proxy=(value) @gem_runner_proxy = value end |
#gem_spec_manager=(value) ⇒ Object (writeonly)
Sets the attribute gem_spec_manager
3 4 5 |
# File 'lib/geminstaller/gem_command_manager.rb', line 3 def gem_spec_manager=(value) @gem_spec_manager = value end |
Instance Method Details
#dependency(name, version, additional_options = []) ⇒ Object
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 |
# File 'lib/geminstaller/gem_command_manager.rb', line 29 def dependency(name, version, = []) # rubygems has bug up to 0.9.4 where the pipe options uses 'puts', instead of 'say', so we can't capture it # with enhanced_stream_ui. Patched: http://rubyforge.org/tracker/index.php?func=detail&aid=9020&group_id=126&atid=577 # TODO: use pipe option on later versions which support it name_regexp = "^#{name}$" name_regexp = "/#{name_regexp}/" if GemInstaller::RubyGemsVersionChecker.matches?('>=1.2.0') run_args = ["dependency", name_regexp, "--version", version] run_args += output_lines = @gem_runner_proxy.run(run_args) p output_lines # dependency output has all lines in the first element output_array = output_lines[0].split("\n") # drop the first line which just echoes the dependent gem output_array.shift # drop the line containing 'requires' (rubygems < 0.9.0) if output_array[0] == ' Requires' output_array.shift end # drop all empty lines output_array.reject! { |line| line == "" } # strip leading space output_array.each { |line| line.strip! } # convert into gems output_gems = output_array.collect do |line| name = line.split(' ')[0] version_spec = line.split(/[(,)]/)[1] GemInstaller::RubyGem.new(name, :version => version_spec) end end |
#init_gem_interaction_handler(gem) ⇒ Object
25 26 27 |
# File 'lib/geminstaller/gem_command_manager.rb', line 25 def init_gem_interaction_handler(gem) @gem_interaction_handler.dependent_gem = gem if GemInstaller::RubyGemsVersionChecker.matches?('<=0.9.4') end |
#install_gem(gem, force_reinstall = false) ⇒ Object
19 20 21 22 23 |
# File 'lib/geminstaller/gem_command_manager.rb', line 19 def install_gem(gem, force_reinstall = false) return [] if @gem_spec_manager.is_gem_installed?(gem) && !force_reinstall init_gem_interaction_handler(gem) run_gem_command('install', gem, gem.) end |
#list_remote_gem(gem, additional_options) ⇒ Object
6 7 8 9 10 11 |
# File 'lib/geminstaller/gem_command_manager.rb', line 6 def list_remote_gem(gem, ) run_args = ["list",gem.name,"--remote","--details"] run_args << "--all" if GemInstaller::RubyGemsVersionChecker.matches?('>1.0.1') run_args += @gem_runner_proxy.run(run_args) end |
#run_gem_command(gem_command, gem, options) ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'lib/geminstaller/gem_command_manager.rb', line 60 def run_gem_command(gem_command, gem, ) run_args = [gem_command,gem.name,"--version", "#{gem.version}"] if GemInstaller::RubyGemsVersionChecker.matches?('>=0.9.5') run_args += ['--platform', "#{gem.platform}"] if gem.platform && !gem.platform.empty? end run_args += @gem_runner_proxy.run(run_args) end |
#uninstall_gem(gem) ⇒ Object
13 14 15 16 17 |
# File 'lib/geminstaller/gem_command_manager.rb', line 13 def uninstall_gem(gem) return if !@gem_spec_manager.is_gem_installed?(gem) init_gem_interaction_handler(gem) run_gem_command('uninstall', gem, gem.) end |