Module: ChangeLog::Generators::Utils::InstanceMethods
- Included in:
- InstallGenerator
- Defined in:
- lib/generators/change_log/utils.rb
Instance Method Summary collapse
- #ask_boolean(wording, default_value = nil) ⇒ Object
- #ask_for(wording, default_value = nil, override_if_present_value = nil) ⇒ Object
- #ask_wizard(question) ⇒ Object
- #display(output, color = :green) ⇒ Object
- #multiple_choice(question, choices) ⇒ Object
- #say_custom(tag, text) ⇒ Object
Instance Method Details
#ask_boolean(wording, default_value = nil) ⇒ Object
29 30 31 32 |
# File 'lib/generators/change_log/utils.rb', line 29 def ask_boolean(wording, default_value = nil) value = ask_for(wording, 'Y') value = (value == 'Y') end |
#ask_for(wording, default_value = nil, override_if_present_value = nil) ⇒ Object
23 24 25 26 27 |
# File 'lib/generators/change_log/utils.rb', line 23 def ask_for(wording, default_value = nil, override_if_present_value = nil) override_if_present_value.present? ? display("Using [#{override_if_present_value}] for question '#{wording}'") && override_if_present_value : ask(" ? #{wording} Press <enter> for [#{default_value}] >", :yellow).presence || default_value end |
#ask_wizard(question) ⇒ Object
6 7 8 |
# File 'lib/generators/change_log/utils.rb', line 6 def ask_wizard(question) ask "\033[1m\033[30m\033[46m" + "prompt".rjust(10) + "\033[0m\033[36m" + " #{question}\033[0m" end |
#display(output, color = :green) ⇒ Object
19 20 21 |
# File 'lib/generators/change_log/utils.rb', line 19 def display(output, color = :green) say(" - #{output}", color) end |
#multiple_choice(question, choices) ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/generators/change_log/utils.rb', line 9 def multiple_choice(question, choices) say_custom('question', question) values = {} choices.each_with_index do |choice,i| values[(i + 1).to_s] = choice[1] say_custom (i + 1).to_s + '.', choice[0] end answer = ask_wizard("Enter your selection:") while !values.keys.include?(answer) values[answer] end |
#say_custom(tag, text) ⇒ Object
5 |
# File 'lib/generators/change_log/utils.rb', line 5 def say_custom(tag, text); say "\033[1m\033[36m" + tag.to_s.rjust(10) + "\033[0m" + " #{text}" end |