VersionCheck 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
File without changes
@@ -0,0 +1,6 @@
1
+ === 1.0.0 / 2012-09-28
2
+
3
+ * 1 major enhancement
4
+
5
+ * Birthday!
6
+
@@ -0,0 +1,6 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ lib/versioncheck.rb
6
+ test/test_versioncheck.rb
@@ -0,0 +1,77 @@
1
+ = versioncheck
2
+
3
+ * http://rubyforge.org/projects/versioncheck/
4
+
5
+ == DESCRIPTION:
6
+
7
+ VersionCheck is a ruby class provides tests against a packages version
8
+ so we can determine if our code is running in the version we want
9
+ or is running on a version later than the version we need.
10
+
11
+ Special initializer, VersionCheck.rubyversion, sets up VersionCheck instance
12
+ we can use to check against current Ruby major,minor,update and patch level.
13
+
14
+ == FEATURES/PROBLEMS:
15
+
16
+
17
+ == SYNOPSIS:
18
+
19
+ require 'rubygems'
20
+ require 'versioncheck'
21
+ vc = VersionCheck.new(major,minor,update,build)
22
+
23
+ #to conditionally run code based on having exactly the version x,y
24
+ if vc.have_version?(x,y)
25
+ ...
26
+ end
27
+
28
+ #to conditionally run code based on having at least the given version x,y
29
+ if vc.have_at_least_version?(x,y)
30
+ ...
31
+ end
32
+
33
+ rb_vc = VersionCheck.rubyversion #Equivalent to VersionCheck.new with RubyVersion and patchlevel as params
34
+ #Check the ruby version is at least version 1.9
35
+ if rb_vc.have_at_least_version?("1.9")
36
+ ...
37
+ end
38
+
39
+ #Check the ruby version is at least version 1.8.6
40
+ if rb_vc.have_at_least_version?("1.8.6")
41
+ ...
42
+ end
43
+
44
+
45
+
46
+ == REQUIREMENTS:
47
+
48
+ * require 'rubygems'
49
+
50
+ == INSTALL:
51
+
52
+ * sudo gem install versioncheck
53
+
54
+ == LICENSE:
55
+
56
+ (The MIT License)
57
+
58
+ Copyright (c) 2012 FIX
59
+
60
+ Permission is hereby granted, free of charge, to any person obtaining
61
+ a copy of this software and associated documentation files (the
62
+ 'Software'), to deal in the Software without restriction, including
63
+ without limitation the rights to use, copy, modify, merge, publish,
64
+ distribute, sublicense, and/or sell copies of the Software, and to
65
+ permit persons to whom the Software is furnished to do so, subject to
66
+ the following conditions:
67
+
68
+ The above copyright notice and this permission notice shall be
69
+ included in all copies or substantial portions of the Software.
70
+
71
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
72
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
73
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
74
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
75
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
76
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
77
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,13 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+ #require './lib/versioncheck.rb'
6
+ Hoe.plugin :minitest
7
+
8
+ Hoe.spec 'VersionCheck' do
9
+ self.rubyforge_name = 'versionchecker'
10
+ developer 'Rob Burrowes', 'r.burrowes@auckland.ac.nz'
11
+ #extra_deps << 'whatevs'
12
+ end
13
+
@@ -0,0 +1,110 @@
1
+ #VersionCheck is a ruby class provides tests against a packages version
2
+ #so we can determine if our code is running in the version we want
3
+ #or is running on a version later than the version we need.
4
+ #
5
+ #Naming convention used:
6
+ # RUBY_VERSION 1.8.7 patch level 249
7
+ # is Rubyvesion.major = 1, VersionCheck.minor = 8, VersionCheck.update = 7
8
+ # VersionCheck.build = 249 or VersionCheck.patchlevel = 249
9
+ #
10
+ #Special initializer, VersionCheck.rubyversion, sets up VersionCheck instance
11
+ #we can use to check against current Ruby major,minor,update and patch level.
12
+
13
+ class VersionCheck
14
+ VERSION = '1.0.0' #version of class VersionCheck
15
+
16
+ attr_accessor :major, :minor, :update, :build
17
+ alias patchlevel build
18
+
19
+ #Set up the version we are going to check against.
20
+ def initialize(major,minor=0,update=0,build=0)
21
+ if major.class == Float
22
+ major = major.to_s
23
+ end
24
+ if major.class == String
25
+ major,minor,update = major.split('.').collect { |x| x.to_i }
26
+ end
27
+ @major = major != nil ? major.to_i : 0
28
+ @minor = minor != nil ? minor.to_i : 0
29
+ @update = update != nil ? update.to_i : 0
30
+ @build = build != nil ? build.to_i : 0
31
+ end
32
+
33
+ #Short cut to setting up VersionCheck against current RUBY_VERSION and RUBY_PATCHLEVEL
34
+ def self.rubyversion
35
+ major,minor,update = RUBY_VERSION.split('.').collect { |i| i.to_i }
36
+ self.new(major,minor,update, RUBY_PATCHLEVEL.to_i)
37
+ end
38
+
39
+ #have_version tests that the versien of RUBY is the one we want.
40
+ #Returns true if match to arguments is exact, otherwise false.
41
+ # If update and build are not specified, they are not tested for.
42
+ #Can take:
43
+ # a single float argument.
44
+ # e.g. VersionCheck.have_version?(1.8) Tests for version 1.8 with any update or build version
45
+ # a single string argument.
46
+ # e.g. VersionCheck.have_version?("1") Tests for version 1 with any minor, update or build version
47
+ # e.g. VersionCheck.have_version?("1.8") Tests for version 1.8 with any update or build version
48
+ # VersionCheck.have_version?("1.8.7") Tests for version 1.8.7 with and build version
49
+ # Integer arguments major, minor, update and build
50
+ # e.g. VersionCheck.have_version?(1) Tests for version 1 with any minor, update or build version
51
+ # VersionCheck.have_version?(1,8) Tests for version 1.8 with any update or build version
52
+ # VersionCheck.have_version?(1,8,7) Tests for version 1.8.7 with and build version
53
+ # VersionCheck.have_version?(1,8,7,249) Test for 1.8.7 build 249
54
+ def have_version?(major, minor = nil, update = nil, build = nil)
55
+ if major.class == Float
56
+ major = major.to_s
57
+ end
58
+ if major.class == String
59
+ major,minor,update = major.split('.').collect { |x| x.to_i }
60
+ end
61
+ if major == @major
62
+ return false if minor != nil && minor != @minor
63
+ return false if update != nil && update != @update
64
+ return false if build != nil && build != @build
65
+ return true
66
+ else
67
+ return false
68
+ end
69
+ end
70
+
71
+ #have_at_least_version tests that the versien of RUBY is newer than the one we want.
72
+ #major, minor, update and build are integers.
73
+ #If update and or build are missing, then any update or build version
74
+ #will return true, as long as the major and minor numbers match,
75
+ #or the running Ruby verion major.minor numbers are for a newer version.
76
+ def have_at_least_version?(major, minor = nil, update = nil, build = nil)
77
+ if major.class == Float
78
+ major = major.to_s
79
+ end
80
+ if major.class == String
81
+ major,minor,update = major.split('.').collect { |x| x.to_i }
82
+ end
83
+ if major == @major #Could true
84
+ if minor != nil #Being asked to test minor level
85
+ if minor == @minor #Could be true
86
+ if update != nil #Being asked to test update level
87
+ if update == @update #Could be true
88
+ if build != nil #Being asked to test the build version
89
+ return build <= @build #have at least the required patch level.
90
+ end
91
+ return true #update was equal
92
+ end
93
+ return update < @update #current version is newer
94
+ end
95
+ return true #major and minor was equal.
96
+ end
97
+ return minor < @minor #true if current version is newer
98
+ end
99
+ return true #major was equal.
100
+ end
101
+ return major < @major #true, if current version is newer
102
+ end
103
+
104
+ #to_s returns the current Ruby version and build as a string.
105
+ def to_s
106
+ "#{@major}.#{@minor}.#{@update} Build #{@build}"
107
+ end
108
+
109
+
110
+ end
@@ -0,0 +1,177 @@
1
+ require 'rubygems'
2
+ require 'minitest/autorun'
3
+ require "versioncheck"
4
+
5
+ #Self fulfilling prophecy
6
+ CURRENT_VERSION_MAJOR, CURRENT_VERSION_MINOR, CURRENT_VERSION_UPDATE = RUBY_VERSION.split('.').collect { |i| i.to_i }
7
+ CURRENT_VERSION_BUILD = RUBY_PATCHLEVEL.to_i
8
+
9
+ #Easier to see what is going wrong if tests run in order. There is no order interaction possible anyway
10
+ MiniTest::Unit::TestCase.i_suck_and_my_tests_are_order_dependent!
11
+ puts MiniTest::Unit::TestCase.test_order #Tests run in alpha order, which is why the have A. and 1. markers in the lines
12
+
13
+ describe VersionCheck do
14
+
15
+ before do
16
+ @rubyversion = VersionCheck.new(CURRENT_VERSION_MAJOR, CURRENT_VERSION_MINOR, CURRENT_VERSION_UPDATE, CURRENT_VERSION_BUILD)
17
+ end
18
+
19
+ describe "A. When asking if we have this version, against the same version parameters" do
20
+ #Current Version test
21
+ it "1. has current major version, when passing parameters as integers" do
22
+ @rubyversion.have_version?(CURRENT_VERSION_MAJOR).must_equal true
23
+ end
24
+
25
+ it "2. has current major and minor version, when passing parameters as integers" do
26
+ @rubyversion.have_version?(CURRENT_VERSION_MAJOR,CURRENT_VERSION_MINOR).must_equal true
27
+ end
28
+
29
+ it "3. has current major, minor and update version, when passing parameters as integers" do
30
+ @rubyversion.have_version?(CURRENT_VERSION_MAJOR,CURRENT_VERSION_MINOR,CURRENT_VERSION_UPDATE).must_equal true
31
+ end
32
+
33
+ it "4. has current major, minor, update and build version, when passing parameters as integers" do
34
+ @rubyversion.have_version?(CURRENT_VERSION_MAJOR,CURRENT_VERSION_MINOR,CURRENT_VERSION_UPDATE, CURRENT_VERSION_BUILD).must_equal true
35
+ end
36
+
37
+ it "5. has current major and minor version, when passing parameters as a String" do
38
+ @rubyversion.have_version?("#{CURRENT_VERSION_MAJOR}.#{CURRENT_VERSION_MINOR}").must_equal true
39
+ end
40
+
41
+ it "6. has current major, minor and update version, when passing parameters as a String" do
42
+ @rubyversion.have_version?("#{CURRENT_VERSION_MAJOR}.#{CURRENT_VERSION_MINOR}.#{CURRENT_VERSION_UPDATE}").must_equal true
43
+ end
44
+
45
+ it "7. has current major and minor version, when passing parameters as a Float" do
46
+ @rubyversion.have_version?("#{CURRENT_VERSION_MAJOR}.#{CURRENT_VERSION_MINOR}".to_f).must_equal true
47
+ end
48
+ end
49
+
50
+ describe "B. When asking if we have this version against a later version" do
51
+ #We assume that we don't need to repeat these for the different input methods, as the above tests checked that they worked.
52
+
53
+ it "1. doesn't match later major version" do
54
+ @rubyversion.have_version?(CURRENT_VERSION_MAJOR - 1).must_equal false
55
+ end
56
+
57
+ it "2. doesn't match later major and minor version" do
58
+ @rubyversion.have_version?(CURRENT_VERSION_MAJOR,CURRENT_VERSION_MINOR - 1).must_equal false
59
+ end
60
+
61
+ it "3. doen't match later major, minor and update version" do
62
+ @rubyversion.have_version?(CURRENT_VERSION_MAJOR,CURRENT_VERSION_MINOR,CURRENT_VERSION_UPDATE - 1).must_equal false
63
+ end
64
+
65
+ it "4. doen't match later major, minor, update, build version" do
66
+ @rubyversion.have_version?(CURRENT_VERSION_MAJOR,CURRENT_VERSION_MINOR,CURRENT_VERSION_UPDATE, CURRENT_VERSION_BUILD - 1).must_equal false
67
+ end
68
+ end
69
+
70
+ describe "C.When asking if we have this version, against an earlier version" do
71
+
72
+ it "1. doesn't match earlier major version, when given as integers" do
73
+ @rubyversion.have_version?(CURRENT_VERSION_MAJOR + 1).must_equal false
74
+ end
75
+
76
+ it "2. doesn't match earlier major and minor version" do
77
+ @rubyversion.have_version?(CURRENT_VERSION_MAJOR,CURRENT_VERSION_MINOR + 1).must_equal false
78
+ end
79
+
80
+ it "3. doen't match earlier major, minor and update version, when given as integers" do
81
+ @rubyversion.have_version?(CURRENT_VERSION_MAJOR,CURRENT_VERSION_MINOR,CURRENT_VERSION_UPDATE + 1).must_equal false
82
+ end
83
+
84
+ it "4. doen't match earlier major, minor, update, build version" do
85
+ @rubyversion.have_version?(CURRENT_VERSION_MAJOR,CURRENT_VERSION_MINOR,CURRENT_VERSION_UPDATE, CURRENT_VERSION_BUILD + 1).must_equal false
86
+ end
87
+ end
88
+
89
+ describe "D: Check current version using have_at_least_version?" do
90
+ #Newer Version Tests against current version
91
+ it "1. has at least major, when given as integers" do
92
+ @rubyversion.have_at_least_version?(CURRENT_VERSION_MAJOR).must_equal true
93
+ end
94
+
95
+ it "2. has at least major and minor version, when given as integers" do
96
+ @rubyversion.have_at_least_version?(CURRENT_VERSION_MAJOR,CURRENT_VERSION_MINOR).must_equal true
97
+ end
98
+
99
+ it "3. has at least major, minor and update version, when given as integers" do
100
+ @rubyversion.have_at_least_version?(CURRENT_VERSION_MAJOR,CURRENT_VERSION_MINOR,CURRENT_VERSION_UPDATE).must_equal true
101
+ end
102
+
103
+ it "4. has at least major, minor, update and build version, when given as integers" do
104
+ @rubyversion.have_at_least_version?(CURRENT_VERSION_MAJOR,CURRENT_VERSION_MINOR,CURRENT_VERSION_UPDATE, CURRENT_VERSION_BUILD).must_equal true
105
+ end
106
+
107
+ it "5. has at least major version, when given as a String" do
108
+ @rubyversion.have_at_least_version?("#{CURRENT_VERSION_MAJOR}").must_equal true
109
+ end
110
+
111
+ it "6. has at least major and minor version, when given as a String" do
112
+ @rubyversion.have_at_least_version?("#{CURRENT_VERSION_MAJOR}.#{CURRENT_VERSION_MINOR}").must_equal true
113
+ end
114
+
115
+ it "7. has at least major, minor and update version, when given as String" do
116
+ @rubyversion.have_at_least_version?("#{CURRENT_VERSION_MAJOR}.#{CURRENT_VERSION_MINOR}.#{CURRENT_VERSION_UPDATE}").must_equal true
117
+ end
118
+
119
+ it "8. has at least major and minor version, when given as a Float" do
120
+ @rubyversion.have_at_least_version?("#{CURRENT_VERSION_MAJOR}.#{CURRENT_VERSION_MINOR}".to_f).must_equal true
121
+ end
122
+ end
123
+
124
+ describe "E: Check next version, against current version, using have_at_least_version? " do
125
+ #Newer Version Tests against previous and later versions
126
+ it "1. has at least major version, when given as larger integers" do
127
+ @rubyversion.have_at_least_version?(CURRENT_VERSION_MAJOR + 1).must_equal false #We asked for version after the one we have
128
+ end
129
+
130
+ it "2. has at least major and minor version, when given as larger integers" do
131
+ @rubyversion.have_at_least_version?(CURRENT_VERSION_MAJOR,CURRENT_VERSION_MINOR + 1).must_equal false #We asked for version after the one we have
132
+ end
133
+
134
+ it "3. has at least major, minor and update version, when given as larger integers" do
135
+ @rubyversion.have_at_least_version?(CURRENT_VERSION_MAJOR,CURRENT_VERSION_MINOR,CURRENT_VERSION_UPDATE + 1).must_equal false #We asked for version after the one we have
136
+ end
137
+
138
+ it "4. has at least major, minor, update and build version, when given as larger integers" do
139
+ @rubyversion.have_at_least_version?(CURRENT_VERSION_MAJOR,CURRENT_VERSION_MINOR,CURRENT_VERSION_UPDATE, CURRENT_VERSION_BUILD + 1).must_equal false #We asked for version after the one we have
140
+ end
141
+ end
142
+
143
+ describe "F: Check previous version against current version, usig have_at_least_version?" do
144
+ it "1. doesn't have at least the major version, when given as smaller integers" do
145
+ @rubyversion.have_at_least_version?(CURRENT_VERSION_MAJOR - 1).must_equal true
146
+ end
147
+
148
+ it "2. doesn't have at least major and minor version, when given as smaller integers" do
149
+ @rubyversion.have_at_least_version?(CURRENT_VERSION_MAJOR,CURRENT_VERSION_MINOR - 1).must_equal true
150
+ end
151
+
152
+ it "3. doesn't have at least major, minor and update version, when given as smaller bintegers" do
153
+ @rubyversion.have_at_least_version?(CURRENT_VERSION_MAJOR,CURRENT_VERSION_MINOR,CURRENT_VERSION_UPDATE - 1).must_equal true
154
+ end
155
+
156
+ it "4. doesn't have at least major, minor, update and build version, when given as smaller integers" do
157
+ @rubyversion.have_at_least_version?(CURRENT_VERSION_MAJOR,CURRENT_VERSION_MINOR,CURRENT_VERSION_UPDATE, CURRENT_VERSION_BUILD - 1).must_equal true
158
+ end
159
+ end
160
+ end
161
+
162
+ describe VersionCheck, "Ruby version initilized for you" do
163
+
164
+ before do
165
+ @rubyversion = VersionCheck.rubyversion
166
+ end
167
+
168
+ describe "A. When asking if we have this version, against the same version parameters" do
169
+ #Current Version test
170
+
171
+ it "1. has current major, minor, update and build version, when passing parameters as integers" do
172
+ @rubyversion.have_version?(CURRENT_VERSION_MAJOR,CURRENT_VERSION_MINOR,CURRENT_VERSION_UPDATE, CURRENT_VERSION_BUILD).must_equal true
173
+ end
174
+
175
+ end
176
+
177
+ end
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: VersionCheck
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Rob Burrowes
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-09-28 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: minitest
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ hash: 13
29
+ segments:
30
+ - 3
31
+ - 5
32
+ version: "3.5"
33
+ type: :development
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: rdoc
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ hash: 19
44
+ segments:
45
+ - 3
46
+ - 10
47
+ version: "3.10"
48
+ type: :development
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: hoe
52
+ prerelease: false
53
+ requirement: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ~>
57
+ - !ruby/object:Gem::Version
58
+ hash: 5
59
+ segments:
60
+ - 3
61
+ - 1
62
+ version: "3.1"
63
+ type: :development
64
+ version_requirements: *id003
65
+ description: |-
66
+ VersionCheck is a ruby class provides tests against a packages version
67
+ so we can determine if our code is running in the version we want
68
+ or is running on a version later than the version we need.
69
+
70
+ Special initializer, VersionCheck.rubyversion, sets up VersionCheck instance
71
+ we can use to check against current Ruby major,minor,update and patch level.
72
+ email:
73
+ - r.burrowes@auckland.ac.nz
74
+ executables: []
75
+
76
+ extensions: []
77
+
78
+ extra_rdoc_files:
79
+ - History.txt
80
+ - Manifest.txt
81
+ - README.txt
82
+ files:
83
+ - History.txt
84
+ - Manifest.txt
85
+ - README.txt
86
+ - Rakefile
87
+ - lib/versioncheck.rb
88
+ - test/test_versioncheck.rb
89
+ - .gemtest
90
+ homepage: http://rubyforge.org/projects/versioncheck/
91
+ licenses: []
92
+
93
+ post_install_message:
94
+ rdoc_options:
95
+ - --main
96
+ - README.txt
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ hash: 3
105
+ segments:
106
+ - 0
107
+ version: "0"
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ none: false
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ hash: 3
114
+ segments:
115
+ - 0
116
+ version: "0"
117
+ requirements: []
118
+
119
+ rubyforge_project: versionchecker
120
+ rubygems_version: 1.8.24
121
+ signing_key:
122
+ specification_version: 3
123
+ summary: VersionCheck is a ruby class provides tests against a packages version so we can determine if our code is running in the version we want or is running on a version later than the version we need
124
+ test_files:
125
+ - test/test_versioncheck.rb