bump 0.3.1 → 0.3.2

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/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bump (0.2.0)
4
+ bump (0.3.2)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
data/bin/bump CHANGED
@@ -11,6 +11,7 @@ Bump your gem version.
11
11
 
12
12
  Usage:
13
13
  bump current # show current version
14
+ bump pre # increase prerelease version of your gem (1.0.0-X) [alpha, beta, rc, ]
14
15
  bump patch # increase patch version of your gem (1.0.X)
15
16
  bump minor # increase minor version of your gem (1.X.0)
16
17
  bump major # increase major version of your gem (X.0.0)
data/bump.gemspec CHANGED
@@ -1,5 +1,5 @@
1
1
  Gem::Specification.new "bump" do |s|
2
- s.version = "0.3.1"
2
+ s.version = "0.3.2"
3
3
  s.author = "Gregory Marcilhacy"
4
4
  s.email = "g.marcilhacy@gmail.com"
5
5
  s.homepage = "https://github.com/gregorym/bump"
data/lib/bump.rb CHANGED
@@ -5,13 +5,14 @@ module Bump
5
5
  class UnfoundVersionFileError < StandardError; end
6
6
 
7
7
  class Bump
8
- BUMPS = %w(major minor patch)
8
+ BUMPS = %w(major minor patch pre)
9
+ PRERELEASE = ["alpha","beta","rc",nil]
9
10
  OPTIONS = BUMPS | ["current"]
10
- VERSION_REGEX = /(\d+\.\d+\.\d+)/
11
+ VERSION_REGEX = /(\d+\.\d+\.\d+(?:-(?:#{PRERELEASE.compact.join('|')}))?)/
11
12
 
12
13
  def self.run(bump, options)
13
14
  case bump
14
- when "major", "minor", "patch"
15
+ when *BUMPS
15
16
  bump(bump, options)
16
17
  when "current"
17
18
  current
@@ -96,17 +97,23 @@ module Bump
96
97
  end
97
98
 
98
99
  def self.next_version(current, part)
99
- match = current.match /(\d+)\.(\d+)\.(\d+)/
100
+ current, prerelease = current.split('-')
101
+ major, minor, patch, *other = current.split('.')
100
102
  case part
101
103
  when "major"
102
- "#{match[1].to_i + 1}.0.0"
104
+ major, minor, patch, prerelease = major.succ, 0, 0, nil
103
105
  when "minor"
104
- "#{match[1]}.#{match[2].to_i + 1}.0"
106
+ minor, patch, prerelease = minor.succ, 0, nil
105
107
  when "patch"
106
- "#{match[1]}.#{match[2]}.#{match[3].to_i + 1}"
108
+ patch = patch.succ
109
+ when "pre"
110
+ prerelease.strip! if prerelease.respond_to? :strip
111
+ prerelease = PRERELEASE[PRERELEASE.index(prerelease).succ % PRERELEASE.length]
107
112
  else
108
113
  raise "unknown part #{part.inspect}"
109
114
  end
115
+ version = [major, minor, patch, *other].compact.join('.')
116
+ [version, prerelease].compact.join('-')
110
117
  end
111
118
  end
112
119
  end
data/spec/bump_spec.rb CHANGED
@@ -145,28 +145,87 @@ describe Bump do
145
145
  end
146
146
 
147
147
  context "version in VERSION" do
148
+ let(:version) { "1.2.3" }
149
+
148
150
  before do
149
- write "VERSION", "1.2.3\n"
151
+ write "VERSION", "#{version}\n"
150
152
  end
151
153
 
152
154
  it "show current" do
153
- bump("current").should include("1.2.3")
154
- read("VERSION").should == "1.2.3\n"
155
+ bump("current").should include("#{version}")
156
+ read("VERSION").should include("#{version}")
155
157
  end
156
158
 
157
159
  it "should bump version" do
158
160
  bump("minor").should include("1.3.0")
159
- read("VERSION").should == "1.3.0\n"
161
+ read("VERSION").should include("1.3.0")
160
162
  end
161
163
 
162
164
  it "should bump if a gemspec & version.rb exists and leave it alone" do
163
165
  write_gemspec "File.read('VERSION')"
164
166
  write_version_rb "File.read('VERSION')"
165
167
  bump("minor").should include("1.3.0")
166
- read("VERSION").should == "1.3.0\n"
168
+ read("VERSION").should include("1.3.0")
167
169
  read(version_rb_file).should include("VERSION = File.read('VERSION')")
168
170
  read(gemspec).should include("version = File.read('VERSION')")
169
171
  end
172
+
173
+ context "with pre-release identifier" do
174
+ let(:version) { "1.2.3-alpha" }
175
+ before do
176
+ write "VERSION", "#{version}\n"
177
+ end
178
+
179
+ it "show current" do
180
+ bump("current").should include(version)
181
+ read("VERSION").should include(version)
182
+ end
183
+
184
+ it "minor should drop prerelease" do
185
+ bump("minor").should include("1.3.0")
186
+ read("VERSION").should include("1.3.0")
187
+ bump("minor").should_not include("alpha")
188
+ read("VERSION").should_not include("alpha")
189
+ end
190
+
191
+ it "major should drop prerelease" do
192
+ bump("major").should include("2.0.0")
193
+ read("VERSION").should include("2.0.0")
194
+ bump("major").should_not include("alpha")
195
+ read("VERSION").should_not include("alpha")
196
+ end
197
+
198
+ context "alpha" do
199
+ it "should bump to beta" do
200
+ bump("pre").should include("1.2.3-beta")
201
+ read("VERSION").should include("1.2.3-beta")
202
+ end
203
+ end
204
+
205
+ context "beta" do
206
+ let(:version) { "1.2.3-beta" }
207
+ it "should bump to rc" do
208
+ bump("pre").should include("1.2.3-rc")
209
+ read("VERSION").should include("1.2.3-rc")
210
+ end
211
+ end
212
+
213
+ context "rc" do
214
+ let(:version) { "1.2.3-rc" }
215
+ it "should bump to final" do
216
+ bump("pre").should include("1.2.3")
217
+ read("VERSION").should include("1.2.3")
218
+ end
219
+ end
220
+
221
+ context "final" do
222
+ let(:version) { "1.2.3" }
223
+ it "should bump to alpha" do
224
+ bump("pre").should include("1.2.3-alpha")
225
+ read("VERSION").should include("1.2.3-alpha")
226
+ end
227
+ end
228
+ end
170
229
  end
171
230
 
172
231
  context "with a Gemfile" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bump
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: