Class: Railstart::CommandBuilder
- Inherits:
-
Object
- Object
- Railstart::CommandBuilder
- Defined in:
- lib/railstart/command_builder.rb
Overview
Translates configuration and user answers into a rails new command string.
This class provides deterministic, side-effect-free command construction.
Class Method Summary collapse
- .add_flags(flags, source, value) ⇒ Object private
-
.build(app_name, config, answers) ⇒ String
Build a
rails newcommand string using config metadata and answers. - .collect_flags(questions, answers) ⇒ Object private
- .process_multi_select(flags, question, answer) ⇒ Object private
- .process_question_flags(flags, question, answer) ⇒ Object private
- .process_select(flags, question, answer) ⇒ Object private
Class Method Details
.add_flags(flags, source, value) ⇒ Object (private)
76 77 78 79 80 81 82 83 |
# File 'lib/railstart/command_builder.rb', line 76 def add_flags(flags, source, value) flag_list = source["rails_flags"] || [source["rails_flag"]].compact flag_list.each do |flag| interpolated = Config.interpolate_flag(flag, value) flags << interpolated end end |
.build(app_name, config, answers) ⇒ String
Build a rails new command string using config metadata and answers.
25 26 27 28 |
# File 'lib/railstart/command_builder.rb', line 25 def build(app_name, config, answers) flags = collect_flags(config["questions"], answers) "rails new #{app_name} #{flags.join(" ")}".strip end |
.collect_flags(questions, answers) ⇒ Object (private)
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/railstart/command_builder.rb', line 32 def collect_flags(questions, answers) flags = [] Array(questions).each do |question| answer = answers[question["id"]] next unless answer process_question_flags(flags, question, answer) end flags end |
.process_multi_select(flags, question, answer) ⇒ Object (private)
68 69 70 71 72 73 74 |
# File 'lib/railstart/command_builder.rb', line 68 def process_multi_select(flags, question, answer) Array(question["choices"]).each do |choice| next unless Array(answer).include?(choice["value"]) add_flags(flags, choice, choice["value"]) end end |
.process_question_flags(flags, question, answer) ⇒ Object (private)
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/railstart/command_builder.rb', line 43 def process_question_flags(flags, question, answer) case question["type"] when "select" process_select(flags, question, answer) when "yes_no", "input" add_flags(flags, question, answer) when "multi_select" process_multi_select(flags, question, answer) end end |
.process_select(flags, question, answer) ⇒ Object (private)
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/railstart/command_builder.rb', line 54 def process_select(flags, question, answer) # Check if the selected choice has a choice-level rails_flag selected_choice = Array(question["choices"]).find { |choice| choice["value"] == answer } if selected_choice && (selected_choice["rails_flag"] || selected_choice["rails_flags"]) # Use choice-level flag add_flags(flags, selected_choice, answer) elsif question["rails_flag"] || question["rails_flags"] # Fall back to question-level flag add_flags(flags, question, answer) end # If neither exists, no flag is added (e.g., for choices that don't need flags) end |