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.2"

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
# 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]

  @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

Class Method Details

.[](version) ⇒ Object



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

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

Instance Method Details

#<(other) ⇒ Object



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

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

#<=(other) ⇒ Object



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

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

#==(other) ⇒ Object



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

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

#===(other) ⇒ Object



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

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

#>(other) ⇒ Object



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

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

#>=(other) ⇒ Object



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

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

#authentication_schemesObject



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

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



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

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



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

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)


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

def text_search?
  !!text_search
end

#ttl_collections?Boolean

Returns:

  • (Boolean)


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

def ttl_collections?
  self >= "2.2.0"
end