Class: Tebako::RubyVersion
- Inherits:
-
Object
- Object
- Tebako::RubyVersion
- Defined in:
- lib/tebako/ruby_version.rb
Overview
Ruby version
Direct Known Subclasses
Constant Summary collapse
- RUBY_VERSIONS =
Supported Ruby versions: latest patch release of each maintained line (3.2+ through 4.0). Support for 2.7.x, 3.0.x and 3.1.x was dropped.
{ "3.2.11" => "b3eeabd6636f334531db3ffdc3229eb05e524740e6c84fdc043720573cf2f8b2", "3.3.11" => "59f0fafb1a59a05dc3765117af3fa68e153eb48254708549f321c1e9e078d7a0", "3.4.10" => "ecee2d072a14f2d14347dd56dfd8fe5c3130abf5117bfaacbda0f4ef9cc429ec", "4.0.6" => "837d299e8f7ddf2be31a229a7a7e019d354979825117989acb3b32b1a9be262a" }.freeze
- MIN_RUBY_VERSION_WINDOWS =
"3.2.11"- DEFAULT_RUBY_VERSION =
"4.0.6"
Instance Attribute Summary collapse
-
#ruby_version ⇒ Object
readonly
Returns the value of attribute ruby_version.
Instance Method Summary collapse
- #api_version ⇒ Object
- #extend_ruby_version ⇒ Object
-
#initialize(ruby_version) ⇒ RubyVersion
constructor
A new instance of RubyVersion.
- #lib_version ⇒ Object
- #ruby31? ⇒ Boolean
- #ruby32? ⇒ Boolean
- #ruby32only? ⇒ Boolean
- #ruby33? ⇒ Boolean
- #ruby33only? ⇒ Boolean
- #ruby34? ⇒ Boolean
- #ruby3x7? ⇒ Boolean
-
#ruby3x? ⇒ Boolean
Version predicates are "this behavior applies to this version and newer", compared on Gem::Version so they are correct for Ruby 4.x (major != 3) and for two-digit patch levels (e.g. 3.3.11, 3.4.10).
- #run_checks ⇒ Object
- #version_check ⇒ Object
- #version_check_format ⇒ Object
- #version_check_msys ⇒ Object
Constructor Details
#initialize(ruby_version) ⇒ RubyVersion
Returns a new instance of RubyVersion.
47 48 49 50 51 |
# File 'lib/tebako/ruby_version.rb', line 47 def initialize(ruby_version) @ruby_version = ruby_version.nil? ? DEFAULT_RUBY_VERSION : ruby_version run_checks end |
Instance Attribute Details
#ruby_version ⇒ Object (readonly)
Returns the value of attribute ruby_version.
53 54 55 |
# File 'lib/tebako/ruby_version.rb', line 53 def ruby_version @ruby_version end |
Instance Method Details
#api_version ⇒ Object
55 56 57 |
# File 'lib/tebako/ruby_version.rb', line 55 def api_version @api_version ||= "#{@ruby_version.split(".")[0..1].join(".")}.0" end |
#extend_ruby_version ⇒ Object
59 60 61 |
# File 'lib/tebako/ruby_version.rb', line 59 def extend_ruby_version @extend_ruby_version ||= [@ruby_version, RUBY_VERSIONS[@ruby_version]] end |
#lib_version ⇒ Object
63 64 65 |
# File 'lib/tebako/ruby_version.rb', line 63 def lib_version @lib_version ||= "#{@ruby_version.split(".")[0..1].join}0" end |
#ruby31? ⇒ Boolean
75 76 77 |
# File 'lib/tebako/ruby_version.rb', line 75 def ruby31? @ruby31 ||= at_least?("3.1.0") end |
#ruby32? ⇒ Boolean
79 80 81 |
# File 'lib/tebako/ruby_version.rb', line 79 def ruby32? @ruby32 ||= at_least?("3.2.0") end |
#ruby32only? ⇒ Boolean
83 84 85 |
# File 'lib/tebako/ruby_version.rb', line 83 def ruby32only? @ruby32only ||= minor_line?(3, 2) end |
#ruby33? ⇒ Boolean
87 88 89 |
# File 'lib/tebako/ruby_version.rb', line 87 def ruby33? @ruby33 ||= at_least?("3.3.0") end |
#ruby33only? ⇒ Boolean
91 92 93 |
# File 'lib/tebako/ruby_version.rb', line 91 def ruby33only? @ruby33only ||= minor_line?(3, 3) end |
#ruby34? ⇒ Boolean
101 102 103 |
# File 'lib/tebako/ruby_version.rb', line 101 def ruby34? @ruby34 ||= at_least?("3.4.0") end |
#ruby3x7? ⇒ Boolean
95 96 97 98 99 |
# File 'lib/tebako/ruby_version.rb', line 95 def ruby3x7? @ruby3x7 ||= ruby34? || (ruby32only? && teeny >= 7) || (ruby33only? && teeny >= 7) end |
#ruby3x? ⇒ Boolean
Version predicates are "this behavior applies to this version and newer", compared on Gem::Version so they are correct for Ruby 4.x (major != 3) and for two-digit patch levels (e.g. 3.3.11, 3.4.10). Ruby 4.0 satisfies the >= 3.x gates by design - it inherits the latest (3.4+) build behavior.
71 72 73 |
# File 'lib/tebako/ruby_version.rb', line 71 def ruby3x? @ruby3x ||= at_least?("3.0.0") end |
#run_checks ⇒ Object
105 106 107 108 109 |
# File 'lib/tebako/ruby_version.rb', line 105 def run_checks version_check_format version_check version_check_msys end |
#version_check ⇒ Object
111 112 113 114 115 116 117 118 |
# File 'lib/tebako/ruby_version.rb', line 111 def version_check return if RUBY_VERSIONS.key?(@ruby_version) raise Tebako::Error.new( "Ruby version #{@ruby_version} is not supported", 110 ) end |
#version_check_format ⇒ Object
120 121 122 123 124 |
# File 'lib/tebako/ruby_version.rb', line 120 def version_check_format return if @ruby_version =~ /^\d+\.\d+\.\d+$/ raise Tebako::Error.new("Invalid Ruby version format '#{@ruby_version}'. Expected format: x.y.z", 109) end |
#version_check_msys ⇒ Object
126 127 128 129 130 |
# File 'lib/tebako/ruby_version.rb', line 126 def version_check_msys if Gem::Version.new(@ruby_version) < Gem::Version.new(MIN_RUBY_VERSION_WINDOWS) && ScenarioManagerBase.new.msys? raise Tebako::Error.new("Ruby version #{@ruby_version} is not supported on Windows", 111) end end |