version 0.10.0 → 1.0.0a

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,8 +1,7 @@
1
1
  = Version
2
2
 
3
3
  * http://github.com/stouset/version
4
- * http://rdoc.info/projects/stouset/version
5
- * http://getcaliper.com/caliper/project?repo=git%3A%2F%2Fgithub.com%2Fstouset%2Fversion.git
4
+ * http://rdoc.info/gems/version/
6
5
  * http://atlruby.org/stouset/posts/138-version-task
7
6
 
8
7
  == Description
@@ -38,11 +37,11 @@ You're all set up.
38
37
  $ rake version:bump # => 0.1.1
39
38
  $ rake version:bump:minor # => 0.2.0
40
39
  $ rake version:bump:revision # => 0.2.1
41
- $ rake version:bump:pre # => 0.2.1a
40
+ $ rake version:bump:pre # => 0.2.2a
42
41
  $ rake version:bump # => 0.2.2
43
42
  $ rake version:bump:major # => 1.0.0
44
- $ rake version:bump:minor # => 1.0.1
45
- $ cat VERSION # => 1.0.1
43
+ $ rake version:bump:minor # => 1.1.0
44
+ $ cat VERSION # => 1.1.0
46
45
 
47
46
  The VersionTask can automatically manage git tagging for
48
47
  you, too.
@@ -93,12 +92,12 @@ library. It's simple to use, but I'll be surprised if there's much point
93
92
  beyond doing the legwork for the Rake task and class versioning.
94
93
 
95
94
  v = "1.2.0".to_version
96
- v.to_s # => 1.2.0
97
- v.bump! # => 1.2.1
98
- v.bump!(:major) # => 1.3.0
99
- v.bump!(:minor, true) # => 1.3
100
- v.major = 2 # => 2.0
101
- v.to_a # => ['2', '0']
95
+ v.to_s # => 1.2.0
96
+ v.bump! # => 1.2.1
97
+ v.bump!(:major) # => 2.0.0
98
+ v.bump!(:minor, false, true) # => 2.1
99
+ v.major = 3 # => 3.0
100
+ v.to_a # => ['3', '0']
102
101
 
103
102
  == Install
104
103
 
data/Rakefile CHANGED
@@ -9,7 +9,7 @@ require 'spec/rake/spectask'
9
9
 
10
10
  spec = Gem::Specification.new do |s|
11
11
  s.name = 'version'
12
- s.version = Version.current
12
+ s.version = Version.current or '0.0.0'
13
13
  s.summary = 'simple version-number encapsulation'
14
14
 
15
15
  s.author = 'Stephen Touset'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.10.0
1
+ 1.0.0a
@@ -59,7 +59,7 @@ class Rake::VersionTask < Rake::TaskLib
59
59
 
60
60
  file filename
61
61
 
62
- desc 'Print the current version number'
62
+ desc "Print the current version number (#{read})"
63
63
  task(:version => filename) { puts read }
64
64
 
65
65
  namespace :version do
@@ -69,21 +69,32 @@ class Rake::VersionTask < Rake::TaskLib
69
69
  puts write(version)
70
70
  end
71
71
 
72
- desc 'Bump the least-significant version number'
72
+ desc "Bump to #{read.bump!}"
73
73
  task(:bump => filename) { puts write(read.bump!) }
74
74
 
75
75
  namespace :bump do
76
- desc 'Bump the major version number'
76
+ desc "Bump to #{read.bump!(:major)}"
77
77
  task(:major => filename) { puts write(read.bump!(:major)) }
78
78
 
79
- desc 'Bump the minor version number'
79
+ desc "Bump to #{read.bump!(:minor)}"
80
80
  task(:minor => filename) { puts write(read.bump!(:minor)) }
81
81
 
82
- desc 'Bump the revision number'
82
+ desc "Bump to #{read.bump!(:revision)}"
83
83
  task(:revision => filename) { puts write(read.bump!(:revision)) }
84
84
 
85
- desc 'Bump to a prerelease version'
85
+ desc "Bump to #{read.bump!(:pre)}"
86
86
  task(:pre => filename) { puts write(read.bump!(:pre)) }
