Class: GemInstaller::GemInteractionHandler

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

Constant Summary collapse

DEPENDENCY_PROMPT =
'Install required dependency'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGemInteractionHandler

Returns a new instance of GemInteractionHandler.



6
7
8
# File 'lib/geminstaller/gem_interaction_handler.rb', line 6

def initialize
  check_rubygems_version
end

Instance Attribute Details

#dependent_gem=(value) ⇒ Object (writeonly)

Sets the attribute dependent_gem

Parameters:

  • value

    the value to set the attribute dependent_gem to.



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

def dependent_gem=(value)
  @dependent_gem = value
end

#noninteractive_chooser_class=(value) ⇒ Object (writeonly)

Sets the attribute noninteractive_chooser_class

Parameters:

  • value

    the value to set the attribute noninteractive_chooser_class to.



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

def noninteractive_chooser_class=(value)
  @noninteractive_chooser_class = value
end

#valid_platform_selector=(value) ⇒ Object (writeonly)

Sets the attribute valid_platform_selector

Parameters:

  • value

    the value to set the attribute valid_platform_selector to.



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

def valid_platform_selector=(value)
  @valid_platform_selector = value
end

Instance Method Details

#check_rubygems_versionObject



34
35
36
37
38
39
# File 'lib/geminstaller/gem_interaction_handler.rb', line 34

def check_rubygems_version
  if GemInstaller::RubyGemsVersionChecker.matches?('>=0.9.5')
    # gem_interaction_handler is not used for RubyGems >= 0.9.5
    raise RuntimeError.new("Internal GemInstaller Error: GemInteractionHandler should not be used for RubyGems >= 0.9.5")
  end
end

#dependent_gem_with_platform_specified?(list, noninteractive_chooser) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/geminstaller/gem_interaction_handler.rb', line 30

def dependent_gem_with_platform_specified?(list, noninteractive_chooser)
  noninteractive_chooser.dependent_gem?(@dependent_gem.name, list) and @dependent_gem.platform
end

#handle_ask_yes_no(question) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/geminstaller/gem_interaction_handler.rb', line 10

def handle_ask_yes_no(question)
  return unless question.index(DEPENDENCY_PROMPT)
  message = "Error: RubyGems is prompting to install a required dependency, and you have not " +
            "specified the '--install-dependencies' option for the current gem.  You must modify your " +
            "geminstaller config file to either specify the '--install-depencencies' (-y) " +
            "option, or explicitly add an entry for the dependency gem earlier in the file.\n"
  raise GemInstaller::UnauthorizedDependencyPromptError.new(message)
end

#handle_choose_from_list(question, list, noninteractive_chooser = nil) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/geminstaller/gem_interaction_handler.rb', line 19

def handle_choose_from_list(question, list, noninteractive_chooser = nil)
  noninteractive_chooser ||= @noninteractive_chooser_class.new
  valid_platforms = nil
  if dependent_gem_with_platform_specified?(list, noninteractive_chooser) or noninteractive_chooser.uninstall_list_type?(question)
    valid_platforms = [@dependent_gem.platform]
  else
    valid_platforms = @valid_platform_selector.select(@dependent_gem.platform)
  end
  noninteractive_chooser.choose(question, list, @dependent_gem.name, @dependent_gem.version, valid_platforms)
end