Permalink
Browse files

Add revision support.

  • Loading branch information...
1 parent ac3ed9c commit 8ae8209e9f7582b3792f7decc5c85d0200c49364 @meh committed Jun 23, 2011
Showing with 63 additions and 46 deletions.
  1. +6 −6 lib/versionub/type.rb
  2. +18 −14 lib/versionub/types/standard.rb
  3. +39 −26 test/versionomy_spec.rb
View
@@ -34,13 +34,13 @@ def initialize (type, text, data)
@data = data
end
- String.instance_methods.each {|meth|
- next if respond_to? meth
-
- define_method meth do |*args|
- String.instance_method(meth).bind(@text).call(*args)
+ def method_missing (id, *args, &block)
+ if @text.respond_to?(id)
+ @text.send id, *args, &block
+ else
+ super
end
- }
+ end
def <=> (value)
to_s <=> value
@@ -46,7 +46,10 @@
(part.as(:pre) | any.as(:pre))) |
((str('rc')) >>
- (part.as(:rc) | any.as(:rc))) |
+ (part.as(:release_candidate) | any.as(:release_candidate))) |
+
+ ((str('revision') | str('rev') | str('r')) >>
+ (part.as(:revision) | any.as(:revision))) |
((str('patch') | str('p')).maybe >>
(part.as(:patch) | any.as(:patch)))
@@ -78,7 +81,7 @@
}
end
- [:major, :minor, :tiny, [:patch, :p, :patchlevel]].each {|part|
+ [:major, :minor, [:tiny, :teeny], [:patch, :patchlevel, :p], [:revision, :rev, :r]].each {|part|
part = [part].flatten
name = part.shift
@@ -99,7 +102,7 @@ def bugfix
end
end; alias tiny2 bugfix
- [:patch, [:release_candidate, :rc], :pre, [:beta, :b, :beta_version], [:alpha, :a, :alpha_version], [:development, :d, :dev]].each {|part|
+ [:patch, :revision, [:release_candidate, :rc], :pre, [:beta, :b, :beta_version], [:alpha, :a, :alpha_version], [:development, :d, :dev]].each {|part|
part = [part].flatten
name = part.shift
@@ -122,6 +125,7 @@ def release_type
return :development if development?
return :pre if pre?
return :release_candidate if release_candidate?
+ return :revision if revision?
return :patch if patch?
return :final
end
@@ -135,19 +139,19 @@ def <=> (value)
end
}
- if patch?
- if value.patch?
- return patch <=> value.patch
- else
- return 1
+ [:patch, :revision].each {|name|
+ if send("#{name}?")
+ if value.send("#{name}?")
+ return send(name) <=> value.send(name)
+ else
+ return 1
+ end
+ elsif value.send("#{name}?")
+ return -1
end
- elsif value.patch?
- return -1
- end
+ }
- parts = [:release_candidate, :pre, :beta, :alpha, :development]
-
- parts.each_with_index {|name, index|
+ (parts = [:release_candidate, :pre, :beta, :alpha, :development]).each_with_index {|name, index|
if send("#{name}?")
if value.send("#{name}?")
return send(name) <=> value.send(name)
View
@@ -1,44 +1,57 @@
#! /usr/bin/env ruby
require 'rubygems'
require 'versionub'
-require 'versionomy'
-describe Versionub do
- describe '.parse' do
- it 'returns the same as Versionomy for 1.2.3a2' do
- a = Versionub.parse('1.2.3a2')
- b = Versionomy.parse('1.2.3a2')
+begin
+ require 'versionomy'
- a.major.should == b.major
- a.minor.should == b.minor
- a.tiny.should == b.tiny
- a.tiny2.should == b.tiny2
+ describe Versionub do
+ describe '.parse' do
+ it 'returns the same as Versionomy for 1.2.3a2' do
+ a = Versionub.parse('1.2.3a2')
+ b = Versionomy.parse('1.2.3a2')
- a.release_type.should == b.release_type
+ a.major.should == b.major
+ a.minor.should == b.minor
+ a.tiny.should == b.tiny
+ a.tiny2.should == b.tiny2
- a.alpha.should == b.alpha_version
- end
+ a.release_type.should == b.release_type
+
+ a.alpha.should == b.alpha_version
+ end
+
+ it 'returns 2008.2 for Versionub.parse("2008 SP2", :windows)' do
+ Versionub.parse('2008 SP2', :windows) == '2008.2'
+ end
- it 'returns 2008.2 for Versionub.parse("2008 SP2", :windows)' do
- Versionub.parse('2008 SP2', :windows) == '2008.2'
+ it 'parses 1.8.3-r4 correctly' do
+ a = Versionub.parse('1.8.3-r4')
+
+ a.major.should == 1
+ a.minor.should == 8
+ a.teeny.should == 3
+ a.revision.should == 4
+ end
end
- end
- describe '.create' do
- it 'returns the same as Versionomy for { :major => 1, :minor => 3, :tiny => 2 }' do
- a = Versionub.create(:major => 1, :minor => 3, :tiny => 2)
- b = Versionomy.create(:major => 1, :minor => 3, :tiny => 2)
+ describe '.create' do
+ it 'returns the same as Versionomy for { :major => 1, :minor => 3, :tiny => 2 }' do
+ a = Versionub.create(:major => 1, :minor => 3, :tiny => 2)
+ b = Versionomy.create(:major => 1, :minor => 3, :tiny => 2)
- a.major.should == b.major
- a.minor.should == b.minor
- a.tiny.should == b.tiny
- a.tiny2.should == b.tiny2
+ a.major.should == b.major
+ a.minor.should == b.minor
+ a.tiny.should == b.tiny
+ a.tiny2.should == b.tiny2
- a.release_type.should == b.release_type
+ a.release_type.should == b.release_type
- a.patchlevel.should == b.patchlevel
+ a.patchlevel.should == b.patchlevel
+ end
end
end
+rescue LoadError
end
describe Versionub::Type::Instance do

0 comments on commit 8ae8209

Please sign in to comment.