87
+
88
+ namespace :pre do
89
+ desc "Bump to #{read.bump!(:major, true)}"
90
+ task(:major => filename) { puts write(read.bump!(:major, true)) }
91
+
92
+ desc "Bump to #{read.bump!(:minor, true)}"
93
+ task(:minor => filename) { puts write(read.bump!(:minor, true)) }
94
+
95
+ desc "Bump to #{read.bump!(:revision, true)}"
96
+ task(:revision => filename) { puts write(read.bump!(:revision, true)) }
97
+ end
87
98
  end
88
99
  end
89
100
  end
@@ -94,7 +105,7 @@ class Rake::VersionTask < Rake::TaskLib
94
105
  # Returns the Version contained in the file at +filename+.
95
106
  #
96
107
  def read
97
- contents = path.read
108
+ contents = path.read rescue '0.0.0'
98
109
 
99
110
  case filetype.to_s
100
111
  when '' then contents.chomp.to_version
@@ -106,6 +117,8 @@ class Rake::VersionTask < Rake::TaskLib
106
117
  # Writes out +version+ to the file at +filename+ with the correct format.
107
118
  #
108
119
  def write(version)
120
+ return if version == read
121
+
109
122
  path.open('w') do |io|
110
123
  io << case filetype.to_s
111
124
  when '' then version.to_s + "\n"
@@ -63,15 +63,8 @@ class Version
63
63
  #++
64
64
  #
65
65
  [ :major, :minor, :revision ].to_enum.each.with_index do |component, i|
66
- define_method(:"#{component}") { self[i] }
67
- define_method(:"#{component}=") {|v| self[i] = v }
68
- end
69
-
70
- #
71
- # Retrieves the component of the Version at +index+.
72
- #
73
- def [](index)
74
- self.components[index] ? self.components[index].to_s : nil
66
+ define_method(:"#{component}") { self.components[i] ? self.components[i].to_s : nil }
67
+ define_method(:"#{component}=") {|v| self[i] = v }
75
68
  end
76
69
 
77
70
  #
@@ -112,28 +105,38 @@ class Version
112
105
  end
113
106
 
114
107
  #
115
- # Bumps the version number. Pass +index+ to bump a component other than the
116
- # least-significant part. Set +trim+ to true if you want the version to be
117
- # resized to only large enough to contain the index.
108
+ # Bumps the version number. Pass +component+ to bump a component other than
109
+ # the least-significant part. Set +pre+ to true if you want to bump the
110
+ # component to a prerelease version. Set +trim+ to true if you want the
111
+ # version to be resized to only large enough to contain the component set.
118
112
  #
119
- # "1.0.4a".bump! # => '1.0.5'
120
- # "1.0.4a".bump!(:pre) # => '1.0.5b'
121
- # "1.0.4a".bump!(:minor, true) # => '1.2'
113
+ # "1.0.4a".bump! # => '1.0.4'
114
+ # "1.0.4a".bump!(:pre) # => '1.0.4b'
115
+ # "1.0.4a".bump!(:minor, false, true) # => '1.1'
116
+ # "1.0.4a".bump!(:minor, true, true) # => '1.1a
117
+ # "1.0.4a".bump!(:minor, true, false) # => '1.1.0a'
122
118
  #
123
- def bump!(index = self.length - 1, trim = false)
124
- case index
125
- when :major then self.bump!(0, trim)
126
- when :minor then self.bump!(1, trim)
127
- when :revision then self.bump!(2, trim)
128
- when :pre then self[-1] = self.components[-1].next(true)
119
+ def bump!(component = -1, pre = false, trim = false)
120
+ case component
121
+ when :major then self.bump!(0, pre, trim)
122
+ when :minor then self.bump!(1, pre, trim)
123
+ when :revision then self.bump!(2, pre, trim)
124
+ when :pre then self.bump!(-1, true, trim)
129
125
  else
