version_info 1.0.0 → 1.1.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.
- data/Gemfile.lock +4 -1
- data/README.md +73 -14
- data/lib/version_info/data.rb +21 -14
- data/lib/version_info/rake_tasks.rb +1 -0
- data/lib/version_info/version_info.yml +1 -1
- data/lib/version_info.rb +7 -3
- data/spec/version_info/version_info_spec.rb +39 -2
- data/version_info.gemspec +2 -0
- metadata +28 -20
data/Gemfile.lock
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
version_info (0.
|
4
|
+
version_info (1.0.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: http://rubygems.org/
|
8
8
|
specs:
|
9
9
|
diff-lcs (1.1.2)
|
10
10
|
notifier (0.1.1)
|
11
|
+
rake (0.9.2)
|
11
12
|
rspec (2.3.0)
|
12
13
|
rspec-core (~> 2.3.0)
|
13
14
|
rspec-expectations (~> 2.3.0)
|
@@ -23,6 +24,8 @@ PLATFORMS
|
|
23
24
|
ruby
|
24
25
|
|
25
26
|
DEPENDENCIES
|
27
|
+
bundler
|
28
|
+
rake
|
26
29
|
rspec
|
27
30
|
test_notifier
|
28
31
|
version_info!
|
data/README.md
CHANGED
@@ -2,12 +2,22 @@
|
|
2
2
|
|
3
3
|
### Overview
|
4
4
|
|
5
|
-
|
5
|
+
VersionInfo is a powerful and very lightweight gem to manage version data in your Ruby projects or gems. Very user friendly thanks to rake / thor tasks
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
#### Features
|
8
|
+
|
9
|
+
* rake & thor tasks avaiables to yaml file creation, bump segments and show info
|
10
|
+
|
11
|
+
* can define custom segments to build your version tag with the tipical structure X.X.X.X.
|
12
|
+
|
13
|
+
* can use a custom tag format: do you want a tag like "1-3-1pre"?. No problem!.
|
14
|
+
|
15
|
+
* can include any custom info in your version data.
|
16
|
+
|
17
|
+
* Version data is stored in a yaml file.
|
18
|
+
|
19
|
+
* good rspec tests
|
9
20
|
|
10
|
-
Also rake & thor tasks are avaiable to simplify yaml file creation and update.
|
11
21
|
|
12
22
|
Feel free to contact me about bugs/features
|
13
23
|
|
@@ -21,9 +31,11 @@ Include VersionInfo in your main project module (or class):
|
|
21
31
|
include VersionInfo
|
22
32
|
end
|
23
33
|
|
24
|
-
From here, is better to use
|
34
|
+
From here, is better to use rake/thor tasks (see it forward).
|
35
|
+
|
36
|
+
Here is how VersionInfo works and their user options:
|
25
37
|
|
26
|
-
After you included
|
38
|
+
After you included VersionInfo, a new constant MyProject::VERSION is created holding an object of class VersionInfo::Data
|
27
39
|
|
28
40
|
VersionInfo use yaml file to store version data:
|
29
41
|
|
@@ -39,21 +51,27 @@ when using Rake or Thor.
|
|
39
51
|
Anyway, you can change this (recomended):
|
40
52
|
module MyProject
|
41
53
|
include VersionInfo
|
42
|
-
|
54
|
+
VERSION.file_name = '/path/to/my_file.yaml'
|
43
55
|
end
|
44
56
|
|
45
|
-
Note you can put any custom data. In order to get the version tag, VersionInfo
|
57
|
+
Note you can put any custom data. In order to get the version tag, VersionInfo define the segments of the version tag. Here the source code:
|
46
58
|
|
47
59
|
module VersionInfo
|
48
60
|
|
61
|
+
# current segments or defaults
|
49
62
|
def self.segments
|
50
|
-
[:major, :minor, :patch
|
63
|
+
@segments ||= [:major, :minor, :patch]
|
64
|
+
end
|
65
|
+
|
66
|
+
# define segments
|
67
|
+
def self.segments=(values)
|
68
|
+
@segments = values
|
51
69
|
end
|
52
70
|
|
53
71
|
...
|
54
72
|
end
|
55
73
|
|
56
|
-
|
74
|
+
Using the previous version_info.yml:
|
57
75
|
|
58
76
|
puts MyProject::VERSION.tag
|
59
77
|
|
@@ -66,13 +84,54 @@ Also you can bump any segment. With the same sample:
|
|
66
84
|
|
67
85
|
=> 1.0.0
|
68
86
|
|
69
|
-
Note
|
87
|
+
Note other "lower weight" segments are reset to 0.
|
88
|
+
|
89
|
+
### Bonus: Custom segments and tag format.
|
90
|
+
|
91
|
+
You can override the default segments
|
92
|
+
|
93
|
+
VersionInfo.segments = [:a, :b, :c]
|
94
|
+
module MyProject
|
95
|
+
include VersionInfo # force new VERSION value
|
96
|
+
end
|
97
|
+
|
98
|
+
Note this must be done **before** include VersionInfo.
|
99
|
+
|
100
|
+
Also, tag format can be redefined. VersionInfo uses simple
|
101
|
+
sprintf in order to build the tag string. Here is the code:
|
102
|
+
|
103
|
+
def tag
|
104
|
+
tag_format % to_hash
|
105
|
+
end
|
106
|
+
|
107
|
+
By default, tag_format, returns a simple sprintf format string,
|
108
|
+
using the segment names, expecting their values are numbers:
|
109
|
+
|
110
|
+
def tag_format
|
111
|
+
@tag_format ||= VersionInfo.segments.map { |k| "%<#{k}>d"}.join('.')
|
112
|
+
end
|
113
|
+
|
114
|
+
So tag_format return some like "%<major>d.%<minor>d%<patch>d".
|
115
|
+
|
116
|
+
If your VersionInfo yaml file is like:
|
117
|
+
|
118
|
+
---
|
119
|
+
major: 2
|
120
|
+
minor: 1
|
121
|
+
patch: 53
|
122
|
+
buildflag: pre
|
123
|
+
|
124
|
+
You can change the tag format
|
125
|
+
|
126
|
+
MyProject::VERSION.buildflag = 'pre'
|
127
|
+
MyProject::VERSION.tag_format = MyProject::VERSION.tag_format + "--%<buildflag>s"
|
128
|
+
puts MyProject::VERSION.tag # => '2.1.53--pre'
|
70
129
|
|
71
130
|
### Rake / Thor tasks
|
72
131
|
|
73
132
|
Put in your rake file:
|
74
133
|
|
75
|
-
VersionInfo::RakeTasks.install(:class => MyProject) #
|
134
|
+
VersionInfo::RakeTasks.install(:class => MyProject) # pass here the thing where you included VersionInfo
|
76
135
|
|
77
136
|
And you get a few tasks with a namespace vinfo:
|
78
137
|
|
@@ -87,7 +146,7 @@ And you get a few tasks with a namespace vinfo:
|
|
87
146
|
|
88
147
|
If you prefer Thor:
|
89
148
|
|
90
|
-
VersionInfo::ThorTasks.install(:class => MyProject) #
|
149
|
+
VersionInfo::ThorTasks.install(:class => MyProject) # pass here the thing where you included VersionInfo
|
91
150
|
|
92
151
|
thor list
|
93
152
|
=>
|
@@ -100,7 +159,7 @@ If you prefer Thor:
|
|
100
159
|
|
101
160
|
### Install
|
102
161
|
|
103
|
-
VersionInfo is [https://rubygems.org/gems/version_info](https://rubygems.org/gems/version_info)
|
162
|
+
VersionInfo is at [https://rubygems.org/gems/version_info](https://rubygems.org/gems/version_info) :
|
104
163
|
|
105
164
|
gem install version_info
|
106
165
|
|
data/lib/version_info/data.rb
CHANGED
@@ -9,7 +9,7 @@ module VersionInfo
|
|
9
9
|
if File.exist?(file_name)
|
10
10
|
load
|
11
11
|
else
|
12
|
-
|
12
|
+
reset
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
@@ -19,7 +19,11 @@ module VersionInfo
|
|
19
19
|
|
20
20
|
def file_name=(value)
|
21
21
|
@file_name = value
|
22
|
-
load
|
22
|
+
load if File.exist?(@file_name)
|
23
|
+
end
|
24
|
+
|
25
|
+
def reset
|
26
|
+
marshal_load(get_defaults)
|
23
27
|
end
|
24
28
|
|
25
29
|
def bump(key)
|
@@ -44,9 +48,21 @@ module VersionInfo
|
|
44
48
|
def to_s
|
45
49
|
tag
|
46
50
|
end
|
51
|
+
|
52
|
+
def to_hash
|
53
|
+
marshal_dump
|
54
|
+
end
|
47
55
|
|
48
56
|
def tag
|
49
|
-
|
57
|
+
tag_format % to_hash
|
58
|
+
end
|
59
|
+
|
60
|
+
def tag_format
|
61
|
+
@tag_format ||= VersionInfo.segments.map { |k| "%<#{k}>d"}.join('.')
|
62
|
+
end
|
63
|
+
|
64
|
+
def tag_format=(value)
|
65
|
+
@tag_format = value
|
50
66
|
end
|
51
67
|
|
52
68
|
protected
|
@@ -56,7 +72,8 @@ module VersionInfo
|
|
56
72
|
|
57
73
|
def load_from(io)
|
58
74
|
values = YAML.load(io)
|
59
|
-
|
75
|
+
# force keys as symbols
|
76
|
+
values.keys.each{|k| values[k.to_sym] = values.delete(k)}
|
60
77
|
marshal_load(values)
|
61
78
|
self
|
62
79
|
end
|
@@ -66,15 +83,5 @@ module VersionInfo
|
|
66
83
|
YAML.dump(values, io)
|
67
84
|
self
|
68
85
|
end
|
69
|
-
|
70
|
-
def underscore(camel_cased_word)
|
71
|
-
word = camel_cased_word.to_s.dup
|
72
|
-
word.gsub!(/::/, '/')
|
73
|
-
word.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
|
74
|
-
word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
|
75
|
-
word.tr!("-", "_")
|
76
|
-
word.downcase!
|
77
|
-
word
|
78
|
-
end
|
79
86
|
end
|
80
87
|
end
|
data/lib/version_info.rb
CHANGED
@@ -2,13 +2,17 @@ require 'version_info/data'
|
|
2
2
|
|
3
3
|
module VersionInfo
|
4
4
|
|
5
|
+
# current segments or defaults
|
5
6
|
def self.segments
|
6
|
-
[:major, :minor, :patch]
|
7
|
+
@segments ||= [:major, :minor, :patch]
|
8
|
+
end
|
9
|
+
|
10
|
+
# define segments
|
11
|
+
def self.segments=(values)
|
12
|
+
@segments = values
|
7
13
|
end
|
8
14
|
|
9
15
|
def self.included(other)
|
10
|
-
# data = Class.new(Data)
|
11
|
-
# other.const_set('Version', data)
|
12
16
|
other.const_set('VERSION', Data.new)
|
13
17
|
end
|
14
18
|
|
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
require 'version_info/test_file'
|
4
4
|
|
5
|
-
describe "VersionInfo" do
|
5
|
+
describe "VersionInfo defaults" do
|
6
6
|
|
7
7
|
before :each do
|
8
8
|
module TestFile
|
@@ -13,7 +13,6 @@ describe "VersionInfo" do
|
|
13
13
|
after :each do
|
14
14
|
module TestFile
|
15
15
|
remove_const :VERSION
|
16
|
-
# remove_const :Version
|
17
16
|
end
|
18
17
|
end
|
19
18
|
|
@@ -38,6 +37,15 @@ describe "VersionInfo" do
|
|
38
37
|
TestFile::VERSION.tag.should == '0.0.0'
|
39
38
|
end
|
40
39
|
|
40
|
+
it "tag has format" do
|
41
|
+
TestFile::VERSION.tag.should == '0.0.0'
|
42
|
+
end
|
43
|
+
it "tag format can be changed" do
|
44
|
+
TestFile::VERSION.build_flag = 'pre'
|
45
|
+
TestFile::VERSION.tag_format = TestFile::VERSION.tag_format + "--%<build_flag>s"
|
46
|
+
TestFile::VERSION.tag.should == '0.0.0--pre'
|
47
|
+
end
|
48
|
+
|
41
49
|
it "can bump a segment" do
|
42
50
|
TestFile::VERSION.bump(:patch)
|
43
51
|
TestFile::VERSION.tag.should == '0.0.1'
|
@@ -81,3 +89,32 @@ describe "VersionInfo" do
|
|
81
89
|
end
|
82
90
|
|
83
91
|
end
|
92
|
+
|
93
|
+
describe "VersionInfo custom segments" do
|
94
|
+
before :each do
|
95
|
+
VersionInfo.segments = [:a, :b, :c]
|
96
|
+
module TestFile
|
97
|
+
include VersionInfo # force new VERSION value
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
after :each do
|
102
|
+
module TestFile
|
103
|
+
remove_const :VERSION
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
it "can be assigned" do
|
108
|
+
TestFile::VERSION.marshal_dump.should == {:a => 0, :b => 0, :c => 0 }
|
109
|
+
end
|
110
|
+
|
111
|
+
it "segments are properties" do
|
112
|
+
TestFile::VERSION.a.should == 0
|
113
|
+
end
|
114
|
+
|
115
|
+
it "can bump a custom segment" do
|
116
|
+
TestFile::VERSION.bump(:c)
|
117
|
+
TestFile::VERSION.bump(:b)
|
118
|
+
TestFile::VERSION.tag.should == '0.1.0'
|
119
|
+
end
|
120
|
+
end
|
data/version_info.gemspec
CHANGED
@@ -20,6 +20,8 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
21
21
|
s.require_paths = ["lib"]
|
22
22
|
|
23
|
+
s.add_development_dependency "bundler"
|
24
|
+
s.add_development_dependency "rake"
|
23
25
|
s.add_development_dependency "rspec"
|
24
26
|
s.add_development_dependency "test_notifier"
|
25
27
|
end
|
metadata
CHANGED
@@ -1,12 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: version_info
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
|
6
|
-
- 1
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
version: 1.0.0
|
4
|
+
prerelease:
|
5
|
+
version: 1.1.0
|
10
6
|
platform: ruby
|
11
7
|
authors:
|
12
8
|
- Jorge L. Cangas
|
@@ -14,35 +10,52 @@ autorequire:
|
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
12
|
|
17
|
-
date: 2011-
|
18
|
-
default_executable:
|
13
|
+
date: 2011-07-18 00:00:00 Z
|
19
14
|
dependencies:
|
20
15
|
- !ruby/object:Gem::Dependency
|
21
|
-
name:
|
16
|
+
name: bundler
|
22
17
|
prerelease: false
|
23
18
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
19
|
none: false
|
25
20
|
requirements:
|
26
21
|
- - ">="
|
27
22
|
- !ruby/object:Gem::Version
|
28
|
-
segments:
|
29
|
-
- 0
|
30
23
|
version: "0"
|
31
24
|
type: :development
|
32
25
|
version_requirements: *id001
|
33
26
|
- !ruby/object:Gem::Dependency
|
34
|
-
name:
|
27
|
+
name: rake
|
35
28
|
prerelease: false
|
36
29
|
requirement: &id002 !ruby/object:Gem::Requirement
|
37
30
|
none: false
|
38
31
|
requirements:
|
39
32
|
- - ">="
|
40
33
|
- !ruby/object:Gem::Version
|
41
|
-
segments:
|
42
|
-
- 0
|
43
34
|
version: "0"
|
44
35
|
type: :development
|
45
36
|
version_requirements: *id002
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: rspec
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: "0"
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id003
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: test_notifier
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: "0"
|
57
|
+
type: :development
|
58
|
+
version_requirements: *id004
|
46
59
|
description: Easy way to get version label, bump the segments (major, minor, patch), and you can include custom version data
|
47
60
|
email:
|
48
61
|
- jorge.cangas@gmail.com
|
@@ -70,7 +83,6 @@ files:
|
|
70
83
|
- spec/version_info/test_file.rb
|
71
84
|
- spec/version_info/version_info_spec.rb
|
72
85
|
- version_info.gemspec
|
73
|
-
has_rdoc: true
|
74
86
|
homepage: http://github.com/jcangas/version_info
|
75
87
|
licenses: []
|
76
88
|
|
@@ -84,21 +96,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
84
96
|
requirements:
|
85
97
|
- - ">="
|
86
98
|
- !ruby/object:Gem::Version
|
87
|
-
segments:
|
88
|
-
- 0
|
89
99
|
version: "0"
|
90
100
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
101
|
none: false
|
92
102
|
requirements:
|
93
103
|
- - ">="
|
94
104
|
- !ruby/object:Gem::Version
|
95
|
-
segments:
|
96
|
-
- 0
|
97
105
|
version: "0"
|
98
106
|
requirements: []
|
99
107
|
|
100
108
|
rubyforge_project: version_info
|
101
|
-
rubygems_version: 1.
|
109
|
+
rubygems_version: 1.8.5
|
102
110
|
signing_key:
|
103
111
|
specification_version: 3
|
104
112
|
summary: A Ruby gem to manage your project version data. Rake tasks included!
|