Class: ChefLicensing::TUIEngine::TUIEngineState

Inherits:
Hash
  • Object
show all
Defined in:
lib/chef-licensing/tui_engine/tui_engine_state.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ TUIEngineState

Returns a new instance of TUIEngineState.



12
13
14
15
16
17
18
19
# File 'lib/chef-licensing/tui_engine/tui_engine_state.rb', line 12

def initialize(opts = {})
  @input = {}
  # store the pastel key for enabling styled messages in the yaml file
  @input[:pastel] = Pastel.new
  @logger = ChefLicensing::Config.logger
  @prompt = ChefLicensing::TUIEngine::TUIPrompt.new(opts)
  @tui_actions = ChefLicensing::TUIEngine::TUIActions.new(opts)
end

Instance Attribute Details

#inputObject

Returns the value of attribute input.



10
11
12
# File 'lib/chef-licensing/tui_engine/tui_engine_state.rb', line 10

def input
  @input
end

#loggerObject

Returns the value of attribute logger.



10
11
12
# File 'lib/chef-licensing/tui_engine/tui_engine_state.rb', line 10

def logger
  @logger
end

#next_interaction_idObject

Returns the value of attribute next_interaction_id.



10
11
12
# File 'lib/chef-licensing/tui_engine/tui_engine_state.rb', line 10

def next_interaction_id
  @next_interaction_id
end

#promptObject

Returns the value of attribute prompt.



10
11
12
# File 'lib/chef-licensing/tui_engine/tui_engine_state.rb', line 10

def prompt
  @prompt
end

#tui_actionsObject

Returns the value of attribute tui_actions.



10
11
12
# File 'lib/chef-licensing/tui_engine/tui_engine_state.rb', line 10

def tui_actions
  @tui_actions
end

Instance Method Details

#append_info_to_input(extra_info_hash) ⇒ Object



41
42
43
# File 'lib/chef-licensing/tui_engine/tui_engine_state.rb', line 41

def append_info_to_input(extra_info_hash)
  @input.merge!(extra_info_hash)
end

#default_action(interaction) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/chef-licensing/tui_engine/tui_engine_state.rb', line 21

def default_action(interaction)
  logger.debug "Default action called for interaction id: #{interaction.id}"

  response = if interaction.messages
               messages = render_messages(interaction.messages)
               @prompt.send(interaction.prompt_type, messages, interaction.prompt_attributes)
             elsif interaction.action
               @tui_actions.send(interaction.action, @input)
             end

  @input.store(interaction.id, response)
  logger.debug "Response for interaction #{interaction.id} is #{@input[interaction.id]}"

  @next_interaction_id = if interaction.paths.size > 1
                           interaction.response_path_map[response.to_s]
                         elsif interaction.paths.size == 1
                           interaction.paths.keys.first
                         end
end