Class: Bundler::RubyVersion

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

Direct Known Subclasses

SystemRubyVersion

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (RubyVersion) initialize(version, patchlevel, engine, engine_version)



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/bundler/ruby_version.rb', line 5

def initialize(version, 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.

  @version        = version
  @engine         = engine || "ruby"
  # keep track of the engine specified by the user
  @input_engine   = engine
  @engine_version = engine_version || version
  @patchlevel     = patchlevel
end

Instance Attribute Details

- (Object) engine (readonly)

Returns the value of attribute engine



3
4
5
# File 'lib/bundler/ruby_version.rb', line 3

def engine
  @engine
end

- (Object) engine_version (readonly)

Returns the value of attribute engine_version



3
4
5
# File 'lib/bundler/ruby_version.rb', line 3

def engine_version
  @engine_version
end

- (Object) patchlevel (readonly)

Returns the value of attribute patchlevel



3
4
5
# File 'lib/bundler/ruby_version.rb', line 3

def patchlevel
  @patchlevel
end

- (Object) version (readonly)

Returns the value of attribute version



3
4
5
# File 'lib/bundler/ruby_version.rb', line 3

def version
  @version
end

Instance Method Details

- (Object) ==(other)



34
35
36
37
38
39
# File 'lib/bundler/ruby_version.rb', line 34

def ==(other)
  version          == other.version &&
    engine         == other.engine &&
    engine_version == other.engine_version &&
    patchlevel     == other.patchlevel
end

- (Object) diff(other)

Returns a tuple of thsee things:

[diff, this, other]
The priority of attributes are
1. engine
2. ruby_version
3. engine_version


47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/bundler/ruby_version.rb', line 47

def diff(other)
  if engine != other.engine && @input_engine
    [ :engine, engine, other.engine ]
  elsif version != other.version
    [ :version, version, other.version ]
  elsif engine_version != other.engine_version && @input_engine
    [ :engine_version, engine_version, other.engine_version ]
  elsif patchlevel != other.patchlevel && @patchlevel
    [ :patchlevel, patchlevel, other.patchlevel ]
  else
    nil
  end
end

- (Object) host



61
62
63
64
65
66
67
# File 'lib/bundler/ruby_version.rb', line 61

def host
  @host ||= [
    RbConfig::CONFIG["host_cpu"],
    RbConfig::CONFIG["host_vendor"],
    RbConfig::CONFIG["host_os"]
  ].join("-")
end

- (Object) to_s



26
27
28
29
30
31
32
# File 'lib/bundler/ruby_version.rb', line 26

def to_s
  output = "ruby #{version}"
  output << "p#{patchlevel}" if patchlevel
  output << " (#{engine} #{engine_version})" unless engine == "ruby"

  output
end