version_info 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.
- data/.gitignore +3 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +28 -0
- data/README.md +48 -0
- data/Rakefile +4 -0
- data/autotest/discover.rb +1 -0
- data/lib/version_info/data.rb +60 -0
- data/lib/version_info/tasks.rb +18 -0
- data/lib/version_info/version.rb +3 -0
- data/lib/version_info.rb +17 -0
- data/spec/spec_helper.rb +3 -0
- data/spec/version_info/test_file.rb +7 -0
- data/spec/version_info/version_info_spec.rb +75 -0
- data/version_info.gemspec +24 -0
- metadata +103 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
version_info (0.2.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: http://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.1.2)
|
10
|
+
notifier (0.1.1)
|
11
|
+
rspec (2.3.0)
|
12
|
+
rspec-core (~> 2.3.0)
|
13
|
+
rspec-expectations (~> 2.3.0)
|
14
|
+
rspec-mocks (~> 2.3.0)
|
15
|
+
rspec-core (2.3.1)
|
16
|
+
rspec-expectations (2.3.0)
|
17
|
+
diff-lcs (~> 1.1.2)
|
18
|
+
rspec-mocks (2.3.0)
|
19
|
+
test_notifier (0.3.6)
|
20
|
+
notifier
|
21
|
+
|
22
|
+
PLATFORMS
|
23
|
+
ruby
|
24
|
+
|
25
|
+
DEPENDENCIES
|
26
|
+
rspec
|
27
|
+
test_notifier
|
28
|
+
version_info!
|
data/README.md
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
## Usage:
|
2
|
+
|
3
|
+
|
4
|
+
Include VersionInfo in your main project module (or class):
|
5
|
+
|
6
|
+
require 'version_info'
|
7
|
+
|
8
|
+
module MyProject
|
9
|
+
include VersionInfo
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
Create a file to store your version data. By default the file is named version_info.yml:
|
14
|
+
|
15
|
+
---
|
16
|
+
major: 0
|
17
|
+
minor: 1
|
18
|
+
patch: 0
|
19
|
+
author: jcangas
|
20
|
+
|
21
|
+
|
22
|
+
Note you can put any custom data. In order to get the version tag, VersionInfo reserve some special keys
|
23
|
+
for use as the "segments" of the version tag:
|
24
|
+
|
25
|
+
module VersionInfo
|
26
|
+
|
27
|
+
def self.segments
|
28
|
+
[:major, :minor, :patch, :state, :build]
|
29
|
+
end
|
30
|
+
|
31
|
+
...
|
32
|
+
end
|
33
|
+
|
34
|
+
Usingh the previous version_info.yml:
|
35
|
+
|
36
|
+
puts MyProject::VERSION.tag
|
37
|
+
|
38
|
+
=> 0.1.0
|
39
|
+
|
40
|
+
Also you can bump any segment. With the same sample:
|
41
|
+
|
42
|
+
MyProject::VERSION.bump(:major)
|
43
|
+
puts MyProject::VERSION.tag
|
44
|
+
|
45
|
+
=> 1.0.0
|
46
|
+
|
47
|
+
Note the other segments are reset to 0 after bump.
|
48
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Autotest.add_discovery { "rspec2" }
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
module VersionInfo
|
3
|
+
class Data < OpenStruct
|
4
|
+
attr_accessor :file_name
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
super
|
8
|
+
if File.exist?(file_name)
|
9
|
+
load
|
10
|
+
else
|
11
|
+
marshal_load(get_defaults)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def file_name
|
16
|
+
@file_name ||= 'version_info.yml'
|
17
|
+
end
|
18
|
+
|
19
|
+
def bump(key)
|
20
|
+
idx = VersionInfo.segments.index(key.to_sym) + 1
|
21
|
+
return unless idx
|
22
|
+
VersionInfo.segments[idx..-1].each do |sgm|
|
23
|
+
send("#{sgm}=", 0) if send(sgm)
|
24
|
+
end
|
25
|
+
send("#{key}=", 1 + send(key))
|
26
|
+
end
|
27
|
+
|
28
|
+
def load
|
29
|
+
load_from(File.read(file_name))
|
30
|
+
self
|
31
|
+
end
|
32
|
+
|
33
|
+
def save
|
34
|
+
File.open( file_name, 'w' ) {|out| save_to(out)}
|
35
|
+
self
|
36
|
+
end
|
37
|
+
|
38
|
+
def tag
|
39
|
+
VersionInfo.segments.map { |k| send(k) }.compact.join('.')
|
40
|
+
end
|
41
|
+
|
42
|
+
protected
|
43
|
+
def get_defaults
|
44
|
+
VersionInfo.segments[0..2].inject({}){|h, k| h[k] = 0; h}
|
45
|
+
end
|
46
|
+
|
47
|
+
def load_from(io)
|
48
|
+
values = YAML.load(io)
|
49
|
+
values.keys.each{|k, v| values[k.to_sym] = values.delete(k)}
|
50
|
+
marshal_load(values)
|
51
|
+
self
|
52
|
+
end
|
53
|
+
|
54
|
+
def save_to(io)
|
55
|
+
values = self.marshal_dump.keys.compact.inject({}){|r, k| r[k.to_s] = send(k); r }
|
56
|
+
YAML.dump(values, io )
|
57
|
+
self
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module VersionInfo
|
2
|
+
class Tasks
|
3
|
+
def self.install(opts = nil)
|
4
|
+
dir = caller.find{|c| /Rakefile:/}[/^(.*?)\/Rakefile:/, 1]
|
5
|
+
self.new(dir, opts && opts[:name]).install
|
6
|
+
end
|
7
|
+
|
8
|
+
def install
|
9
|
+
namespace :vinfo do
|
10
|
+
desc "bump SEGMENT , Bumps a version info segment ('major','minor','patch','state','build')"
|
11
|
+
task 'bump' do
|
12
|
+
puts "Wow!"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
data/lib/version_info.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'version_info/data'
|
2
|
+
|
3
|
+
module VersionInfo
|
4
|
+
|
5
|
+
autoload :Tasks, 'version_info/tasks'
|
6
|
+
|
7
|
+
def self.segments
|
8
|
+
[:major, :minor, :patch, :state, :build]
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.included(other)
|
12
|
+
other.const_set('VERSION', Data.new)
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'version_info/test_file'
|
4
|
+
|
5
|
+
describe "VersionInfo" do
|
6
|
+
before :each do
|
7
|
+
module TestFile
|
8
|
+
include VersionInfo # force new VERSION data
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
it "is initalized" do
|
13
|
+
TestFile::VERSION.marshal_dump.should == {:major => 0, :minor => 0, :patch => 0 }
|
14
|
+
end
|
15
|
+
|
16
|
+
it "has default filename" do
|
17
|
+
TestFile::VERSION.file_name.should == 'version_info.yml'
|
18
|
+
end
|
19
|
+
|
20
|
+
it "can assign filename" do
|
21
|
+
TestFile::VERSION.file_name = 'test_file.vinfo'
|
22
|
+
TestFile::VERSION.file_name.should == 'test_file.vinfo'
|
23
|
+
end
|
24
|
+
|
25
|
+
it "has a minor property" do
|
26
|
+
TestFile::VERSION.minor.should == 0
|
27
|
+
end
|
28
|
+
|
29
|
+
it "has a tag property" do
|
30
|
+
TestFile::VERSION.tag.should == '0.0.0'
|
31
|
+
end
|
32
|
+
|
33
|
+
it "can bump a segment" do
|
34
|
+
TestFile::VERSION.bump(:patch)
|
35
|
+
TestFile::VERSION.tag.should == '0.0.1'
|
36
|
+
end
|
37
|
+
|
38
|
+
it "bump a segment reset sublevels " do
|
39
|
+
TestFile::VERSION.bump(:patch)
|
40
|
+
TestFile::VERSION.bump(:minor)
|
41
|
+
TestFile::VERSION.tag.should == '0.1.0'
|
42
|
+
end
|
43
|
+
|
44
|
+
it "can save " do
|
45
|
+
io = StringIO.new
|
46
|
+
File.stub!(:open).and_yield(io)
|
47
|
+
TestFile::VERSION.bump(:minor)
|
48
|
+
TestFile::VERSION.save
|
49
|
+
io.string.should == "--- \nmajor: 0\nminor: 1\npatch: 0\n"
|
50
|
+
end
|
51
|
+
|
52
|
+
it "can save custom data " do
|
53
|
+
io = StringIO.new
|
54
|
+
File.stub!(:open).and_yield(io)
|
55
|
+
TestFile::VERSION.bump(:minor)
|
56
|
+
TestFile::VERSION.author = 'jcangas'
|
57
|
+
TestFile::VERSION.save
|
58
|
+
io.string.should == "--- \nmajor: 0\nminor: 1\npatch: 0\nauthor: jcangas\n"
|
59
|
+
end
|
60
|
+
|
61
|
+
it "can load " do
|
62
|
+
io = StringIO.new("--- \nmajor: 1\nminor: 2\npatch: 3\n")
|
63
|
+
File.should_receive(:read).and_return{io}
|
64
|
+
TestFile::VERSION.load
|
65
|
+
TestFile::VERSION.marshal_dump.should == {:major => 1, :minor => 2, :patch => 3 }
|
66
|
+
end
|
67
|
+
|
68
|
+
it "can load custom data " do
|
69
|
+
io = StringIO.new("--- \nmajor: 1\nminor: 2\npatch: 3\nauthor: jcangas\n")
|
70
|
+
File.should_receive(:read).and_return{io}
|
71
|
+
TestFile::VERSION.load
|
72
|
+
TestFile::VERSION.marshal_dump.should == {:major => 1, :minor => 2, :patch => 3, :author => 'jcangas' }
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "version_info/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "version_info"
|
7
|
+
s.version = VersionInfo::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Jorge L. Cangas"]
|
10
|
+
s.email = ["jorge.cangas@gmail.com"]
|
11
|
+
s.homepage = "http://rubygems.org/gems/version_info"
|
12
|
+
s.summary = %q{A Ruby gem to manage your project version data}
|
13
|
+
s.description = %q{Easy way to get version label, bump the segments (major, minor, patch), and you can include custom version data}
|
14
|
+
|
15
|
+
s.rubyforge_project = "version_info"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_development_dependency "rspec"
|
23
|
+
s.add_development_dependency "test_notifier"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: version_info
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 2
|
8
|
+
- 0
|
9
|
+
version: 0.2.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Jorge L. Cangas
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-12-31 00:00:00 +01:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rspec
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
version: "0"
|
31
|
+
type: :development
|
32
|
+
version_requirements: *id001
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: test_notifier
|
35
|
+
prerelease: false
|
36
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
version: "0"
|
44
|
+
type: :development
|
45
|
+
version_requirements: *id002
|
46
|
+
description: Easy way to get version label, bump the segments (major, minor, patch), and you can include custom version data
|
47
|
+
email:
|
48
|
+
- jorge.cangas@gmail.com
|
49
|
+
executables: []
|
50
|
+
|
51
|
+
extensions: []
|
52
|
+
|
53
|
+
extra_rdoc_files: []
|
54
|
+
|
55
|
+
files:
|
56
|
+
- .gitignore
|
57
|
+
- Gemfile
|
58
|
+
- Gemfile.lock
|
59
|
+
- README.md
|
60
|
+
- Rakefile
|
61
|
+
- autotest/discover.rb
|
62
|
+
- lib/version_info.rb
|
63
|
+
- lib/version_info/data.rb
|
64
|
+
- lib/version_info/tasks.rb
|
65
|
+
- lib/version_info/version.rb
|
66
|
+
- spec/spec_helper.rb
|
67
|
+
- spec/version_info/test_file.rb
|
68
|
+
- spec/version_info/version_info_spec.rb
|
69
|
+
- version_info.gemspec
|
70
|
+
has_rdoc: true
|
71
|
+
homepage: http://rubygems.org/gems/version_info
|
72
|
+
licenses: []
|
73
|
+
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options: []
|
76
|
+
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
segments:
|
85
|
+
- 0
|
86
|
+
version: "0"
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
segments:
|
93
|
+
- 0
|
94
|
+
version: "0"
|
95
|
+
requirements: []
|
96
|
+
|
97
|
+
rubyforge_project: version_info
|
98
|
+
rubygems_version: 1.3.7
|
99
|
+
signing_key:
|
100
|
+
specification_version: 3
|
101
|
+
summary: A Ruby gem to manage your project version data
|
102
|
+
test_files: []
|
103
|
+
|