Class: RailsAiBridge::Generators::ProfileResolver
- Inherits:
-
Object
- Object
- RailsAiBridge::Generators::ProfileResolver
- Defined in:
- lib/generators/rails_ai_bridge/install/profile_resolver.rb
Overview
Resolves the install profile either from a CLI option or an interactive prompt. Accepts any object that responds to +say+ and +ask+ as the shell dependency (typically the generator itself, enabling seamless stubbing in tests).
Constant Summary collapse
- PROFILE_OPTIONS =
{ 'custom' => { description: 'Pick formats interactively (per-format prompts).', formats: nil, split_rules: true }, 'minimal' => { description: 'Thin Cursor/Windsurf/Claude/Copilot/Gemini shims, no split rule directories.', formats: %i[claude cursor windsurf copilot gemini], split_rules: false }, 'full' => { description: 'All formats plus split rule directories for every assistant.', formats: RailsAiBridge::Serializers::ContextFileSerializer::FORMAT_MAP.keys, split_rules: true }, 'mcp' => { description: 'Only .mcp.json now — generate assistant files later.', formats: [], split_rules: false } }.freeze
Class Method Summary collapse
-
.description_for(profile) ⇒ String?
Human-readable description, or +nil+ for unknown profiles.
-
.formats_for(profile) ⇒ Array<Symbol>?
Format symbols for the profile, or +nil+ for unknown profiles.
-
.split_rules_for(profile) ⇒ Boolean?
Whether to generate split-rules directories, or +nil+ for unknown profiles.
Instance Method Summary collapse
-
#call ⇒ String
Resolves the profile, raising +ArgumentError+ when a CLI option names an unrecognised profile (fail-fast) or falling back to +"custom"+ with a yellow warning when an unrecognised answer is typed interactively.
-
#initialize(option, shell:) ⇒ ProfileResolver
constructor
A new instance of ProfileResolver.
Constructor Details
#initialize(option, shell:) ⇒ ProfileResolver
Returns a new instance of ProfileResolver.
32 33 34 35 |
# File 'lib/generators/rails_ai_bridge/install/profile_resolver.rb', line 32 def initialize(option, shell:) @option = option&.to_s&.downcase @shell = shell end |
Class Method Details
.description_for(profile) ⇒ String?
Returns human-readable description, or +nil+ for unknown profiles.
63 64 65 |
# File 'lib/generators/rails_ai_bridge/install/profile_resolver.rb', line 63 def self.description_for(profile) PROFILE_OPTIONS.fetch(profile, nil)&.dig(:description) end |
.formats_for(profile) ⇒ Array<Symbol>?
Returns format symbols for the profile, or +nil+ for unknown profiles.
51 52 53 |
# File 'lib/generators/rails_ai_bridge/install/profile_resolver.rb', line 51 def self.formats_for(profile) PROFILE_OPTIONS.fetch(profile, nil)&.dig(:formats)&.dup end |
.split_rules_for(profile) ⇒ Boolean?
Returns whether to generate split-rules directories, or +nil+ for unknown profiles.
57 58 59 |
# File 'lib/generators/rails_ai_bridge/install/profile_resolver.rb', line 57 def self.split_rules_for(profile) PROFILE_OPTIONS.fetch(profile, nil)&.dig(:split_rules) end |
Instance Method Details
#call ⇒ String
Resolves the profile, raising +ArgumentError+ when a CLI option names an unrecognised profile (fail-fast) or falling back to +"custom"+ with a yellow warning when an unrecognised answer is typed interactively.
43 44 45 46 47 |
# File 'lib/generators/rails_ai_bridge/install/profile_resolver.rb', line 43 def call return resolve_from_option if @option resolve_interactively end |