bump 0.1.5 → 0.2.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.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bump (0.1.4)
4
+ bump (0.1.5)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -4,17 +4,16 @@ bc. gem install bump
4
4
 
5
5
  h1. Usage
6
6
 
7
- Current version of your gem file:
7
+ Current version of your gem:
8
8
 
9
9
  bc. bump current
10
10
  Current version: 0.1.2
11
11
 
12
- Bump your gemfile (major, minor, tiny):
12
+ Bump your gemfile (major, minor, patch):
13
13
 
14
- bc. bump tiny
14
+ bc. bump patch
15
15
  Bump version 0.1.2 to 0.1.3
16
16
 
17
-
18
17
  h1. Todo
19
18
 
20
19
  * Handle options properly
@@ -1,5 +1,5 @@
1
1
  Gem::Specification.new "bump" do |s|
2
- s.version = "0.1.5"
2
+ s.version = "0.2.0"
3
3
  s.author = "Gregory Marcilhacy"
4
4
  s.email = "g.marcilhacy@gmail.com"
5
5
  s.homepage = "https://github.com/gregorym/bump"
@@ -1,28 +1,24 @@
1
1
  module Bump
2
-
3
2
  class InvalidOptionError < StandardError; end
4
3
  class UnfoundVersionError < StandardError; end
5
- class TooManyGemspecsFoundError < StandardError; end
6
- class UnfoundGemspecError < StandardError; end
4
+ class TooManyVersionFilesError < StandardError; end
5
+ class UnfoundVersionFileError < StandardError; end
7
6
 
8
7
  class Bump
8
+ attr_accessor :bump
9
9
 
10
- attr_accessor :bump, :gemspec_path, :version, :next_version
11
-
12
- BUMPS = %w(major minor tiny)
10
+ BUMPS = %w(major minor patch)
13
11
  OPTIONS = BUMPS | ["current"]
