Class: Rigit::Prompt
- Inherits:
-
Object
- Object
- Rigit::Prompt
- Defined in:
- lib/rigit/prompt.rb
Overview
Handles prompt request for user input in batch. This is a wrapper around TTY::Prompt that gets all the params (typically from the rig config file), and asks the user for input one by one, while considering prefilled values.
Instance Attribute Summary collapse
-
#input ⇒ Object
readonly
Returns the value of attribute input.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
-
#get_input(prefill = {}) ⇒ Object
Asks the user for input.
-
#initialize(params) ⇒ Prompt
constructor
A new instance of Prompt.
Constructor Details
#initialize(params) ⇒ Prompt
Returns a new instance of Prompt.
11 12 13 |
# File 'lib/rigit/prompt.rb', line 11 def initialize(params) @params = params end |
Instance Attribute Details
#input ⇒ Object (readonly)
Returns the value of attribute input.
9 10 11 |
# File 'lib/rigit/prompt.rb', line 9 def input @input end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
9 10 11 |
# File 'lib/rigit/prompt.rb', line 9 def params @params end |
Instance Method Details
#get_input(prefill = {}) ⇒ Object
Asks the user for input. If a prefill hash is provided, it will be used for values, and skip asking the user to provide answers for the ones that are prefilled.
18 19 20 21 22 23 24 25 26 |
# File 'lib/rigit/prompt.rb', line 18 def get_input(prefill = {}) @input = {} params.each do |key, spec| next if skip_by_condition? spec @input[key] = prefill.has_key?(key) ? prefill[key] : ask(spec) end @input end |