versionary 0.1.0

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,7 @@
1
+ .*.swp
2
+ .bundle
3
+ .DS_Store
4
+
5
+ # nesta / sinatra
6
+ ._*
7
+ .sass-cache
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source :rubygems
2
+
3
+ # See:
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,27 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ versionary (0.1.0)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.1.2)
10
+ rake (0.8.7)
11
+ rspec (2.6.0)
12
+ rspec-core (~> 2.6.0)
13
+ rspec-expectations (~> 2.6.0)
14
+ rspec-mocks (~> 2.6.0)
15
+ rspec-core (2.6.4)
16
+ rspec-expectations (2.6.0)
17
+ diff-lcs (~> 1.1.2)
18
+ rspec-mocks (2.6.0)
19
+
20
+ PLATFORMS
21
+ ruby
22
+
23
+ DEPENDENCIES
24
+ bundler (~> 1.0.0)
25
+ rake (~> 0.8.7)
26
+ rspec (>= 2.5.0)
27
+ versionary!
data/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # Versionary - a simple gem that allows you to compare version numbers
2
+
3
+ This was extracted from the [RiverGlide ruby template project](https://github.com/RiverGlide/ruby_project_template)
4
+
5
+ ## Synopsis
6
+
7
+ A simple, comparable, [rational](http://docs.rubygems.org/read/chapter/7), version number object.
8
+
9
+ Allows you to do things like this:
10
+
11
+ raise "not the right version" unless VersionNumber.of( RUBY_VERSION ) >= VersionNumber.of( '1.9'2' )
12
+ raise "not the right version" unless VersionNumber.of( RUBY_VERSION ) >= '1.9.2'
13
+
14
+ Or any other comparison between any VersionNumber you create:
15
+
16
+ VersionNumber.of( '0.9.10' ) > '0.9.9'
17
+ VersionNumber.of( '0.9.9' ) < '0.9.10'
18
+ VersionNumber.of( '0.9.10' ) >= '0.9.9'
19
+ VersionNumber.of( '0.9.10' ) == '0.9.10'
20
+
21
+ As you can see, it does a numerical (rather than alphabetical) comparison of the major, minor and build numbers.
22
+
23
+ It doesn't do version bumping or anything like that - but if you want to to, fork it, branch, add that ability and send us a pull request :-)
24
+
25
+ ## Usage
26
+
27
+ If you're using bundler, reference the gem in your Gemfile or gemspec as a runtime dependency and bundler will do the rest...
28
+ Or, `gem install versionary` and then:
29
+
30
+ require 'versionary/version_number'
data/Rakefile ADDED
@@ -0,0 +1,35 @@
1
+ puts "\n ** RiverGlide.com - flow without friction **\n"
2
+
3
+ ENV[ 'MINIMUM_RUBY_VERSION' ] = '1.8.7'
4
+
5
+ require './rake/required_audits'
6
+ desc "Make sure your environment is ready"
7
+ task :environment_ready => [
8
+ :you_need_the_right_ruby_version,
9
+ :you_need_our_dependency_manager,
10
+ :you_need_to_install_any_dependencies
11
+ ]
12
+
13
+ begin
14
+ require 'bundler'
15
+ Bundler::GemHelper.install_tasks
16
+ rescue NameError => e
17
+ puts "This problem should get sorted out once you've completed the above instructions:\n" + e.message
18
+ end
19
+
20
+ require 'rake/rdoctask'
21
+ Rake::RDocTask.new do |rdoc|
22
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
23
+
24
+ rdoc.rdoc_dir = 'rdoc'
25
+ rdoc.title = "CukeSalad #{version}"
26
+ rdoc.rdoc_files.include('README*')
27
+ rdoc.rdoc_files.include('lib/**/*.rb')
28
+ end
29
+
30
+ require './rake/testing_tasks/check_internals_with_rspec'
31
+ desc "Checks the environment and runs all tests"
32
+ task :default => [
33
+ :environment_ready,
34
+ :spec
35
+ ]
data/cucumber.yml ADDED
@@ -0,0 +1,6 @@
1
+ default: --tags ~@wip --tags ~@todo
2
+ wip: --tags @wip
3
+ todo: --tags @todo
4
+ all: features
5
+ autotest: --color
6
+ autotest-all: --color
@@ -0,0 +1,72 @@
1
+ module Versionary
2
+ class VersionNumber
3
+
4
+ include Comparable
5
+
6
+ attr_reader :major, :minor, :build
7
+
8
+ VERSION_PATTERN = /^\d+\.\d+\.\d+$/
9
+
10
+ def self.of version
11
+ self.new version
12
+ end
13
+
14
+ def initialize version
15
+ raise NotAVersionComplaint.about version if not a_recognised? version
16
+ number = infer_from version
17
+ @major = value_of :major, number
18
+ @minor = value_of :minor, number
19
+ @build = value_of :build, number
20
+ end
21
+
22
+ def <=> other_version
23
+ with_other_version = VersionNumber.of(other_version) if other_version.class == String
24
+ with_other_version = other_version if other_version.class == self.class
25
+
26
+ compare(self, with_other_version)
27
+ end
28
+
29
+ def to_s
30
+ "#{@major}.#{@minor}.#{@build}"
31
+ end
32
+
33
+ private
34
+ def a_recognised? version
35
+ version =~ VERSION_PATTERN
36
+ end
37
+
38
+ def infer_from version
39
+ version.split( '.' ).collect { |n| n.to_i }
40
+ end
41
+
42
+ def value_of position, from_numbers
43
+ positions = {:major => 0, :minor => 1, :build => 2}
44
+ from_numbers[positions[position]]
45
+ end
46
+
47
+ def compare first_version, second_version
48
+ differences = []
49
+ differences[0] = first_version.major <=> second_version.major
50
+ differences[1] = first_version.minor <=> second_version.minor
51
+ differences[2] = first_version.build <=> second_version.build
52
+ differences.each do |indication|
53
+ return indication if it_is_a_greater_than_or_less_than? indication
54
+ end
55
+ 0
56
+ end
57
+
58
+ def it_is_a_greater_than_or_less_than? indication
59
+ indication != 0
60
+ end
61
+ end
62
+
63
+ class NotAVersionComplaint < Exception
64
+ def self.about version
65
+ self.new version
66
+ end
67
+
68
+ def initialize version
69
+ super "#{version} is not a recognised version number"
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,16 @@
1
+ task :you_need_our_dependency_manager do
2
+ begin
3
+ require 'bundler'
4
+ puts "You have our preferred dependency manager. Cool!"
5
+ rescue LoadError => e
6
+ abort "\nOoops! You're not quite ready to start.\n" +
7
+ e.message + "\n\n" +
8
+ "We can fix this easily...\n" +
9
+ "\nAll you should need to do is run `gem install bundler`\n" +
10
+ "\nBefore you do that, we recommend that you use rvm and use a fresh gemset.\n" +
11
+ " rvm: http://beginrescueend.com/\n" +
12
+ " rvm gemsets: http://beginrescueend.com/gemsets/\n" +
13
+ " rvm creating gemsets: http://beginrescueend.com/gemsets/creating/\n" +
14
+ "\nOnce you've installed bundler into your nice new gemset, run `rake` again and we'll tell you what's next.\n\n"
15
+ end
16
+ end
@@ -0,0 +1,20 @@
1
+ $: << File.join(File.expand_path(File.dirname(__FILE__)), "..", "..", "lib")
2
+ require 'versionary/version_number'
3
+
4
+ task :you_need_the_right_ruby_version do
5
+ include Versionary
6
+
7
+ minimum_ruby_version = ENV[ 'MINIMUM_RUBY_VERSION' ]
8
+
9
+ with_guidance = "
10
+ Oops! You are using ruby #{RUBY_VERSION}. We really want you to use ruby #{minimum_ruby_version} or higher
11
+ Suggestion:
12
+ We like using rvm to manage our ruby versions.
13
+ That way, you can just say `rvm use #{minimum_ruby_version}` and hey presto, you're on version #{minimum_ruby_version}
14
+ rvm: http://beginrescueend.com/
15
+ Hey, it's up to you, but once you're on ruby #{minimum_ruby_version} let us know by running `rake` again.\n\n"
16
+
17
+ abort with_guidance if VersionNumber.of( RUBY_VERSION ) < minimum_ruby_version
18
+
19
+ puts "You're using ruby #{RUBY_VERSION}. We're happy about that."
20
+ end
@@ -0,0 +1,11 @@
1
+ task :you_need_to_install_any_dependencies do
2
+ begin
3
+ Bundler.setup(:default, :development)
4
+ puts "You have all the dependencies you need!!\n\n"
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts "Oops! So near, yet so far.\n\n"
7
+ $stderr.puts e.message + "\n\n"
8
+ $stderr.puts "Run `bundle install` and all the dependencies you need will be installed\n\n"
9
+ exit e.status_code
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ require './rake/audit_tasks/you_need_the_right_ruby_version'
2
+ require './rake/audit_tasks/you_need_our_dependency_manager'
3
+ require './rake/audit_tasks/you_need_to_install_any_dependencies'
@@ -0,0 +1,18 @@
1
+ begin
2
+ require 'cucumber/rake/task'
3
+
4
+ Cucumber::Rake::Task.new(:features)
5
+
6
+ additional_tasks = {
7
+ :features_wip => '-p wip',
8
+ :features_todo => '-p todo'
9
+ }
10
+
11
+ additional_tasks.each do | task_name, options |
12
+ Cucumber::Rake::Task.new(task_name) do |wip|
13
+ wip.cucumber_opts = options
14
+ end
15
+ end
16
+ rescue LoadError => e
17
+ #do_nothing - bundler will sort this out
18
+ end
@@ -0,0 +1,20 @@
1
+ begin
2
+ require 'rspec/core'
3
+ require 'rspec/core/rake_task'
4
+
5
+ file_pattern = 'spec/**/*_spec.rb'
6
+ tasks = {
7
+ :spec => "-cfd --tag ~wip --tag ~todo",
8
+ :spec_wip => "-cfd --tag @wip",
9
+ :spec_todo => "-cfd --tag @todo"
10
+ }
11
+
12
+ tasks.each do | task_name, options |
13
+ RSpec::Core::RakeTask.new(task_name) do |spec|
14
+ spec.pattern = FileList[file_pattern]
15
+ spec.rspec_opts = options
16
+ end
17
+ end
18
+ rescue LoadError => e
19
+ #do_nothing - bundler will sort this out
20
+ end
@@ -0,0 +1,100 @@
1
+ require 'versionary/version_number'
2
+ module Versionary
3
+ describe VersionNumber do
4
+ include Versionary
5
+
6
+ context "when the versions are the same" do
7
+ it "tells you they are equal" do
8
+ VersionNumber.of( RUBY_VERSION ).should == VersionNumber.of( RUBY_VERSION )
9
+ end
10
+
11
+ it "tells you that the first number is not less than second number" do
12
+ VersionNumber.of( RUBY_VERSION ).should_not < VersionNumber.of( RUBY_VERSION )
13
+ end
14
+
15
+ it "tells you that the first number is not greater than second number" do
16
+ VersionNumber.of( RUBY_VERSION ).should_not > VersionNumber.of( RUBY_VERSION )
17
+ end
18
+ end
19
+
20
+ [:major, :minor, :build].each do | position |
21
+ context "when the #{position} number is different" do
22
+ context "making the first version lower than the second version" do
23
+ let(:first_version) {'0.0.9'}
24
+ let(:second_version) { a_version :higher_than, first_version, position }
25
+
26
+ it "tells you that the first number is less than the second number" do
27
+ VersionNumber.of( first_version ).should < VersionNumber.of( second_version )
28
+ end
29
+
30
+ it "tells you that the first number is not greater than the second number" do
31
+ VersionNumber.of( first_version ).should_not > VersionNumber.of( second_version )
32
+ end
33
+
34
+ it "tells you that they're not equal" do
35
+ VersionNumber.of( first_version ).should_not == VersionNumber.of( second_version )
36
+ end
37
+ end
38
+
39
+ context "making the first version higher than the second version" do
40
+ let(:first_version) {'10.10.10'} # to ensure that digits are compared numerically, not alphabetically
41
+ let(:second_version) { a_version :lower_than, first_version, position }
42
+
43
+ it "tells you that the first number is greater than the second number" do
44
+ VersionNumber.of( first_version ).should > VersionNumber.of( second_version )
45
+ end
46
+
47
+ it "tells you that the first number is not less than the second number" do
48
+ VersionNumber.of( first_version ).should_not < VersionNumber.of( second_version )
49
+ end
50
+
51
+ it "tells you that they're not equal" do
52
+ VersionNumber.of( first_version ).should_not == VersionNumber.of( second_version )
53
+ end
54
+ end
55
+ end
56
+ end
57
+
58
+ context "when the latter number is a string" do
59
+ it "tells you when they're equal as version numbers" do
60
+ VersionNumber.of('1.9.2').should == '1.9.2'
61
+ end
62
+
63
+ it "tells you when the first version number is greater than a string representation" do
64
+ VersionNumber.of('1.9.10').should > '1.9.9'
65
+ end
66
+ it "tells you when the first version number is less than a string representation" do
67
+ VersionNumber.of('1.9.9').should < '1.9.10'
68
+ end
69
+
70
+ it "tells you when the number is not equal to the string representation" do
71
+ VersionNumber.of('1.9.9').should_not == '1.9.10'
72
+ end
73
+ end
74
+
75
+ context "when the version number provided is not understood, for example:" do
76
+ [ "1.9.a",
77
+ "v1.9.2",
78
+ "1.9.2a",
79
+ "not a version",
80
+ ".1.9.2",
81
+ "1.9.2.1"
82
+ ].each do | unrecognised_version |
83
+ it "can't understand '#{unrecognised_version}'" do
84
+ lambda {VersionNumber.of( unrecognised_version )}.should raise_error NotAVersionComplaint
85
+ end
86
+ end
87
+ end
88
+
89
+ def a_version higher_or_lower_than, version_number, major_minor_or_build
90
+ alterations = {:higher_than => :+, :lower_than => :-}
91
+ positions = {:major => 0, :minor => 1, :build => 2 }
92
+ altered_by = alterations[higher_or_lower_than]
93
+ position = positions[major_minor_or_build]
94
+
95
+ version_numbers = version_number.split( '.' ).collect {|n| n.to_i}
96
+ version_numbers[position] = version_numbers[position].send altered_by, 1
97
+ version_numbers.join '.'
98
+ end
99
+ end
100
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: versionary
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - RiverGlide
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-06-15 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: bundler
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 23
30
+ segments:
31
+ - 1
32
+ - 0
33
+ - 0
34
+ version: 1.0.0
35
+ type: :development
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: rake
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ hash: 49
46
+ segments:
47
+ - 0
48
+ - 8
49
+ - 7
50
+ version: 0.8.7
51
+ type: :development
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: rspec
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 27
62
+ segments:
63
+ - 2
64
+ - 5
65
+ - 0
66
+ version: 2.5.0
67
+ type: :development
68
+ version_requirements: *id003
69
+ description: "Versionary has a simple VersionNumber object that allows you to do things like `raise \"Not the right version\" unless VersionNumber.of( RUBY_VERSION ) >= '1.9.2'` "
70
+ email:
71
+ - talktous@riverglide.com
72
+ executables: []
73
+
74
+ extensions: []
75
+
76
+ extra_rdoc_files: []
77
+
78
+ files:
79
+ - .gitignore
80
+ - Gemfile
81
+ - Gemfile.lock
82
+ - README.md
83
+ - Rakefile
84
+ - cucumber.yml
85
+ - lib/versionary/version_number.rb
86
+ - rake/audit_tasks/you_need_our_dependency_manager.rb
87
+ - rake/audit_tasks/you_need_the_right_ruby_version.rb
88
+ - rake/audit_tasks/you_need_to_install_any_dependencies.rb
89
+ - rake/required_audits.rb
90
+ - rake/testing_tasks/check_features_with_cucumber.rb
91
+ - rake/testing_tasks/check_internals_with_rspec.rb
92
+ - spec/versionary/version_number_spec.rb
93
+ has_rdoc: true
94
+ homepage: https://github.com/RiverGlide/Versionary
95
+ licenses:
96
+ - MIT
97
+ post_install_message:
98
+ rdoc_options: []
99
+
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ hash: 3
108
+ segments:
109
+ - 0
110
+ version: "0"
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ none: false
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ hash: 3
117
+ segments:
118
+ - 0
119
+ version: "0"
120
+ requirements: []
121
+
122
+ rubyforge_project:
123
+ rubygems_version: 1.6.2
124
+ signing_key:
125
+ specification_version: 3
126
+ summary: Simple, comparable, rational Version Number object
127
+ test_files:
128
+ - spec/versionary/version_number_spec.rb