Class: CreateRubyGem::Compatibility::Matrix

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

Overview

Static lookup table mapping Bundler version ranges to the bundle gem options each range supports.

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

Examples:

Look up the entry for a specific Bundler version

entry = Matrix.for('3.1.0')
entry.supports_option?(:linter)  #=> true

Defined Under Namespace

Classes: Entry

Constant Summary collapse

TABLE =

Returns all known Bundler compatibility entries.

Returns:

  • (Array<Entry>)

    all known Bundler compatibility entries

[
  Entry.new(
    requirement: Gem::Requirement.new('>= 2.4', '< 3.0'),
    supported_options: {
      exe: nil,
      coc: nil,
      ext: %w[c],
      git: nil,
      github_username: nil,
      mit: nil,
      test: %w[minitest rspec test-unit],
      ci: %w[circle github gitlab],
      edit: nil,
      bundle_install: nil
    }
  ),
  Entry.new(
    requirement: Gem::Requirement.new('>= 3.0', '< 4.0'),
    supported_options: {
      exe: nil,
      coc: nil,
      changelog: nil,
      ext: %w[c],
      git: nil,
      github_username: nil,
      mit: nil,
      test: %w[minitest rspec test-unit],
      ci: %w[circle github gitlab],
      linter: %w[rubocop standard],
      edit: nil,
      bundle_install: nil
    }
  ),
  Entry.new(
    requirement: Gem::Requirement.new('>= 4.0', '< 5.0'),
    supported_options: {
      exe: nil,
      coc: nil,
      changelog: nil,
      ext: %w[c go rust],
      git: nil,
      github_username: nil,
      mit: nil,
      test: %w[minitest rspec test-unit],
      ci: %w[circle github gitlab],
      linter: %w[rubocop standard],
      edit: nil,
      bundle_install: nil
    }
  )
].freeze

Class Method Summary collapse

Class Method Details

.for(bundler_version) ⇒ Entry

Finds the compatibility entry for the given Bundler version.

Parameters:

  • bundler_version (Gem::Version, String)

    the Bundler version

Returns:

Raises:



107
108
109
110
111
112
113
114
115
# File 'lib/create_ruby_gem/compatibility/matrix.rb', line 107

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

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

.supported_rangesArray<String>

Returns human-readable version range strings for all entries.

Returns:

  • (Array<String>)


98
99
100
# File 'lib/create_ruby_gem/compatibility/matrix.rb', line 98

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