Class: Roro::Configurators::QuestionBuilder
- Inherits:
-
Object
- Object
- Roro::Configurators::QuestionBuilder
- Defined in:
- lib/roro/configurators/question_builder.rb
Instance Attribute Summary collapse
-
#inflection ⇒ Object
readonly
Returns the value of attribute inflection.
-
#question ⇒ Object
readonly
Returns the value of attribute question.
-
#storyfile ⇒ Object
readonly
Returns the value of attribute storyfile.
Instance Method Summary collapse
- #build_inflection ⇒ Object
- #get_story_preface(story) ⇒ Object
- #humanize(hash) ⇒ Object
- #inflection_options ⇒ Object
- #inflection_prompt ⇒ Object
-
#initialize(args = {}) ⇒ QuestionBuilder
constructor
A new instance of QuestionBuilder.
- #override(environment, key, value, override_value = nil) ⇒ Object
- #override_prompt(environment, key, value) ⇒ Object
- #story_from(key) ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ QuestionBuilder
Returns a new instance of QuestionBuilder.
9 10 11 12 13 14 15 16 |
# File 'lib/roro/configurators/question_builder.rb', line 9 def initialize(args={}) case when args[:inflection] @inflection = args[:inflection] when args[:storyfile] @storyfile = args[:storyfile] end end |
Instance Attribute Details
#inflection ⇒ Object (readonly)
Returns the value of attribute inflection.
7 8 9 |
# File 'lib/roro/configurators/question_builder.rb', line 7 def inflection @inflection end |
#question ⇒ Object (readonly)
Returns the value of attribute question.
7 8 9 |
# File 'lib/roro/configurators/question_builder.rb', line 7 def question @question end |
#storyfile ⇒ Object (readonly)
Returns the value of attribute storyfile.
7 8 9 |
# File 'lib/roro/configurators/question_builder.rb', line 7 def storyfile @storyfile end |
Instance Method Details
#build_inflection ⇒ Object
36 37 38 39 40 41 |
# File 'lib/roro/configurators/question_builder.rb', line 36 def build_inflection prompt = inflection_prompt = = humanize() @question = ["#{prompt} #{}", limited_to: .keys] end |
#get_story_preface(story) ⇒ Object
69 70 71 72 73 74 75 76 |
# File 'lib/roro/configurators/question_builder.rb', line 69 def get_story_preface(story) storyfile = "#{story}/#{stack_name(story)}.yml" if stack_is_storyfile?(storyfile) read_yaml("#{story}/#{stack_name(story)}.yml")[:preface] else nil end end |
#humanize(hash) ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'lib/roro/configurators/question_builder.rb', line 60 def humanize(hash) array = [] hash.map do |key, value| preface = get_story_preface("#{@inflection}/#{value}") array << "\n(#{key}) #{value}:\n #{preface}" end array.join end |
#inflection_options ⇒ Object
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/roro/configurators/question_builder.rb', line 49 def Hash.new.tap do |h| children(@inflection) .map { |f| stack_name(f) } .sort .each_with_index do |c, i| h[(i + 1).to_s] = stack_name(c) end end end |
#inflection_prompt ⇒ Object
43 44 45 46 47 |
# File 'lib/roro/configurators/question_builder.rb', line 43 def inflection_prompt prompt = 'Please choose from these' collection = stack_name(@inflection).gsub('_', ' ') + ":\n" [prompt, stack_parent(@inflection), collection].join(' ') end |
#override(environment, key, value, override_value = nil) ⇒ Object
18 19 20 |
# File 'lib/roro/configurators/question_builder.rb', line 18 def override(environment, key, value, override_value=nil) @question = "#{override_prompt(environment, key, value)}" end |
#override_prompt(environment, key, value) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/roro/configurators/question_builder.rb', line 22 def override_prompt(environment, key, value) name = value.dig(:name) || key # prompt = "Would you like to accept the default value for #{name}?\n" help = value.dig(:help) ? "#{value.dig(:help)}" : nil default = "#{key}=#{value[:value]}" ["\nEnvironment: #{environment}", " name: #{name}", " key: #{key}", " variable: #{value[:value]}", " default: #{default}", " help: #{help}\n" ].join("\n") end |
#story_from(key) ⇒ Object
78 79 80 |
# File 'lib/roro/configurators/question_builder.rb', line 78 def story_from(key) [key] end |