Class: Bundler::RubyVersion
- Inherits:
-
Object
- Object
- Bundler::RubyVersion
- Defined in:
- lib/bundler/ruby_version.rb
Constant Summary collapse
- PATTERN =
/ ruby\s (\d+\.\d+\.\d+(?:\.\S+)?) # ruby version (?:p(-?\d+))? # optional patchlevel (?:\s\((\S+)\s(.+)\))? # optional engine info /xo.freeze
Instance Attribute Summary collapse
-
#engine ⇒ Object
readonly
Returns the value of attribute engine.
-
#engine_gem_version ⇒ Object
readonly
Returns the value of attribute engine_gem_version.
-
#engine_versions ⇒ Object
readonly
Returns the value of attribute engine_versions.
-
#gem_version ⇒ Object
readonly
Returns the value of attribute gem_version.
-
#patchlevel ⇒ Object
readonly
Returns the value of attribute patchlevel.
-
#versions ⇒ Object
readonly
Returns the value of attribute versions.
Class Method Summary collapse
-
.from_string(string) ⇒ RubyVersion, Nil
Returns a RubyVersion from the given string.
- .system ⇒ Object
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#diff(other) ⇒ Object
Returns a tuple of these things: [diff, this, other] The priority of attributes are 1.
- #host ⇒ Object
-
#initialize(versions, patchlevel, engine, engine_version) ⇒ RubyVersion
constructor
A new instance of RubyVersion.
- #single_version_string ⇒ Object
- #to_s(versions = self.versions) ⇒ Object
- #versions_string(versions) ⇒ Object
Constructor Details
#initialize(versions, patchlevel, engine, engine_version) ⇒ RubyVersion
Returns a new instance of RubyVersion.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/bundler/ruby_version.rb', line 12 def initialize(versions, patchlevel, engine, engine_version) # The parameters to this method must satisfy the # following constraints, which are verified in # the DSL: # # * If an engine is specified, an engine version # must also be specified # * If an engine version is specified, an engine # must also be specified # * If the engine is "ruby", the engine version # must not be specified, or the engine version # specified must match the version. @versions = Array(versions).map do |v| op, v = Gem::Requirement.parse(v) op == "=" ? v.to_s : "#{op} #{v}" end @gem_version = Gem::Requirement.create(@versions.first).requirements.first.last @input_engine = engine && engine.to_s @engine = engine && engine.to_s || "ruby" @engine_versions = (engine_version && Array(engine_version)) || @versions @engine_gem_version = Gem::Requirement.create(@engine_versions.first).requirements.first.last @patchlevel = patchlevel || (@gem_version.prerelease? ? "-1" : nil) end |
Instance Attribute Details
#engine ⇒ Object (readonly)
Returns the value of attribute engine.
5 6 7 |
# File 'lib/bundler/ruby_version.rb', line 5 def engine @engine end |
#engine_gem_version ⇒ Object (readonly)
Returns the value of attribute engine_gem_version.
5 6 7 |
# File 'lib/bundler/ruby_version.rb', line 5 def engine_gem_version @engine_gem_version end |
#engine_versions ⇒ Object (readonly)
Returns the value of attribute engine_versions.
5 6 7 |
# File 'lib/bundler/ruby_version.rb', line 5 def engine_versions @engine_versions end |
#gem_version ⇒ Object (readonly)
Returns the value of attribute gem_version.
5 6 7 |
# File 'lib/bundler/ruby_version.rb', line 5 def gem_version @gem_version end |
#patchlevel ⇒ Object (readonly)
Returns the value of attribute patchlevel.
5 6 7 |
# File 'lib/bundler/ruby_version.rb', line 5 def patchlevel @patchlevel end |
#versions ⇒ Object (readonly)
Returns the value of attribute versions.
5 6 7 |
# File 'lib/bundler/ruby_version.rb', line 5 def versions @versions end |
Class Method Details
.from_string(string) ⇒ RubyVersion, Nil
Returns a RubyVersion from the given string.
58 59 60 |
# File 'lib/bundler/ruby_version.rb', line 58 def self.from_string(string) new($1, $2, $3, $4) if string =~ PATTERN end |
.system ⇒ Object
104 105 106 107 108 109 110 111 |
# File 'lib/bundler/ruby_version.rb', line 104 def self.system ruby_engine = RUBY_ENGINE.dup ruby_version = Gem.ruby_version.to_s ruby_engine_version = RUBY_ENGINE == "ruby" ? ruby_version : RUBY_ENGINE_VERSION.dup patchlevel = RUBY_PATCHLEVEL.to_s @system ||= RubyVersion.new(ruby_version, patchlevel, ruby_engine, ruby_engine_version) end |
Instance Method Details
#==(other) ⇒ Object
66 67 68 69 70 71 |
# File 'lib/bundler/ruby_version.rb', line 66 def ==(other) versions == other.versions && engine == other.engine && engine_versions == other.engine_versions && patchlevel == other.patchlevel end |
#diff(other) ⇒ Object
Returns a tuple of these things:
[diff, this, other]
The priority of attributes are
1. engine
2. ruby_version
3. engine_version
87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/bundler/ruby_version.rb', line 87 def diff(other) raise ArgumentError, "Can only diff with a RubyVersion, not a #{other.class}" unless other.is_a?(RubyVersion) if engine != other.engine && @input_engine [:engine, engine, other.engine] elsif versions.empty? || !matches?(versions, other.gem_version) [:version, versions_string(versions), versions_string(other.versions)] elsif @input_engine && !matches?(engine_versions, other.engine_gem_version) [:engine_version, versions_string(engine_versions), versions_string(other.engine_versions)] elsif patchlevel && (!patchlevel.is_a?(String) || !other.patchlevel.is_a?(String) || !matches?(patchlevel, other.patchlevel)) [:patchlevel, patchlevel, other.patchlevel] end end |
#host ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/bundler/ruby_version.rb', line 73 def host @host ||= [ RbConfig::CONFIG["host_cpu"], RbConfig::CONFIG["host_vendor"], RbConfig::CONFIG["host_os"], ].join("-") end |
#single_version_string ⇒ Object
62 63 64 |
# File 'lib/bundler/ruby_version.rb', line 62 def single_version_string to_s(gem_version) end |
#to_s(versions = self.versions) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/bundler/ruby_version.rb', line 38 def to_s(versions = self.versions) output = String.new("ruby #{versions_string(versions)}") output << "p#{patchlevel}" if patchlevel && patchlevel != "-1" output << " (#{engine} #{versions_string(engine_versions)})" unless engine == "ruby" output end |
#versions_string(versions) ⇒ Object
100 101 102 |
# File 'lib/bundler/ruby_version.rb', line 100 def versions_string(versions) Array(versions).join(", ") end |