130
- self.resize!(index + 1) if (trim or index >= self.length)
131
- self[index] = (self.components[index] || Component.new('0')).next
126
+ # resize to match the new length, if applicable
127
+ self.resize!(component + 1) if (trim or component >= self.length)
128
+
129
+ # mark all but the changed bit as non-prerelease
130
+ self[0...component].each(&:unprerelease!)
131
+
132
+ # I don't even understand this part any more; god help you
133
+ self[component] = self[component].next if pre and self.prerelease? and component == self.length - 1
134
+ self[component] = self[component].next unless pre and self.prerelease? and component == -1
135
+ self[-1] = self[-1].next(true) if pre
136
+ self
132
137
  end
133
-
134
- self
135
138
  end
136
-
139
+
137
140
  #
138
141
  # Returns the current length of the version number.
139
142
  #
@@ -197,6 +200,13 @@ class Version
197
200
 
198
201
  protected
199
202
 
203
+ #
204
+ # Retrieves the component of the Version at +index+.
205
+ #
206
+ def [](index)
207
+ self.components[index] || Component.new('0')
208
+ end
209
+
200
210
  def components
201
211
  @components ||= []
202
212
  end
@@ -24,6 +24,10 @@ class Version::Component
24
24
  not self.letter.empty?
25
25
  end
26
26
 
27
+ def unprerelease!
28
+ self.next! if self.prerelease?
29
+ end
30
+
27
31
  def next(pre = false)
28
32
  self.dup.next!(pre)
29
33
  end
@@ -31,7 +35,7 @@ class Version::Component
31
35
  def next!(pre = false)
32
36
  case
33
37
  when ( pre and self.prerelease?) then self.letter.next!
34
- when ( pre and not self.prerelease?) then self.letter = 'a'; self.digits = self.digits.next
38
+ when ( pre and not self.prerelease?) then self.letter = 'a'
35
39
  when (not pre and self.prerelease?) then self.letter = ''
36
40
  when (not pre and not self.prerelease?) then self.digits = self.digits.next
37
41
  end
@@ -20,6 +20,10 @@ describe Version do
20
20
  its(:revision) { should be_nil }
21
21
  its(:prerelease?) { should be_false }
22
22
 
23
+ it 'should bump to 2.10' do
24
+ subject.bump!.should == v2_10
25
+ end
26
+
23
27
  it 'should major-bump to 3.0' do
24
28
  subject.bump!(:major).should == v3_0
25
29
  end
@@ -35,9 +39,65 @@ describe Version do
35
39
  it 'should prerelease-bump to 2.10a' do
36
40
  subject.bump!(:pre).should == v2_10a
37
41
  end
42
+
43
+ it 'should prerelease-bump major to 3_0a' do
44
+ subject.bump!(:major, true).should == v3_0a
45
+ end
46
+
47
+ it 'should prerelease-bump minor to 2.10a' do
48
+ subject.bump!(:minor, true).should == v2_10a
49
+ end
50
+
51
+ it 'should prerelease-bump revision to 2.9.1a' do
52
+ subject.bump!(:revision, true).should == v2_9_1a
53
+ end
54
+ end
55
+
56
+ describe Version do
57
+ include ImplicitVersion
58
+
59
+ subject { v0_10_0 }
60
+
61
+ its(:major) { should == '0' }
62
+ its(:minor) { should == '10' }
63
+ its(:revision) { should == '0' }
64
+ its(:prerelease?) { should be_false }
65
+
66
+ it 'should bump to 0.10.1' do
67
+ subject.bump!.should == v0_10_1
68
+ end
69
+
70
+ it 'should major-bump to 1.0.0' do
71
+ subject.bump!(:major).should == v1_0_0
72
+ end
73
+
74
+ it 'should minor-bump to 0.11.0' do
75
+ subject.bump!(:minor).should == v0_11_0
76
+ end
77
+
78
+ it 'should revision-bump to 0.10.1' do
79
+ subject.bump!(:revision).should == v0_10_1
80
+ end
81
+
82
+ it 'should prerelease-bump to 0.10.1a' do
83
+ subject.bump!(:pre).should == v0_10_1a
84
+ end
85
+
86
+ it 'should prerelease-bump major to 1.0.0a' do
87
+ subject.bump!(:major, true).should == v1_0_0a
88
+ end
89
+
90
+ it 'should prerelease-bump minor to 0.11.0a' do
91
+ subject.bump!(:minor, true).should == v0_11_0a
92
+ end
93
+
94
+ it 'should prerelease-bump revision to 0.10.1a' do
95
+ subject.bump!(:revision, true).should == v0_10_1a
96
+ end
38
97
  end
