version_bumper 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -3,13 +3,23 @@ version_bumper
3
3
 
4
4
  Simple. Bump your versions.
5
5
 
6
+ What is it for?
7
+ ---------------
8
+ Given that we agree upon a [version format][1], maintain a version for your project. The version is kept in a file, in the root of your project, which is a common thing to do.
9
+ Especially useful for developers using rake as their build runner in non-ruby projects (don't you?).
10
+
11
+
12
+
13
+ Quick start
14
+ -----------
6
15
  $ gem install version_bumper
7
16
 
8
- In your Rakefile `require 'version_bumper'` and you're done.
17
+ First lets agree that version looks like this: major.minor.revision.build
18
+ In your `Rakefile` `require 'version_bumper'` and you're done. If you're in rails, `gem 'version_bumper'` to your `Gemfile` in addition.
9
19
 
10
20
  $ rake -T
11
21
  rake bump:build # bump build
12
- rake bump:init # write a blank version to VERSION
22
+ rake bump:init # write a blank version
13
23
  rake bump:major # bump major
14
24
  rake bump:minor # bump minor
15
25
  rake bump:revision # bump revision
@@ -36,9 +46,17 @@ Contributing to version_bumper
36
46
  * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
37
47
  * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
38
48
 
49
+ Commiters
50
+ ---------
51
+ jondot (Dotan Nahum)
52
+ splattael (Peter Suschlik)
53
+
39
54
  Copyright
40
55
  ---------
41
56
 
42
57
  Copyright (c) 2011 Dotan Nahum. See LICENSE.txt for
43
58
  further details.
44
59
 
60
+
61
+
62
+ [1]: http://semver.org
@@ -1,48 +1,45 @@
1
- module Bumper
2
- class Version
3
-
4
- ['major', 'minor', 'revision', 'build'].each do |part|
5
- define_method part do
6
- @v[part]
7
- end
8
- end
9
-
10
- def initialize(v)
11
- @v= {}
12
- if v =~ /^(\d+)\.(\d+)\.(\d+)(?:\.(.*?))?$/
13
- @v['major'] = $1.to_i
14
- @v['minor'] = $2.to_i
15
- @v['revision'] = $3.to_i
16
- @v['build'] = $4
17
- end
18
- end
19
-
20
- def bump(part)
21
- @v[part] = @v[part].succ
22
-
23
- return @v[part] if part == 'build'
24
- @v['build'] = '0'
25
- return @v[part] if part == 'revision'
26
- @v['revision'] = 0
27
- return @v[part] if part == 'minor'
28
- @v['minor'] = 0
29
- @v[part]
30
- end
31
-
32
- def method_missing(m, *args, &block)
33
- if(m.to_s =~ /^bump_(.*)$/)
34
- if @v.has_key? $1
35
- return send(:bump, $1)
36
- end
37
- end
38
- super
39
- end
40
-
41
- def to_s
42
- "#{major}.#{minor}.#{revision}" + (build.nil? ? "" : ".#{build}")
43
- end
44
- def write(f)
45
- File.open(f,'w'){ |h| h.write(self.to_s) }
46
- end
47
- end
1
+ module Bumper
2
+ class Version
3
+
4
+ [:major, :minor, :revision, :build].each do |part|
5
+ define_method part do
6
+ @v[part]
7
+ end
8
+
9
+ define_method "bump_#{part}" do
10
+ bump(part)
11
+ end
12
+ end
13
+
14
+ def initialize(v)
15
+ @v = {}
16
+ if v =~ /^(\d+)\.(\d+)\.(\d+)(?:\.(.*?))?$/
17
+ @v[:major] = $1.to_i
18
+ @v[:minor] = $2.to_i
19
+ @v[:revision] = $3.to_i
20
+ @v[:build] = $4
21
+ end
22
+ end
23
+
24
+ def bump(part)
25
+ version = @v[part] = @v[part].succ
26
+
27
+ return version if part == :build
28
+ @v[:build] = '0'
29
+ return version if part == :revision
30
+ @v[:revision] = 0
31
+ return version if part == :minor
32
+ @v[:minor] = 0
33
+
34
+ version
35
+ end
36
+
37
+ def to_s
38
+ [major, minor, revision, build].compact.join('.')
39
+ end
40
+
41
+ def write(f)
42
+ File.open(f,'w'){ |h| h.write(self.to_s) }
43
+ end
44
+ end
48
45
  end
@@ -5,6 +5,12 @@ class TestVersionBumper < MiniTest::Unit::TestCase
5
5
  v = Bumper::Version.new('0.0.0.0')
6
6
  assert_equal '0.0.0.0', v.to_s
7
7
  end
8
+
9
+ def test_version_without_build
10
+ v = Bumper::Version.new('0.0.0')
11
+ assert_nil v.build
12
+ assert_equal '0.0.0', v.to_s
13
+ end
8
14
 
9
15
  def test_that_it_should_have_correct_properties_test
10
16
  v = Bumper::Version.new('0.0.0.0')
@@ -20,7 +26,7 @@ class TestVersionBumper < MiniTest::Unit::TestCase
20
26
  assert_equal 1, v.bump_revision
21
27
  assert_equal 1, v.bump_minor
22
28
  assert_equal 1, v.bump_major
23
- assert_equal '1.0.0.0', v.to_s
29
+ assert_equal '1.0.0.0', v.to_s
24
30
  end
25
31
 
26
32
  def test_that_it_should_bump_versions_alt
@@ -29,7 +35,7 @@ class TestVersionBumper < MiniTest::Unit::TestCase
29
35
  assert_equal 1, v.bump_minor
30
36
  assert_equal 1, v.bump_revision
31
37
  assert_equal '1', v.bump_build
32
- assert_equal '1.1.1.1', v.to_s
38
+ assert_equal '1.1.1.1', v.to_s
33
39
  end
34
40
 
35
41
  def test_that_when_bumping_reset_smaller_versions
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: version_bumper
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
8
+ - 2
9
9
  - 0
10
- version: 0.1.0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Dotan Nahum
@@ -15,12 +15,13 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-05 00:00:00 +02:00
18
+ date: 2011-02-16 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  type: :development
23
23
  prerelease: false
24
+ name: minitest
24
25
  version_requirements: &id001 !ruby/object:Gem::Requirement
25
26
  none: false
26
27
  requirements:
@@ -30,11 +31,11 @@ dependencies:
30
31
  segments:
31
32
  - 0
32
33
  version: "0"
33
- name: minitest
34
34
  requirement: *id001
35
35
  - !ruby/object:Gem::Dependency
36
36
  type: :development
37
37
  prerelease: false
38
+ name: bundler
38
39
  version_requirements: &id002 !ruby/object:Gem::Requirement
39
40
  none: false
40
41
  requirements:
@@ -46,11 +47,11 @@ dependencies:
46
47
  - 0
47
48
  - 0
48
49
  version: 1.0.0
49
- name: bundler
50
50
  requirement: *id002
51
51
  - !ruby/object:Gem::Dependency
52
52
  type: :development
53
53
  prerelease: false
54
+ name: jeweler
54
55
  version_requirements: &id003 !ruby/object:Gem::Requirement
55
56
  none: false
56
57
  requirements:
@@ -62,11 +63,11 @@ dependencies:
62
63
  - 5
63
64
  - 2
64
65
  version: 1.5.2
65
- name: jeweler
66
66
  requirement: *id003
67
67
  - !ruby/object:Gem::Dependency
68
68
  type: :development
69
69
  prerelease: false
70
+ name: rcov
70
71
  version_requirements: &id004 !ruby/object:Gem::Requirement
71
72
  none: false
72
73
  requirements:
@@ -76,7 +77,6 @@ dependencies:
76
77
  segments:
77
78
  - 0
78
79
  version: "0"
79
- name: rcov
80
80
  requirement: *id004
81
81
  description: Simply bump your versions
82
82
  email: jondotan@gmail.com