Sha256: 177996ccb37e6497a4fcb993fec4cab4b5706f8fe5b98155f4fee36d2c77f12b

Contents?: true

Size: 1.15 KB

Versions: 9

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

require "open-uri"
require "rails/version"
require "yaml"

module Nextgen
  RailsVersion = Struct.new(
    :args,
    :label,
    :asset_pipelines,
    :databases,
    :default_features,
    :optional_features,
    keyword_init: true
  )

  class << RailsVersion
    def current
      from_yaml(:current) do |version|
        version.label.sub!("%%CURRENT_VERSION%%") { ::Rails.version }
      end
    end

    def edge
      from_yaml(:edge)
    end

    def main
      from_yaml(:main) do |version|
        version.label.sub!("%%MAIN_VERSION%%") { main_version }
      end
    end

    private

    def from_yaml(key)
      @yaml ||= begin
        yaml_path = File.expand_path("../../config/rails_versions.yml", __dir__)
        YAML.load_file(yaml_path, aliases: true, symbolize_names: true)
      end
      new(**@yaml.fetch(key)).tap do |version|
        yield(version) if block_given?
      end.freeze
    end

    def main_version
      @main_version ||= begin
        URI.open("https://raw.githubusercontent.com/rails/rails/main/RAILS_VERSION").read.strip
      rescue OpenURI::HTTPError
        "unknown"
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
nextgen-0.31.0 lib/nextgen/rails_version.rb
nextgen-0.30.0 lib/nextgen/rails_version.rb
nextgen-0.29.0 lib/nextgen/rails_version.rb
nextgen-0.28.2 lib/nextgen/rails_version.rb
nextgen-0.28.1 lib/nextgen/rails_version.rb
nextgen-0.28.0 lib/nextgen/rails_version.rb
nextgen-0.27.1 lib/nextgen/rails_version.rb
nextgen-0.27.0 lib/nextgen/rails_version.rb
nextgen-0.26.0 lib/nextgen/rails_version.rb