Class: AIA::HistoryManager
- Inherits:
-
Object
- Object
- AIA::HistoryManager
- Defined in:
- lib/aia/history_manager.rb
Instance Method Summary collapse
-
#initialize ⇒ HistoryManager
constructor
A new instance of HistoryManager.
- #request_variable_value(variable_name:, default_value: nil) ⇒ Object
Constructor Details
#initialize ⇒ HistoryManager
Returns a new instance of HistoryManager.
8 9 10 |
# File 'lib/aia/history_manager.rb', line 8 def initialize # No prompt dependency — just handles user input for parameter collection end |
Instance Method Details
#request_variable_value(variable_name:, default_value: nil) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/aia/history_manager.rb', line 13 def request_variable_value(variable_name:, default_value: nil) Reline::HISTORY.clear question = if default_value.nil? "Value for #{variable_name} (required): " else "Value for #{variable_name} (#{default_value}): " end Reline.output = $stdout original_prompt_proc = Reline.line_editor.prompt_proc begin input = Reline.readline(question, true) if input.nil? # Ctrl+D return default_value if default_value puts "\nParameter '#{variable_name}' is required." exit(1) end value = input.strip if value.empty? return default_value if default_value puts "Parameter '#{variable_name}' is required." exit(1) end value rescue Interrupt puts "\nVariable input interrupted." exit(1) ensure Reline.line_editor.prompt_proc = original_prompt_proc end end |