Class: CreateRailsApp::Compatibility::Matrix

Inherits:
Object
  • Object
show all
Defined in:
lib/create_rails_app/compatibility/matrix.rb

Overview

Static lookup table mapping Rails version ranges to the rails new options each range supports.

This is the single source of truth for what each Rails version can do. The wizard, validator, and builder all consult it.

Examples:

Look up the entry for a specific Rails version

entry = Matrix.for('8.0.1')
entry.supports_option?(:kamal)  #=> true

Defined Under Namespace

Classes: Entry

Constant Summary collapse

SUPPORTED_SERIES =

Supported Rails series for version detection and installation.

Returns:

%w[7.2 8.0 8.1].freeze
COMMON_OPTIONS =

Options shared across all supported Rails versions. Enum values are derived from Catalog to prevent drift.

{
  api: nil,
  database: Options::Catalog::BASE_DATABASE_VALUES,
  javascript: Options::Catalog::DEFINITIONS[:javascript][:values],
  css: Options::Catalog::DEFINITIONS[:css][:values],
  asset_pipeline: Options::Catalog::DEFINITIONS[:asset_pipeline][:values],
  active_record: nil,
  action_mailer: nil,
  action_mailbox: nil,
  action_text: nil,
  active_job: nil,
  active_storage: nil,
  action_cable: nil,
  hotwire: nil,
  jbuilder: nil,
  test: nil,
  system_test: nil,
  brakeman: nil,
  rubocop: nil,
  ci: nil,
  docker: nil,
  devcontainer: nil,
  bootsnap: nil,
  dev_gems: nil,
  keeps: nil,
  decrypted_diffs: nil,
  git: nil,
  bundle: nil
}.freeze
RAILS_8_OPTIONS =

Options added or changed in Rails 8.0+.

{
  kamal: nil,
  thruster: nil,
  solid: nil,
  database: Options::Catalog::DEFINITIONS[:database][:values],
  asset_pipeline: nil
}.freeze
RAILS_81_OPTIONS =

Options added in Rails 8.1+.

{
  bundler_audit: nil
}.freeze
TABLE =

Returns all known Rails compatibility entries.

Returns:

  • all known Rails compatibility entries

[
  Entry.new(
    requirement: Gem::Requirement.new('~> 7.2.0'),
    supported_options: COMMON_OPTIONS.dup.freeze
  ),
  Entry.new(
    requirement: Gem::Requirement.new('~> 8.0.0'),
    supported_options: COMMON_OPTIONS.merge(RAILS_8_OPTIONS).freeze
  ),
  Entry.new(
    requirement: Gem::Requirement.new('~> 8.1.0'),
    supported_options: COMMON_OPTIONS.merge(RAILS_8_OPTIONS).merge(RAILS_81_OPTIONS).freeze
  )
].freeze

Class Method Summary collapse

Class Method Details

.for(rails_version) ⇒ Entry

Finds the compatibility entry for the given Rails version.

Parameters:

  • the Rails version

Returns:

Raises:

  • if no entry matches



121
122
123
124
125
126
127
128
129
# File 'lib/create_rails_app/compatibility/matrix.rb', line 121

def self.for(rails_version)
  version = Gem::Version.new(rails_version.to_s)
  entry = TABLE.find { |candidate| candidate.match?(version) }
  return entry if entry

  message = "Unsupported Rails version: #{version}. "
  message += "Supported ranges: #{supported_ranges.join(' | ')}"
  raise UnsupportedRailsVersionError, message
end

.supported_rangesArray<String>

Returns human-readable version range strings for all entries.

Returns:



112
113
114
# File 'lib/create_rails_app/compatibility/matrix.rb', line 112

def self.supported_ranges
  TABLE.map { |entry| entry.requirement.requirements.map(&:join).join(', ') }
end