Class: FlashKick::QuestionHelper
- Inherits:
-
Object
- Object
- FlashKick::QuestionHelper
- Defined in:
- lib/generators/flash_kick/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
42 43 44 45 |
# File 'lib/generators/flash_kick/lib/question_helper.rb', line 42 def self.boolean_question(question, key, default=nil) answer = Thor.new.yes?(question) FlashKick::VariableStore.add_variable(key, answer == true ? answer : false) end |
.question(type, &block) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/generators/flash_kick/lib/question_helper.rb', line 11 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
47 48 49 50 |
# File 'lib/generators/flash_kick/lib/question_helper.rb', line 47 def self.question_divider(value=nil) puts '-' * 100 @shell.say("Default: #{value}", :green) unless value.nil? end |
.string_question(question, key, default = nil) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/generators/flash_kick/lib/question_helper.rb', line 28 def self.string_question(question, key, default=nil) if @@required == true answer = '' until answer != '' answer = Thor.new.ask(question) FlashKick::VariableStore.add_variable(key, answer.empty? ? default : answer) @shell.say("Answer required, but you can always change it later!!!\n\n", :yellow) if answer == '' end else answer = Thor.new.ask(question) FlashKick::VariableStore.add_variable(key, answer.empty? ? default : answer) end end |