Class: ChefLicensing::TUIEngine::TUIEngineState
- Inherits:
-
Hash
- Object
- Hash
- ChefLicensing::TUIEngine::TUIEngineState
- Defined in:
- lib/chef-licensing/tui_engine/tui_engine_state.rb
Instance Attribute Summary collapse
-
#input ⇒ Object
Returns the value of attribute input.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#next_interaction_id ⇒ Object
Returns the value of attribute next_interaction_id.
-
#prompt ⇒ Object
Returns the value of attribute prompt.
-
#tui_actions ⇒ Object
Returns the value of attribute tui_actions.
Instance Method Summary collapse
- #append_info_to_input(extra_info_hash) ⇒ Object
- #default_action(interaction) ⇒ Object
-
#initialize(opts = {}) ⇒ TUIEngineState
constructor
A new instance of TUIEngineState.
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
#input ⇒ Object
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 |
#logger ⇒ Object
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_id ⇒ Object
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 |
#prompt ⇒ Object
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_actions ⇒ Object
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. = (interaction.) @prompt.send(interaction.prompt_type, , 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 |