Class: Cyoi::Cli::AutoDetection::UI

Inherits:
Object
  • Object
show all
Defined in:
lib/cyoi/cli/auto_detection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes, highline) ⇒ UI

Returns a new instance of UI.



9
10
11
12
13
# File 'lib/cyoi/cli/auto_detection.rb', line 9

def initialize(attributes, highline)
  @hl = highline
  @attributes = attributes.is_a?(Hash) ? ReadWriteSettings.new(attributes) : attributes
  raise "@attributes must be ReadWriteSettings (or Hash)" unless @attributes.is_a?(ReadWriteSettings)
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



6
7
8
# File 'lib/cyoi/cli/auto_detection.rb', line 6

def attributes
  @attributes
end

#hlObject (readonly)

Returns the value of attribute hl.



7
8
9
# File 'lib/cyoi/cli/auto_detection.rb', line 7

def hl
  @hl
end

Instance Method Details

#aggregated_detector_choicesObject



37
38
39
40
41
42
43
44
# File 'lib/cyoi/cli/auto_detection.rb', line 37

def aggregated_detector_choices
  @aggregated_detector_choices ||= begin
    detectors.inject({}) do |choices, detector_class|
      detector = detector_class.new
      choices.merge!(detector.auto_detection_choices)
    end
  end
end

#detectorsObject



46
47
48
49
50
# File 'lib/cyoi/cli/auto_detection.rb', line 46

def detectors
  [
    Cyoi::Cli::AutoDetection::AutoDetectionFog
  ]
end

#export_attributesObject

helper to export the complete nested attributes.



33
34
35
# File 'lib/cyoi/cli/auto_detection.rb', line 33

def export_attributes
  attributes.to_nested_hash
end

#performObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/cyoi/cli/auto_detection.rb', line 15

def perform
  # Display menu of choices
  # Include "Alternate credentials" as the last option
  if aggregated_detector_choices.keys.size > 0
    hl.choose do |menu|
      menu.prompt = "Choose an auto-detected infrastructure: "
      aggregated_detector_choices.each do |label, credentials|
        menu.choice(label) do
          attributes.set("name", credentials.delete("name"))
          attributes.set("credentials", credentials)
        end
      end
      menu.choice("Alternate credentials") { false }
    end
  end
end