14
- VERSION_REGEX = /\.version\s*=\s*["'](\d+\.\d+\.\d+)["']/
12
+ VERSION_REGEX = /(\d+\.\d+\.\d+)/
15
13
 
16
14
  def initialize(bump)
17
15
  @bump = bump.is_a?(Array) ? bump.first : bump
18
16
  end
19
17
 
20
18
  def run
21
- @version = find_current_version
22
-
23
19
  case @bump
24
- when "major", "minor", "tiny"
25
- bump
20
+ when "major", "minor", "patch"
21
+ bump(@bump)
26
22
  when "current"
27
23
  current
28
24
  else
@@ -32,55 +28,76 @@ module Bump
32
28
  ["Invalid option. Choose between #{OPTIONS.join(',')}.", 1]
33
29
  rescue UnfoundVersionError
34
30
  ["Unable to find your gem version", 1]
35
- rescue UnfoundGemspecError
31
+ rescue UnfoundVersionFileError
36
32
  ["Unable to find gemspec file", 1]
37
- rescue TooManyGemspecsFoundError
33
+ rescue TooManyVersionFilesError
38
34
  ["More than one gemspec file", 1]
39
35
  rescue Exception => e
40
- ["Something wrong happened: #{e.message}", 1]
36
+ ["Something wrong happened: #{e.message}\n#{e.backtrace.join("\n")}", 1]
41
37
  end
42
38
 
43
39
  private
44
40
 
45
- def bump
46
- @next_version = find_next_version
47
- system(%(ruby -i -pe "gsub(/#{@version}/, '#{@next_version}')" #{gemspec_path}))
48
- ["Bump version #{@version} to #{@next_version}", 0]
41
+ def bump(part)
42
+ current, file = current_version
43
+ next_version = next_version(current, part)
44
+ replace(file, current, next_version)
45
+ ["Bump version #{current} to #{next_version}", 0]
46
+ end
47
+
48
+ def replace(file, old, new)
49
+ content = File.read(file)
50
+ File.open(file, "w"){|f| f.write(content.gsub(old, new)) }
49
51
  end
50
52
 
51
53
  def current
52
- ["Current version: #{@version}", 0]
54
+ ["Current version: #{current_version.first}", 0]
53
55
  end
54
56
 
55
- def find_current_version
56
- match = File.read(gemspec_path).match VERSION_REGEX
57
- if match.nil?
58
- raise UnfoundVersionError
59
- else
60
- match[1]
61
- end
57
+ def current_version
58
+ version, file = version_from_version_rb || version_from_gemspec || raise(UnfoundVersionFileError)
59
+ raise UnfoundVersionError unless version
60
+ [version, file]
62
61
  end
63
62
 
64
- def gemspec_path
65
- @gemspec_path ||= begin
66
- gemspecs = Dir.glob("*.gemspec")
67
- raise UnfoundGemspecError if gemspecs.size.zero?
68
- raise TooManyGemspecsFoundError if gemspecs.size > 1
69
- gemspecs.first
63
+ def version_from_version_rb
64
+ return unless file = find_version_file("*/**/version.rb")
65
+ [
66
+ File.read(file)[VERSION_REGEX],
67
+ file
68
+ ]
69
+ end
70
+
71
+ def version_from_gemspec
72
+ return unless file = find_version_file("*.gemspec")
73
+ [
74
+ File.read(file)[/\.version\s*=\s*["']#{VERSION_REGEX}["']/, 1],
75
+ file
76
+ ]
77
+ end
78
+
79
+ def find_version_file(pattern)
80
+ files = Dir.glob(pattern)
81
+ case files.size
82
+ when 0 then nil
83
+ when 1 then files.first
84
+ else
85
+ raise TooManyVersionFilesError
70
86
  end
71
87
  end
72
88
 
73
- def find_next_version
74
- match = @version.match /(\d+)\.(\d+)\.(\d+)/
75
- case @bump
89
+ def next_version(current, part)
90
+ match = current.match /(\d+)\.(\d+)\.(\d+)/
91
+ case part
76
92
  when "major"
77
93
  "#{match[1].to_i + 1}.0.0"
78
94
  when "minor"
79
95
  "#{match[1]}.#{match[2].to_i + 1}.0"
80
- when "tiny"
96
+ when "patch"
81
97
  "#{match[1]}.#{match[2]}.#{match[3].to_i + 1}"
98
+ else
99
+ raise "unknown part #{part.inspect}"
82
100
  end
83
101
  end
84
-
85
102
  end
86
103
  end
@@ -23,15 +23,15 @@ describe Bump do
23
23
  it "should fail with multiple gemspecs" do
24
24
  write_gemspec
25
25
  write("xxxx.gemspec", "xxx")
26
- bump("", :fail => true).should include "More than one gemspec file"
26
+ bump("current", :fail => true).should include "More than one gemspec file"
27
27
  end
28
28
 
29
29
  it "should fail if version is weird" do
30
- write_gemspec("a.b.c")
31
- bump("", :fail => true).should include "Unable to find your gem version"
30
+ write_gemspec('"a.b.c"')
31
+ bump("current", :fail => true).should include "Unable to find your gem version"
32
32
  end
33
33
 
34
- context ".version in gemspect" do
34
+ context ".version in gemspec" do
35
35
  before do
36
36
  write_gemspec
37
37
  end
@@ -41,8 +41,8 @@ describe Bump do
41
41
  read(gemspec).should include('s.version = "4.2.3"')
42
42
  end
43
43
 
44
- it "should bump tiny" do
45
- bump("tiny").should include("4.2.4")
44
+ it "should bump patch" do
45
+ bump("patch").should include("4.2.4")
46
46
  read(gemspec).should include('s.version = "4.2.4"')
47
47
  end
48
48
 
@@ -57,18 +57,55 @@ describe Bump do
57
57
  end
58
58
 
59
59
  it "should bump more then 10" do
60
- bump("tiny").should include("4.2.4")
61
- bump("tiny").should include("4.2.5")
62
- bump("tiny").should include("4.2.6")
63
- bump("tiny").should include("4.2.7")
64
- bump("tiny").should include("4.2.8")
65
- bump("tiny").should include("4.2.9")
66
- bump("tiny").should include("4.2.10")
67
- bump("tiny").should include("4.2.11")
60
+ bump("patch").should include("4.2.4")
61
+ bump("patch").should include("4.2.5")
62
+ bump("patch").should include("4.2.6")
63
+ bump("patch").should include("4.2.7")
64
+ bump("patch").should include("4.2.8")
65
+ bump("patch").should include("4.2.9")
66
+ bump("patch").should include("4.2.10")
67
+ bump("patch").should include("4.2.11")
68
68
  read(gemspec).should include('s.version = "4.2.11"')
69
69
  end
70
70
  end
71
71
 
72
+ context "VERSION in version.rb" do
73
+ before do
74
+ write "lib/foo/version.rb", <<-RUBY.sub(" "*8, "")
75
+ module Foo
76
+ VERSION = "1.2.3"
77
+ end
78
+ RUBY
79
+ end
80
+
81
+ it "show current" do
82
+ bump("current").should include("1.2.3")
83
+ read("lib/foo/version.rb").should include(' VERSION = "1.2.3"')
84
+ end
85
+
86
+ it "should bump VERSION" do
87
+ bump("minor").should include("1.3.0")
88
+ read("lib/foo/version.rb").should include(' VERSION = "1.3.0"')
89
+ end
90
+
91
+ it "should bump Version" do
92
+ write "lib/foo/version.rb", <<-RUBY.sub(" "*8, "")
93
+ module Foo
94
+ Version = "1.2.3"
95
+ end
96
+ RUBY
97
+ bump("minor").should include("1.3.0")
98
+ read("lib/foo/version.rb").should include(' Version = "1.3.0"')
99
+ end
100
+
101
+ it "should bump if a gemspec exists and leave it alone" do
102
+ write_gemspec "Foo::VERSION"
103
+ bump("minor").should include("1.3.0")
104
+ read("lib/foo/version.rb").should include(' VERSION = "1.3.0"')
105
+ read(gemspec).should include('version = Foo::VERSION')
106
+ end
107
+ end
108
+
72
109
  private
73
110
 
74
111
  def write(file, content)
@@ -91,10 +128,10 @@ describe Bump do
91
128
  run "#{File.expand_path("../../bin/bump", __FILE__)} #{command}", options
92
129
  end
93
130
 
94
- def write_gemspec(version = "4.2.3")
131
+ def write_gemspec(version = '"4.2.3"')
95
132
  write gemspec, <<-RUBY.sub(" "*6, "")
96
133
  Gem::Specification.new do |s|
97
- s.version = "#{version}"
134
+ s.version = #{version}
98
135
  end
99
136
  RUBY
100
137
  end
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.1.5
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -27,7 +27,6 @@ files:
27
27
  - bump.gemspec
28
28
  - lib/bump.rb
29
29
  - spec/bump_spec.rb
30
- - spec/fixture/fixture.gemspec
31
30
  homepage: https://github.com/gregorym/bump
32
31
  licenses:
33
32
  - MIT
File without changes