bump 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.textile +23 -0
  2. data/bump.gemspec +1 -1
  3. data/lib/bump.rb +32 -22
  4. metadata +6 -6
data/README.textile CHANGED
@@ -0,0 +1,23 @@
1
+ h1. Installation
2
+
3
+ bc. gem install bump
4
+
5
+ h1. Usage
6
+
7
+ Current version of your gem file:
8
+
9
+ bc. bump current
10
+ Current version: 0.1.2
11
+
12
+ Bump your gemfile (major, minor, tiny):
13
+
14
+ bc. bump tiny
15
+ Bump version 0.1.2 to 0.1.3
16
+
17
+
18
+ h1. Todo
19
+
20
+ * Handle options properly
21
+ * I really need to write tests!
22
+ * Some code can be refactored
23
+
data/bump.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "bump"
3
- s.version = "0.1.0"
3
+ s.version = "0.1.2"
4
4
  s.author = "Gregory Marcilhacy"
5
5
  s.email = "g.marcilhacy@gmail.com"
6
6
  s.homepage = "http://github.com/gregorymp/bump"
data/lib/bump.rb CHANGED
@@ -3,45 +3,59 @@ module Bump
3
3
  class Bump
4
4
 
5
5
  BUMPS = %w(major minor tiny)
6
+ OPTIONS = BUMPS | ["current"]
6
7
  VERSION_REGEX = /version\s*=\s*["|'](\d.\d.\d)["|']/
7
8
 
8
- class InvalidBumpError < StandardError; end
9
+ class InvalidOptionError < StandardError; end
9
10
  class UnfoundVersionError < StandardError; end
10
11
  class TooManyGemspecsFoundError < StandardError; end
11
12
  class UnfoundGemspecError < StandardError; end
12
13
 
13
14
  def initialize(bump)
14
- begin
15
- bump = bump.is_a?(Array) ? bump.first : bump
16
- raise InvalidBumpError unless BUMPS.include?(bump)
17
- @bump = bump
18
-
19
- rescue InvalidBumpError
20
- display_message "Invalid bump. Choose between #{BUMPS.join(',')}."
21
- rescue Exception
22
- display_message "Something wrong happened"
23
- end
15
+ @bump = bump.is_a?(Array) ? bump.first : bump
24
16
  end
25
17
 
26
18
  def run
27
19
  begin
20
+ raise InvalidOptionError unless OPTIONS.include?(@bump)
21
+
28
22
  gemspec = find_gemspec_file
29
23
  current_version = find_current_version(gemspec)
30
- next_version = find_next_version(current_version)
31
- system(%(ruby -i -pe "gsub(/#{current_version}/, '#{next_version}')" #{gemspec}))
32
- display_message "Bump version #{current_version} to #{next_version}"
33
-
24
+
25
+ case @bump
26
+ when "major", "minor", "tiny"
27
+ bump(current_version, gemspec)
28
+ when "current"
29
+ current(current_version)
30
+ else
31
+ raise Exception
32
+ end
33
+
34
+ rescue InvalidOptionError
35
+ puts "Invalid option. Choose between #{OPTIONS.join(',')}."
34
36
  rescue UnfoundVersionError
35
- display_message "Unable to find your gem version"
37
+ puts "Unable to find your gem version"
36
38
  rescue UnfoundGemspecError
37
- display_message "Unable to find gemspec file"
39
+ puts "Unable to find gemspec file"
38
40
  rescue TooManyGemspecsFoundError
39
- display_message "More than one gemspec file"
41
+ puts "More than one gemspec file"
42
+ rescue Exception => e
43
+ puts "Something wrong happened: #{e.message}"
40
44
  end
41
45
  end
42
46
 
43
47
  private
44
48
 
49
+ def bump(current_version, gemspec)
50
+ next_version = find_next_version(current_version)
51
+ system(%(ruby -i -pe "gsub(/#{current_version}/, '#{next_version}')" #{gemspec}))
52
+ puts "Bump version #{current_version} to #{next_version}"
53
+ end
54
+
55
+ def current(current_version)
56
+ puts "Current version: #{current_version}"
57
+ end
58
+
45
59
  def find_current_version(file)
46
60
  match = File.read(file).match VERSION_REGEX
47
61
  if match.nil?
@@ -70,10 +84,6 @@ module Bump
70
84
  end
71
85
  end
72
86
 
73
- def display_message(message)
74
- print(message); puts;
75
- end
76
-
77
87
  end
78
88
 
79
89
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bump
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
5
- prerelease:
4
+ hash: 31
5
+ prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 2
10
+ version: 0.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Gregory Marcilhacy
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-07-12 00:00:00 +02:00
18
+ date: 2011-07-13 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -62,7 +62,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
62
62
  requirements: []
63
63
 
64
64
  rubyforge_project:
65
- rubygems_version: 1.4.1
65
+ rubygems_version: 1.3.7
66
66
  signing_key:
67
67
  specification_version: 3
68
68
  summary: Bump your gem version file