Class: RailsAiBridge::Generators::ProfileResolver

Inherits:
Object
  • Object
show all
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/Devin/Claude/Copilot/Gemini shims, no split rule directories.',
    formats: %i[claude cursor devin 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

Instance Method Summary collapse

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.

Parameters:

  • profile (String)

    profile name

Returns:

  • (String, nil)

    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.

Parameters:

  • profile (String)

    profile name

Returns:

  • (Array<Symbol>, nil)

    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.

Parameters:

  • profile (String)

    profile name

Returns:

  • (Boolean, nil)

    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

#callString

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.

Returns:

Raises:



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