Class: Tebako::RubyVersion

Inherits:
Object
  • Object
show all
Defined in:
lib/tebako/ruby_version.rb

Overview

Ruby version

Direct Known Subclasses

RubyVersionWithGemfile

Constant Summary collapse

RUBY_VERSIONS =
{
  "2.7.8" => "c2dab63cbc8f2a05526108ad419efa63a67ed4074dbbcf9fc2b1ca664cb45ba0",
  "3.0.7" => "2a3411977f2850431136b0fab8ad53af09fb74df2ee2f4fb7f11b378fe034388",
  "3.1.6" => "0d0dafb859e76763432571a3109d1537d976266be3083445651dc68deed25c22",
  "3.2.4" => "c72b3c5c30482dca18b0f868c9075f3f47d8168eaf626d4e682ce5b59c858692",
  "3.2.5" => "ef0610b498f60fb5cfd77b51adb3c10f4ca8ed9a17cb87c61e5bea314ac34a16",
  "3.2.6" => "d9cb65ecdf3f18669639f2638b63379ed6fbb17d93ae4e726d4eb2bf68a48370",
  "3.2.7" => "8488fa620ff0333c16d437f2b890bba3b67f8745fdecb1472568a6114aad9741",
  "3.3.3" => "83c05b2177ee9c335b631b29b8c077b4770166d02fa527f3a9f6a40d13f3cce2",
  "3.3.4" => "fe6a30f97d54e029768f2ddf4923699c416cdbc3a6e96db3e2d5716c7db96a34",
  "3.3.5" => "3781a3504222c2f26cb4b9eb9c1a12dbf4944d366ce24a9ff8cf99ecbce75196",
  "3.3.6" => "8dc48fffaf270f86f1019053f28e51e4da4cce32a36760a0603a9aee67d7fd8d",
  "3.3.7" => "9c37c3b12288c7aec20ca121ce76845be5bb5d77662a24919651aaf1d12c8628",
  "3.4.1" => "3d385e5d22d368b064c817a13ed8e3cc3f71a7705d7ed1bae78013c33aa7c87f",
  "3.4.2" => "41328ac21f2bfdd7de6b3565ef4f0dd7543354d37e96f157a1552a6bd0eb364b"
}.freeze
MIN_RUBY_VERSION_WINDOWS =
"3.1.6"
DEFAULT_RUBY_VERSION =
"3.3.7"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ruby_version) ⇒ RubyVersion

Returns a new instance of RubyVersion.



55
56
57
58
59
# File 'lib/tebako/ruby_version.rb', line 55

def initialize(ruby_version)
  @ruby_version = ruby_version.nil? ? DEFAULT_RUBY_VERSION : ruby_version

  run_checks
end

Instance Attribute Details

#ruby_versionObject (readonly)

Returns the value of attribute ruby_version.



61
62
63
# File 'lib/tebako/ruby_version.rb', line 61

def ruby_version
  @ruby_version
end

Instance Method Details

#api_versionObject



63
64
65
# File 'lib/tebako/ruby_version.rb', line 63

def api_version
  @api_version ||= "#{@ruby_version.split(".")[0..1].join(".")}.0"
end

#extend_ruby_versionObject



67
68
69
# File 'lib/tebako/ruby_version.rb', line 67

def extend_ruby_version
  @extend_ruby_version ||= [@ruby_version, RUBY_VERSIONS[@ruby_version]]
end

#lib_versionObject



71
72
73
# File 'lib/tebako/ruby_version.rb', line 71

def lib_version
  @lib_version ||= "#{@ruby_version.split(".")[0..1].join}0"
end

#ruby31?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/tebako/ruby_version.rb', line 79

def ruby31?
  @ruby31 ||= ruby3x? && @ruby_version[2].to_i >= 1
end

#ruby32?Boolean

Returns:

  • (Boolean)


83
84
85
# File 'lib/tebako/ruby_version.rb', line 83

def ruby32?
  @ruby32 ||= ruby3x? && @ruby_version[2].to_i >= 2
end

#ruby32only?Boolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/tebako/ruby_version.rb', line 87

def ruby32only?
  @ruby32only ||= ruby3x? && @ruby_version[2] == "2"
end

#ruby33?Boolean

Returns:

  • (Boolean)


91
92
93
# File 'lib/tebako/ruby_version.rb', line 91

def ruby33?
  @ruby33 ||= ruby3x? && @ruby_version[2].to_i >= 3
end

#ruby33only?Boolean

Returns:

  • (Boolean)


95
96
97
# File 'lib/tebako/ruby_version.rb', line 95

def ruby33only?
  @ruby33only ||= ruby3x? && @ruby_version[2] == "3"
end

#ruby34?Boolean

Returns:

  • (Boolean)


105
106
107
# File 'lib/tebako/ruby_version.rb', line 105

def ruby34?
  @ruby34 ||= ruby3x? && @ruby_version[2].to_i >= 4
end

#ruby3x7?Boolean

Returns:

  • (Boolean)


99
100
101
102
103
# File 'lib/tebako/ruby_version.rb', line 99

def ruby3x7?
  @ruby3x7 ||= ruby34? ||
               (ruby33only? && @ruby_version[4].to_i >= 7) ||
               (ruby32only? && @ruby_version[4].to_i >= 7)
end

#ruby3x?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/tebako/ruby_version.rb', line 75

def ruby3x?
  @ruby3x ||= @ruby_version[0] == "3"
end

#run_checksObject



109
110
111
112
113
# File 'lib/tebako/ruby_version.rb', line 109

def run_checks
  version_check_format
  version_check
  version_check_msys
end

#version_checkObject

Raises:



115
116
117
118
119
120
121
122
# File 'lib/tebako/ruby_version.rb', line 115

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_formatObject

Raises:



124
125
126
127
128
# File 'lib/tebako/ruby_version.rb', line 124

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_msysObject



130
131
132
133
134
# File 'lib/tebako/ruby_version.rb', line 130

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