mongodb-version 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mongodb-version.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,11 @@
1
+ guard :bundler do
2
+ watch('Gemfile')
3
+ watch(/^.+\.gemspec/)
4
+ end
5
+
6
+ guard :rspec do
7
+ watch(%r{^spec/.+_spec\.rb$})
8
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
9
+ watch('spec/spec_helper.rb') { "spec" }
10
+ end
11
+
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Chris Winslett
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,34 @@
1
+ # Mongodb::Version
2
+
3
+ Use this gem to ask questions of MongoDB versions. You can compare versions, and determine capabilities.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'mongodb-version'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install mongodb-version
18
+
19
+ ## Usage
20
+
21
+ MongoDB::Version['2.4.6'].ttl_collections? => true
22
+ MongoDB::Version['2.0.6'].ttl_collections? => false
23
+
24
+ MongoDB::Version['2.6.0'].authentication_schemes => [2]
25
+ MongoDB::Version['2.4.6'].authentication_schemes => [1,2]
26
+ MongoDB::Version['2.2.6'].authentication_schemes => [1]
27
+
28
+ ## Contributing
29
+
30
+ 1. Fork it
31
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
32
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
33
+ 4. Push to the branch (`git push origin my-new-feature`)
34
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,85 @@
1
+ require "mongodb/version/version"
2
+
3
+ module MongoDB
4
+
5
+ class Version
6
+ attr_reader :major, :minor, :patch, :special
7
+
8
+ def initialize(version)
9
+ raise "Nil versions are useless to me" if version.nil?
10
+
11
+ @major, @minor, @patch, @special = version.match(/^([\d]+)\.([\d]+)\.([\d]+)(?:\-(.+))?$/).to_a[1..-1]
12
+
13
+ @major = @major.to_i
14
+ @minor = @minor.to_i
15
+ @patch = @patch.to_i
16
+ end
17
+
18
+ def self.[](version)
19
+ version.is_a?(Version) ? version : self.new(version)
20
+ end
21
+
22
+ def >(version)
23
+ version = Version[version]
24
+ self.major > version.major && self.minor > version.minor && self.patch > version.patch
25
+ end
26
+
27
+ def >(other)
28
+ compare([:>, :>, :>], other)
29
+ end
30
+
31
+ def <(other)
32
+ compare([:<, :<, :<], other)
33
+ end
34
+
35
+ def >=(other)
36
+ compare([:>, :>, :>=], other)
37
+ end
38
+
39
+ def <=(other)
40
+ compare([:<, :<, :<=], other)
41
+ end
42
+
43
+ def ==(other)
44
+ compare([:==, :==, :==], other)
45
+ end
46
+
47
+ def ===(other)
48
+ self == other && special == Version[other].special
49
+ end
50
+
51
+ def compare(operators, other)
52
+ other = Version[other] unless other.is_a?(Version)
53
+
54
+ major.send(operators.shift, other.major) || # Major match method?
55
+ ((major == other.major) && # Major equal and further comparison?
56
+ minor.send(operators.shift, other.minor) || # Minor match method?
57
+ ((minor == other.minor) && # Minor equal and further comparison?
58
+ patch.send(operators.shift, other.patch))) # Patch match method?
59
+ end
60
+
61
+ def ttl_collections?
62
+ self >= "2.2.0"
63
+ end
64
+
65
+ def authentication_schemes
66
+ case
67
+ when self < "2.4.0" then [1]
68
+ when self >= "2.4.0" && self < "2.6.0" then [1, 2]
69
+ when self >= "2.6.0" then [2]
70
+ end
71
+ end
72
+
73
+ def text_search
74
+ case
75
+ when self >= "2.4.0" && self < "2.6.0" then :beta
76
+ when self >= "2.6.0" then :production
77
+ end
78
+ end
79
+
80
+ def text_search?
81
+ !!text_search
82
+ end
83
+ end
84
+
85
+ end
@@ -0,0 +1,5 @@
1
+ module MongoDB
2
+ class Version
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mongodb/version/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "mongodb-version"
8
+ spec.version = MongoDB::Version::VERSION
9
+ spec.authors = ["Chris Winslett"]
10
+ spec.email = ["chris@mongohq.com"]
11
+ spec.description = %q{An easy gem to use to ask questions about MongoDB versions}
12
+ spec.summary = %q{You ask, it answers. If it is not answering properly, just submit a pull request :)}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "rspec"
22
+ spec.add_development_dependency "pry-debugger"
23
+ spec.add_development_dependency "guard-rspec"
24
+ spec.add_development_dependency "guard-bundler"
25
+ spec.add_development_dependency "bundler", "~> 1.3"
26
+ spec.add_development_dependency "rake"
27
+ end
@@ -0,0 +1,76 @@
1
+ require 'spec_helper'
2
+
3
+ describe MongoDB::Version do
4
+
5
+ it "breaks a version into pieces" do
6
+ v = MongoDB::Version['2.4.6']
7
+ v.major.should eq(2)
8
+ v.minor.should eq(4)
9
+ v.patch.should eq(6)
10
+ v.special.should eq(nil)
11
+ end
12
+
13
+ it "breaks a version into pieces" do
14
+ v = MongoDB::Version['2.6.0-ssl']
15
+ v.major.should eq(2)
16
+ v.minor.should eq(6)
17
+ v.patch.should eq(0)
18
+ v.special.should eq("ssl")
19
+ end
20
+
21
+ it "compares versions and version strings" do
22
+ (MongoDB::Version['2.4.6'] < '2.4.7').should eq(true)
23
+ (MongoDB::Version['2.4.6'] < MongoDB::Version['2.4.5']).should eq(false)
24
+
25
+ (MongoDB::Version['6.0.0'] > MongoDB::Version['1.9.9']).should eq(true)
26
+ (MongoDB::Version['6.0.0'] < MongoDB::Version['1.9.9']).should eq(false)
27
+
28
+ (MongoDB::Version['2.4.6'] > MongoDB::Version['2.4.5']).should eq(true)
29
+ (MongoDB::Version['2.4.6'] > MongoDB::Version['2.4.7']).should eq(false)
30
+
31
+ (MongoDB::Version['2.4.6'] >= MongoDB::Version['2.4.5-ssl']).should eq(true)
32
+ (MongoDB::Version['2.4.6'] >= MongoDB::Version['2.4.6-ssl']).should eq(true)
33
+ (MongoDB::Version['2.4.5'] >= MongoDB::Version['2.4.6-ssl']).should eq(false)
34
+
35
+ (MongoDB::Version['2.4.5'] <= MongoDB::Version['2.4.6-ssl']).should eq(true)
36
+ (MongoDB::Version['2.4.5'] <= MongoDB::Version['2.4.5-ssl']).should eq(true)
37
+ (MongoDB::Version['2.4.7'] <= MongoDB::Version['2.4.5-ssl']).should eq(false)
38
+
39
+ (MongoDB::Version['2.4.6'] == MongoDB::Version['2.4.6-ssl']).should eq(true)
40
+ (MongoDB::Version['2.4.6'] === MongoDB::Version['2.4.6-ssl']).should eq(false)
41
+ end
42
+
43
+ it "manages TTL collections" do
44
+ MongoDB::Version['2.4.6'].ttl_collections?.should eq(true)
45
+ MongoDB::Version['2.0.6'].ttl_collections?.should eq(false)
46
+ end
47
+
48
+ it "manages TTL collections" do
49
+ MongoDB::Version['2.6.0-rc0'].authentication_schemes.should eq([2])
50
+ MongoDB::Version['2.4.0'].authentication_schemes.should eq([1,2])
51
+ MongoDB::Version['2.2.4'].authentication_schemes.should eq([1])
52
+ end
53
+
54
+ it "manages text search" do
55
+ MongoDB::Version['2.6.0-rc0'].text_search.should eq(:production)
56
+ MongoDB::Version['2.4.0'].text_search.should eq(:beta)
57
+
58
+ MongoDB::Version['2.6.0-rc0'].text_search?.should eq(true)
59
+ MongoDB::Version['2.4.0'].text_search?.should eq(true)
60
+ MongoDB::Version['2.2.0'].text_search?.should eq(false)
61
+ end
62
+
63
+ #it "manages upgrade paths" do
64
+ # MongoDB::Version['2.6.0'].change_version_to?("2.4.0").should eq(false) # Authentication changes
65
+ #
66
+ # MongoDB::Version['2.2.0'].change_version_to?("2.4.0").should eq(false) # Repl key issues
67
+ # MongoDB::Version['2.2.3'].change_version_to?("2.4.0").should eq(true) # Patched repl key issues
68
+ #end
69
+ #
70
+ #it "alerts for major bugs" do
71
+ # MongoDB::Version['2.2.1'].major_bugs?.should eq(false) # bad authentication
72
+ # MongoDB::Version['2.4.2'].major_bugs?.should eq(false) # other issue
73
+ # MongoDB::Version['2.4.9'].major_bugs?.should eq(true) # patched
74
+ #end
75
+
76
+ end
@@ -0,0 +1,4 @@
1
+ require 'bundler'
2
+ Bundler.require
3
+
4
+ require_relative '../lib/mongodb/version'
metadata ADDED
@@ -0,0 +1,156 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mongodb-version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Chris Winslett
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-02-27 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: pry-debugger
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: guard-rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: guard-bundler
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: bundler
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: '1.3'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: '1.3'
94
+ - !ruby/object:Gem::Dependency
95
+ name: rake
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ description: An easy gem to use to ask questions about MongoDB versions
111
+ email:
112
+ - chris@mongohq.com
113
+ executables: []
114
+ extensions: []
115
+ extra_rdoc_files: []
116
+ files:
117
+ - .gitignore
118
+ - Gemfile
119
+ - Guardfile
120
+ - LICENSE.txt
121
+ - README.md
122
+ - Rakefile
123
+ - lib/mongodb/version.rb
124
+ - lib/mongodb/version/version.rb
125
+ - mongodb-version.gemspec
126
+ - spec/lib/mongodb/version_spec.rb
127
+ - spec/spec_helper.rb
128
+ homepage: ''
129
+ licenses:
130
+ - MIT
131
+ post_install_message:
132
+ rdoc_options: []
133
+ require_paths:
134
+ - lib
135
+ required_ruby_version: !ruby/object:Gem::Requirement
136
+ none: false
137
+ requirements:
138
+ - - ! '>='
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ required_rubygems_version: !ruby/object:Gem::Requirement
142
+ none: false
143
+ requirements:
144
+ - - ! '>='
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ requirements: []
148
+ rubyforge_project:
149
+ rubygems_version: 1.8.23
150
+ signing_key:
151
+ specification_version: 3
152
+ summary: You ask, it answers. If it is not answering properly, just submit a pull
153
+ request :)
154
+ test_files:
155
+ - spec/lib/mongodb/version_spec.rb
156
+ - spec/spec_helper.rb