Class: GemInstaller::InstallProcessor

Inherits:
Object
  • Object
show all
Defined in:
lib/geminstaller/install_processor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#gem_command_manager=(value) ⇒ Object (writeonly)

Sets the attribute gem_command_manager

Parameters:

  • value

    the value to set the attribute gem_command_manager to.



3
4
5
# File 'lib/geminstaller/install_processor.rb', line 3

def gem_command_manager=(value)
  @gem_command_manager = value
end

#gem_list_checker=(value) ⇒ Object (writeonly)

Sets the attribute gem_list_checker

Parameters:

  • value

    the value to set the attribute gem_list_checker to.



3
4
5
# File 'lib/geminstaller/install_processor.rb', line 3

def gem_list_checker=(value)
  @gem_list_checker = value
end

#gem_spec_manager=(value) ⇒ Object (writeonly)

Sets the attribute gem_spec_manager

Parameters:

  • value

    the value to set the attribute gem_spec_manager to.



3
4
5
# File 'lib/geminstaller/install_processor.rb', line 3

def gem_spec_manager=(value)
  @gem_spec_manager = value
end

#missing_dependency_finder=(value) ⇒ Object (writeonly)

Sets the attribute missing_dependency_finder

Parameters:

  • value

    the value to set the attribute missing_dependency_finder to.



3
4
5
# File 'lib/geminstaller/install_processor.rb', line 3

def missing_dependency_finder=(value)
  @missing_dependency_finder = value
end

#options=(value) ⇒ Object (writeonly)

Sets the attribute options

Parameters:

  • value

    the value to set the attribute options to.



3
4
5
# File 'lib/geminstaller/install_processor.rb', line 3

def options=(value)
  @options = value
end

#output_filter=(value) ⇒ Object (writeonly)

Sets the attribute output_filter

Parameters:

  • value

    the value to set the attribute output_filter to.



3
4
5
# File 'lib/geminstaller/install_processor.rb', line 3

def output_filter=(value)
  @output_filter = value
end

Instance Method Details

#fix_dependencies(gem) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/geminstaller/install_processor.rb', line 55

def fix_dependencies(gem)
  missing_dependencies = @missing_dependency_finder.find(gem)
  while (missing_dependencies.size > 0)
    missing_dependencies.each do |missing_dependency|
      @output_filter.geminstaller_output(:install,"Installing #{missing_dependency.name} (#{missing_dependency.version})\n")
      # recursively call install_gem to install the missing dependency.  Since fix_dependencies
      # should never be set on an auto-created missing dependency gem, there is no risk of an 
      # endless loop or stack overflow.
      install_gem(missing_dependency)
    end
    # continue to look for and install missing dependencies until none are found
    missing_dependencies = @missing_dependency_finder.find(gem)
  end
end

#install_gem(gem) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/geminstaller/install_processor.rb', line 10

def install_gem(gem)
  already_specified = false
  if gem.check_for_upgrade
    @gem_list_checker.verify_and_specify_remote_gem!(gem)
    already_specified = true
  end
  gem_is_installed = @gem_spec_manager.is_gem_installed?(gem)
  if gem_is_installed
    @output_filter.geminstaller_output(:debug,"Gem #{gem.name}, version #{gem.version} is already installed.\n")
  else
    perform_install(gem, already_specified)
    installation_performed = true
  end
  if gem.fix_dependencies
    if GemInstaller::RubyGemsVersionChecker.matches?('>=0.9.5')
      # RubyGems >=0.9.5 automatically handles missing dependencies, so just perform an install
      unless installation_performed
        @output_filter.geminstaller_output(:install,"The 'fix_dependencies' option was specified for #{gem.name}, version #{gem.version}, so it will be reinstalled to fix any missing dependencies.\n")
        perform_install(gem, already_specified, true)
      end
    else
      # RubyGems <=0.9.4 does not automatically handles missing dependencies, so GemInstaller must find them
      # manually with missing_dependency_finder
      fix_dependencies(gem)
    end
  end
end

#perform_install(gem, already_specified, force_install = false) ⇒ Object



38
39
40
41
42
43
# File 'lib/geminstaller/install_processor.rb', line 38

def perform_install(gem, already_specified, force_install = false)
  @gem_list_checker.verify_and_specify_remote_gem!(gem) unless already_specified
  @output_filter.geminstaller_output(:install,"Invoking gem install for #{gem.name}, version #{gem.version}.\n")
  output_lines = @gem_command_manager.install_gem(gem, force_install)
  print_dependency_install_messages(gem, output_lines) unless @options[:silent]
end


45
46
47
48
49
50
51
52
53
# File 'lib/geminstaller/install_processor.rb', line 45

def print_dependency_install_messages(gem, output_lines)
  output_lines.each do |line|
    line =~ /Successfully installed /
    match = $'
    next unless match
    next if match =~ /#{gem.name}-/
    @output_filter.geminstaller_output(:install,"Rubygems automatically installed dependency gem #{match}\n")
  end
end

#process(gems) ⇒ Object



4
5
6
7
8
# File 'lib/geminstaller/install_processor.rb', line 4

def process(gems)
  gems.each do |gem|
    install_gem(gem)
  end
end