Class: MongoDB::Version

Inherits:
Object
  • Object
show all
Defined in:
lib/mongodb/version.rb,
lib/mongodb/version/version.rb

Constant Summary collapse

VERSION =
"0.0.3"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version) ⇒ Version

Returns a new instance of Version.



8
9
10
11
12
13
14
15
16
17
# File 'lib/mongodb/version.rb', line 8

def initialize(version)
  raise "Nil versions are useless to me" if version.nil?

  @major, @minor, @patch, @special = version.match(/^([\d]+)\.([\d]+)\.([\d]+)(?:\-(.+))?$/).to_a[1..-1]

  @version = version
  @major = @major.to_i
  @minor = @minor.to_i
  @patch = @patch.to_i
end

Instance Attribute Details

#majorObject (readonly)

Returns the value of attribute major.



6
7
8
# File 'lib/mongodb/version.rb', line 6

def major
  @major
end

#minorObject (readonly)

Returns the value of attribute minor.



6
7
8
# File 'lib/mongodb/version.rb', line 6

def minor
  @minor
end

#patchObject (readonly)

Returns the value of attribute patch.



6
7
8
# File 'lib/mongodb/version.rb', line 6

def patch
  @patch
end

#specialObject (readonly)

Returns the value of attribute special.



6
7
8
# File 'lib/mongodb/version.rb', line 6

def special
  @special
end

#versionObject (readonly)

Returns the value of attribute version.



6
7
8
# File 'lib/mongodb/version.rb', line 6

def version
  @version
end

Class Method Details

.[](version) ⇒ Object



19
20
21
# File 'lib/mongodb/version.rb', line 19

def self.[](version)
  version.is_a?(Version) ? version : self.new(version)
end

Instance Method Details

#<(other) ⇒ Object



27
28
29
# File 'lib/mongodb/version.rb', line 27

def <(other)
  compare([:<, :<, :<], other)
end

#<=(other) ⇒ Object



35
36
37
# File 'lib/mongodb/version.rb', line 35

def <=(other)
  compare([:<, :<, :<=], other)
end

#==(other) ⇒ Object



39
40
41
# File 'lib/mongodb/version.rb', line 39

def ==(other)
  compare([:==, :==, :==], other)
end

#===(other) ⇒ Object



43
44
45
# File 'lib/mongodb/version.rb', line 43

def ===(other)
  self == other && special == Version[other].special
end

#>(other) ⇒ Object



23
24
25
# File 'lib/mongodb/version.rb', line 23

def >(other)
  compare([:>, :>, :>], other)
end

#>=(other) ⇒ Object



31
32
33
# File 'lib/mongodb/version.rb', line 31

def >=(other)
  compare([:>, :>, :>=], other)
end

#authentication_schemesObject



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

def authentication_schemes
  case
    when self < "2.4.0" then [1]
    when self >= "2.4.0" && self < "2.6.0" then [1, 2]
    when self >= "2.6.0" then [2]
  end
end

#compare(operators, other) ⇒ Object



47
48
49
50
51
52
53
54
55
# File 'lib/mongodb/version.rb', line 47

def compare(operators, other)
  other = Version[other] unless other.is_a?(Version)

  major.send(operators.shift, other.major) ||            # Major match method?
    ((major == other.major) &&                   # Major equal and further comparison?
        minor.send(operators.shift, other.minor) ||      # Minor match method?
          ((minor == other.minor) &&             # Minor equal and further comparison?
              patch.send(operators.shift, other.patch))) # Patch match method?
end

#text_searchObject



69
70
71
72
73
74
# File 'lib/mongodb/version.rb', line 69

def text_search
  case
    when self >= "2.4.0" && self < "2.6.0" then :beta
    when self >= "2.6.0" then :production
  end
end

#text_search?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/mongodb/version.rb', line 76

def text_search?
  !!text_search
end

#ttl_collections?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/mongodb/version.rb', line 57

def ttl_collections?
  self >= "2.2.0"
end