Class: MongoDB::Version
- Inherits:
-
Object
- Object
- MongoDB::Version
- Defined in:
- lib/mongodb/version.rb,
lib/mongodb/version/version.rb
Constant Summary collapse
- VERSION =
"0.0.1"
Instance Attribute Summary collapse
-
#major ⇒ Object
readonly
Returns the value of attribute major.
-
#minor ⇒ Object
readonly
Returns the value of attribute minor.
-
#patch ⇒ Object
readonly
Returns the value of attribute patch.
-
#special ⇒ Object
readonly
Returns the value of attribute special.
Class Method Summary collapse
Instance Method Summary collapse
- #<(other) ⇒ Object
- #<=(other) ⇒ Object
- #==(other) ⇒ Object
- #===(other) ⇒ Object
- #>(other) ⇒ Object
- #>=(other) ⇒ Object
- #authentication_schemes ⇒ Object
- #compare(operators, other) ⇒ Object
-
#initialize(version) ⇒ Version
constructor
A new instance of Version.
- #text_search ⇒ Object
- #text_search? ⇒ Boolean
- #ttl_collections? ⇒ Boolean
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
#major ⇒ Object (readonly)
Returns the value of attribute major.
6 7 8 |
# File 'lib/mongodb/version.rb', line 6 def major @major end |
#minor ⇒ Object (readonly)
Returns the value of attribute minor.
6 7 8 |
# File 'lib/mongodb/version.rb', line 6 def minor @minor end |
#patch ⇒ Object (readonly)
Returns the value of attribute patch.
6 7 8 |
# File 'lib/mongodb/version.rb', line 6 def patch @patch end |
#special ⇒ Object (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
31 32 33 |
# File 'lib/mongodb/version.rb', line 31 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) compare([:==, :==, :==], other) end |
#===(other) ⇒ Object
47 48 49 |
# File 'lib/mongodb/version.rb', line 47 def ===(other) self == other && special == Version[other].special end |
#>(other) ⇒ Object
22 23 24 25 |
# File 'lib/mongodb/version.rb', line 22 def >(version) version = Version[version] self.major > version.major && self.minor > version.minor && self.patch > version.patch end |
#>=(other) ⇒ Object
35 36 37 |
# File 'lib/mongodb/version.rb', line 35 def >=(other) compare([:>, :>, :>=], other) end |
#authentication_schemes ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/mongodb/version.rb', line 65 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
51 52 53 54 55 56 57 58 59 |
# File 'lib/mongodb/version.rb', line 51 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_search ⇒ Object
73 74 75 76 77 78 |
# File 'lib/mongodb/version.rb', line 73 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
80 81 82 |
# File 'lib/mongodb/version.rb', line 80 def text_search? !!text_search end |
#ttl_collections? ⇒ Boolean
61 62 63 |
# File 'lib/mongodb/version.rb', line 61 def ttl_collections? self >= "2.2.0" end |