Class: Ahoy::QuestionHelper
- Inherits:
-
Object
- Object
- Ahoy::QuestionHelper
- Defined in:
- lib/generators/ahoy/lib/question_helper.rb
Class Method Summary collapse
- .boolean_question(question, key, default = nil) ⇒ Object
- .question(type, &block) ⇒ Object
- .question_divider(value = nil) ⇒ Object
- .string_question(question, key, default = nil) ⇒ Object
Class Method Details
.boolean_question(question, key, default = nil) ⇒ Object
40 41 42 43 |
# File 'lib/generators/ahoy/lib/question_helper.rb', line 40 def self.boolean_question(question, key, default=nil) answer = Thor.new.yes?(question) Ahoy::VariableStore.add_variable(key, answer == true ? answer : false) end |
.question(type, &block) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/generators/ahoy/lib/question_helper.rb', line 9 def self.question(type, &block) question_hash = block.call @@required = question_hash[:required] default = question_hash[:default] key = question_hash.keys[0] question = "#{question_hash[key]}:" question_divider(default) case type when :string string_question(question, key, default) when :boolean boolean_question(question, key, default) end end |
.question_divider(value = nil) ⇒ Object
45 46 47 48 |
# File 'lib/generators/ahoy/lib/question_helper.rb', line 45 def self.question_divider(value=nil) puts '-' * 100 puts "Default: #{value}" unless value.nil? end |
.string_question(question, key, default = nil) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/generators/ahoy/lib/question_helper.rb', line 26 def self.string_question(question, key, default=nil) if @@required == true answer = '' until answer != '' answer = Thor.new.ask(question) Ahoy::VariableStore.add_variable(key, answer.empty? ? default : answer) puts "Answer required, but you can always change it later!!!\n\n" if answer == '' end else answer = Thor.new.ask(question) Ahoy::VariableStore.add_variable(key, answer.empty? ? default : answer) end end |