39
98
 
40
- describe Version, 'with a prerelease version' do
99
+
100
+ describe Version, 'with a prerelease revision' do
41
101
  include ImplicitVersion
42
102
 
43
103
  subject { v1_6_3a }
@@ -47,15 +107,8 @@ describe Version, 'with a prerelease version' do
47
107
  its(:revision) { should == '3a' }
48
108
  its(:prerelease?) { should be_true }
49
109
 
50
- it 'should allow indexed access to components' do
51
- subject[0].should == '1'
52
- subject[1].should == '6'
53
- subject[2].should == '3a'
54
- end
55
-
56
- it 'should return nil for unset components' do
57
- subject[3].should == nil
58
- subject[4].should == nil
110
+ it 'should bump to 1.6.3' do
111
+ subject.bump!.should == v1_6_3
59
112
  end
60
113
 
61
114
  it 'should major-bump to 2.0.0' do
@@ -73,6 +126,61 @@ describe Version, 'with a prerelease version' do
73
126
  it 'should prerelease-bump to 1.6.3b' do
74
127
  subject.bump!(:pre).should == v1_6_3b
75
128
  end
129
+
130
+ it 'should prerelease-bump major to 2.0.0a' do
131
+ subject.bump!(:major, true).should == v2_0_0a
132
+ end
133
+
134
+ it 'should prerelease-bump minor to 1.7.0a' do
135
+ subject.bump!(:minor, true).should == v1_7_0a
136
+ end
137
+
138
+ it 'should prerelease-bump revision to 1.6.4a' do
139
+ subject.bump!(:revision, true).should == v1_6_4a
140
+ end
141
+ end
142
+
143
+ describe Version, 'with a prerelease minor version' do
144
+ include ImplicitVersion
145
+
146
+ subject { v1_6a }
147
+
148
+ its(:major) { should == '1' }
149
+ its(:minor) { should == '6a' }
150
+ its(:revision) { should == nil }
151
+ its(:prerelease?) { should be_true }
152
+
153
+ it 'should bump to 1.6' do
154
+ subject.bump!.should == v1_6
155
+ end
156
+
157
+ it 'should major-bump to 2.0' do
158
+ subject.bump!(:major).should == v2_0
159
+ end
160
+
161
+ it 'should minor-bump to 1.6' do
162
+ subject.bump!(:minor).should == v1_6
163
+ end
164
+
165
+ it 'should revision-bump to 1.6.1' do
166
+ subject.bump!(:revision).should == v1_6_1
167
+ end
168
+
169
+ it 'should bump to 1.6b' do
170
+ subject.bump!(:pre).should == v1_6b
171
+ end
172
+
173
+ it 'should prerelease-bump major to 2.0a' do
174
+ subject.bump!(:major, true).should == v2_0a
175
+ end
176
+
177
+ it 'should prerelease-bump minor to 1.7a' do
178
+ subject.bump!(:minor, true).should == v1_7a
179
+ end
180
+
181
+ it 'should prerelease-bump revision to 1.6.1a' do
182
+ subject.bump!(:revision, true).should == v1_6_1a
183
+ end
76
184
  end
77
185
 
78
186
  describe Version do
metadata CHANGED
@@ -1,8 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: version
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.10.0
4
+ prerelease: 5
5
+ version: 1.0.0a
6
6
  platform: ruby
7
7
  authors:
8
8
  - Stephen Touset
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-04-29 00:00:00 -04:00
13
+ date: 2011-05-02 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -70,9 +70,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
70
70
  required_rubygems_version: !ruby/object:Gem::Requirement
71
71
  none: false
72
72
  requirements:
73
- - - ">="
73
+ - - ">"
74
74
  - !ruby/object:Gem::Version
75
- version: "0"
75
+ version: 1.3.1
76
76
  requirements: []
77
77
 
78
78
  rubyforge_project: