Class: ChefLicensing::TUIEngine
- Inherits:
-
Object
- Object
- ChefLicensing::TUIEngine
- Defined in:
- lib/chef-licensing/tui_engine/tui_engine.rb,
lib/chef-licensing/tui_engine/tui_prompt.rb,
lib/chef-licensing/tui_engine/tui_actions.rb,
lib/chef-licensing/tui_engine/tui_exceptions.rb,
lib/chef-licensing/tui_engine/tui_interaction.rb,
lib/chef-licensing/tui_engine/tui_engine_state.rb
Defined Under Namespace
Classes: BadInteractionFile, BadPromptInput, IncompleteFlowException, MissingInteractionFile, PromptTimeout, TUIActions, TUIEngineState, TUIInteraction, TUIPrompt, UnsupportedInteractionFileFormat
Constant Summary collapse
- INTERACTION_FILE_FORMAT_VERSION =
"1.0.0".freeze
Instance Attribute Summary collapse
-
#action_methods ⇒ Object
Returns the value of attribute action_methods.
-
#interaction_attributes ⇒ Object
Returns the value of attribute interaction_attributes.
-
#interaction_data ⇒ Object
Returns the value of attribute interaction_data.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#opts ⇒ Object
Returns the value of attribute opts.
-
#prompt_methods ⇒ Object
Returns the value of attribute prompt_methods.
-
#traversed_interaction ⇒ Object
Returns the value of attribute traversed_interaction.
-
#tui_interactions ⇒ Object
Returns the value of attribute tui_interactions.
Instance Method Summary collapse
- #append_info_to_input(extra_info_hash) ⇒ Object
-
#initialize(opts = {}) ⇒ TUIEngine
constructor
A new instance of TUIEngine.
- #run_interaction(start_interaction_id = nil) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ TUIEngine
Returns a new instance of TUIEngine.
15 16 17 18 19 20 21 22 |
# File 'lib/chef-licensing/tui_engine/tui_engine.rb', line 15 def initialize(opts = {}) @opts = opts @logger = ChefLicensing::Config.logger @tui_interactions = {} @traversed_interaction = [] initialization_of_engine(opts[:interaction_file]) @state = ChefLicensing::TUIEngine::TUIEngineState.new(@opts) end |
Instance Attribute Details
#action_methods ⇒ Object
Returns the value of attribute action_methods.
13 14 15 |
# File 'lib/chef-licensing/tui_engine/tui_engine.rb', line 13 def action_methods @action_methods end |
#interaction_attributes ⇒ Object
Returns the value of attribute interaction_attributes.
13 14 15 |
# File 'lib/chef-licensing/tui_engine/tui_engine.rb', line 13 def interaction_attributes @interaction_attributes end |
#interaction_data ⇒ Object
Returns the value of attribute interaction_data.
13 14 15 |
# File 'lib/chef-licensing/tui_engine/tui_engine.rb', line 13 def interaction_data @interaction_data end |
#logger ⇒ Object
Returns the value of attribute logger.
13 14 15 |
# File 'lib/chef-licensing/tui_engine/tui_engine.rb', line 13 def logger @logger end |
#opts ⇒ Object
Returns the value of attribute opts.
13 14 15 |
# File 'lib/chef-licensing/tui_engine/tui_engine.rb', line 13 def opts @opts end |
#prompt_methods ⇒ Object
Returns the value of attribute prompt_methods.
13 14 15 |
# File 'lib/chef-licensing/tui_engine/tui_engine.rb', line 13 def prompt_methods @prompt_methods end |
#traversed_interaction ⇒ Object
Returns the value of attribute traversed_interaction.
13 14 15 |
# File 'lib/chef-licensing/tui_engine/tui_engine.rb', line 13 def traversed_interaction @traversed_interaction end |
#tui_interactions ⇒ Object
Returns the value of attribute tui_interactions.
13 14 15 |
# File 'lib/chef-licensing/tui_engine/tui_engine.rb', line 13 def tui_interactions @tui_interactions end |
Instance Method Details
#append_info_to_input(extra_info_hash) ⇒ Object
47 48 49 |
# File 'lib/chef-licensing/tui_engine/tui_engine.rb', line 47 def append_info_to_input(extra_info_hash) state.append_info_to_input(extra_info_hash) end |
#run_interaction(start_interaction_id = nil) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/chef-licensing/tui_engine/tui_engine.rb', line 24 def run_interaction(start_interaction_id = nil) start_interaction_id ||= @tui_interactions.keys.first current_interaction = @tui_interactions[start_interaction_id] previous_interaction = nil until current_interaction.nil? || current_interaction.id == :exit @traversed_interaction << current_interaction.id state.default_action(current_interaction) previous_interaction = current_interaction current_interaction = state.next_interaction_id.nil? ? nil : current_interaction.paths[state.next_interaction_id.to_sym] end # If the last interaction is not the exit interaction. Something went wrong in the flow. # raise the message where the flow broke. raise ChefLicensing::TUIEngine::IncompleteFlowException, "Something went wrong in the flow. The last interaction was #{previous_interaction&.id}." unless current_interaction&.id == :exit state.default_action(current_interaction) # remove the pastel key we used in tui engine state for styling and return the remaining parsed input state.input.delete(:pastel) state.input end |