version_info 1.1.4 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- version_info (1.1.3)
4
+ version_info (1.7.0)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
data/README.md CHANGED
@@ -1,8 +1,62 @@
1
1
  ## VersionInfo
2
2
 
3
- ### Overview
3
+ ### Travis CI status
4
4
 
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
5
+ [![Build Status](https://secure.travis-ci.org/jcangas/version_info.png)](http://travis-ci.org/jcangas/version_info)
6
+
7
+ ### Install
8
+
9
+ VersionInfo is at [https://rubygems.org/gems/version_info](https://rubygems.org/gems/version_info), so:
10
+
11
+ gem install version_info
12
+
13
+ ### Usage
14
+
15
+ VersionInfo is a powerful and lightweight gem to manage version data in your Ruby projects or gems.
16
+ And is very user friendly thanks to rake / thor tasks:
17
+
18
+ First, include VersionInfo in your main project module (or class):
19
+
20
+ require 'version_info'
21
+
22
+ module MyProject
23
+ VERSION = "1.5.0"
24
+
25
+ include VersionInfo
26
+ VERSION.file_name = __FILE__
27
+ end
28
+
29
+ Then use rake/thor tasks:
30
+
31
+ rake vinfo:minor
32
+
33
+ => version changed to 1.6.0
34
+
35
+ Please, note here VersionInfo is included *after* the constant VERSION, if you don't like this also works
36
+
37
+ module MyProject
38
+ include VersionInfo
39
+ self.VERSION = "1.5.0"
40
+ VERSION.file_name = __FILE__
41
+ end
42
+
43
+ Please note here you are invoking a singleton method and not using a constant. When included VersionInfo
44
+ does a bit of magic and then you can use *both* the method and the constant:
45
+
46
+ MyProject.VERSION # it works
47
+ MyProject::VERSION # also works
48
+
49
+ One more sample:
50
+
51
+ Gem::Specification.new do |s|
52
+ s.name = "version_info"
53
+ s.version = VersionInfo::VERSION
54
+ s.platform = Gem::Platform::RUBY
55
+
56
+ After VersionInfo is included, the singleton method and the constant returns a object of class VersionInfo::Data.
57
+ You can use some methods from it, (#bump, #to_s, #tag, etc.). Also you get another singleton method to easy assignment:
58
+
59
+ MyProject.VERSION= "2.0.2" # also works
6
60
 
7
61
  #### Features
8
62
 
@@ -14,77 +68,82 @@
14
68
 
15
69
  * can include any custom info in your version data.
16
70
 
17
- * Version data is stored in a yaml file.
18
-
19
71
  * good rspec tests
20
72
 
73
+ * Flexible formats for stored your version data:
21
74
 
22
- Feel free to contact me about bugs/features
23
-
24
- ### Usage
25
-
26
- Include VersionInfo in your main project module (or class):
27
-
28
- require 'version_info'
75
+ * In a ruby source (default)
29
76
 
30
77
  module MyProject
31
78
  include VersionInfo
79
+ self.VERSION = "1.5.0"
80
+ VERSION.file_name = __FILE__ # required for this format
32
81
  end
82
+
83
+ * In a text file
33
84
 
34
- From here, is better to use rake/thor tasks (see it forward).
35
-
36
- Here is how VersionInfo works and their user options:
37
-
38
- After you included VersionInfo, a new constant MyProject::VERSION is created holding an object of class VersionInfo::Data
85
+ Version.file_format= :text
86
+ module MyProject
87
+ include VersionInfo
88
+ VERSION.file_name = /some_path/your_version_file #convenient but optional for this format
89
+ end
39
90
 
40
- VersionInfo use yaml file to store version data:
91
+ The file is named by default VERSION and looks like
41
92
 
42
- ---
43
- major: 0
44
- minor: 1
45
- patch: 0
93
+ 2.2.3
46
94
  author: jcangas
95
+ email: jorge.cangas@gmail.com
47
96
 
48
- By default the file is named version_info.yml and stored in the current dir, useful
49
- when using Rake or Thor.
97
+
98
+ * In a yaml file, as a hash
50
99
 
51
- Anyway, you can change this (recomended):
100
+ Version.file_format= :yaml
52
101
  module MyProject
53
102
  include VersionInfo
54
- VERSION.file_name = '/path/to/my_file.yaml'
103
+ VERSION.file_name = /some_path/your_file.yaml #convenient but optional for this format
55
104
  end
56
105
 
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:
106
+ The file is named by default version_info.yml and looks like
58
107
 
59
- module VersionInfo
108
+ ---
109
+ major: 1
110
+ minor: 1
111
+ patch: 4
112
+ author: jcangas
60
113
 
61
- # current segments or defaults
62
- def self.segments
63
- @segments ||= [:major, :minor, :patch]
64
- end
65
114
 
66
- # define segments
67
- def self.segments=(values)
68
- @segments = values
69
- end
115
+ Pleae, feel free to contact me about bugs/features
70
116
 
71
- ...
72
- end
117
+ ### Rake / Thor tasks
118
+
119
+ Put in your rake file:
73
120
 
74
- Using the previous version_info.yml:
121
+ VersionInfo::RakeTasks.install(:class => MyProject) # pass here the thing where you included VersionInfo
75
122
 
76
- puts MyProject::VERSION.tag
123
+ And you get a few tasks with a namespace vinfo:
77
124
 
78
- => 0.1.0
125
+ rake -T
126
+ =>
127
+ rake vinfo:file # Show version file format & name
128
+ rake vinfo:inspect # Show complete version info
129
+ rake vinfo:major # Bumps version segment MAJOR
130
+ rake vinfo:minor # Bumps version segment MINOR
131
+ rake vinfo:patch # Bumps version segment PATCH
132
+ rake vinfo:show # Show current version tag and create version_info.yml if missing
79
133
 
80
- Also you can bump any segment. With the same sample:
134
+ If you prefer Thor:
81
135
 
82
- MyProject::VERSION.bump(:major)
83
- puts MyProject::VERSION
136
+ VersionInfo::ThorTasks.install(:class => MyProject) # pass here the thing where you included VersionInfo
84
137
 
85
- => 1.0.0
138
+ thor list
139
+ =>
86
140
 
87
- Note other "lower weight" segments are reset to 0.
141
+ vinfo
142
+ -----
143
+ rake vinfo:file # Show version file format & name
144
+ thor vinfo:bump SEGMENT=patch # bumps segment: [major, minor, patch, build]...
145
+ thor vinfo:inspect # Show complete version info
146
+ thor vinfo:show # Show version tag and create version_info.yml...
88
147
 
89
148
  ### Bonus: Custom segments and tag format.
90
149
 
@@ -92,7 +151,7 @@ Note other "lower weight" segments are reset to 0.
92
151
 
93
152
  VersionInfo.segments = [:a, :b, :c]
94
153
  module MyProject
95
- include VersionInfo # force new VERSION value
154
+ include VersionInfo
96
155
  end
97
156
 
98
157
  Note this must be done **before** include VersionInfo.
@@ -127,39 +186,4 @@ You can change the tag format
127
186
  MyProject::VERSION.tag_format = MyProject::VERSION.tag_format + "--%<buildflag>s"
128
187
  puts MyProject::VERSION.tag # => '2.1.53--pre'
129
188
 
130
- ### Rake / Thor tasks
131
-
132
- Put in your rake file:
133
-
134
- VersionInfo::RakeTasks.install(:class => MyProject) # pass here the thing where you included VersionInfo
135
-
136
- And you get a few tasks with a namespace vinfo:
137
-
138
- rake -T
139
- =>
140
- rake vinfo:build # Bumps version segment BUILD
141
- rake vinfo:inspect # Show complete version info
142
- rake vinfo:major # Bumps version segment MAJOR
143
- rake vinfo:minor # Bumps version segment MINOR
144
- rake vinfo:patch # Bumps version segment PATCH
145
- rake vinfo:show # Show current version tag and create version_info.yml if missing
146
-
147
- If you prefer Thor:
148
-
149
- VersionInfo::ThorTasks.install(:class => MyProject) # pass here the thing where you included VersionInfo
150
-
151
- thor list
152
- =>
153
-
154
- vinfo
155
- -----
156
- thor vinfo:bump SEGMENT=patch # bumps segment: [major, minor, patch, build]...
157
- thor vinfo:inspect # Show complete version info
158
- thor vinfo:show # Show version tag and create version_info.yml...
159
-
160
- ### Install
161
-
162
- VersionInfo is at [https://rubygems.org/gems/version_info](https://rubygems.org/gems/version_info) :
163
-
164
- gem install version_info
165
189
 
data/Rakefile CHANGED
@@ -8,7 +8,7 @@ require 'version_info'
8
8
  require 'version_info/version'
9
9
 
10
10
 
11
- VersionInfo::RakeTasks.install(:class => VersionInfo)
11
+ VersionInfo::install_tasks(:target => VersionInfo)
12
12
 
13
13
  # now we have VersionInfo::VERSION defined, can load this
14
14
  Bundler::GemHelper.install_tasks
@@ -17,7 +17,7 @@ require 'rspec/core/rake_task'
17
17
 
18
18
  desc "run specs"
19
19
  RSpec::Core::RakeTask.new do |t|
20
- t.rspec_opts = ["-c", "-f progress", "-r ./spec/spec_helper.rb"]
20
+ t.rspec_opts = ["-c", "-f d", "-r ./spec/spec_helper.rb"]
21
21
  t.pattern = 'spec/**/*_spec.rb'
22
22
  end
23
23
 
@@ -1,29 +1,41 @@
1
1
  require 'ostruct'
2
- require 'yaml'
3
2
 
4
3
  module VersionInfo
4
+
5
5
  class Data < OpenStruct
6
6
 
7
7
  def initialize
8
8
  super
9
- if File.exist?(file_name)
10
- load
11
- else
12
- reset
9
+ case VersionInfo.file_format.to_s
10
+ when 'text'
11
+ require 'version_info/text_storage'
12
+ extend(TextStorage)
13
+ when 'yaml'
14
+ require 'version_info/yaml_storage'
15
+ extend(YamlStorage)
16
+ else # asume 'module'
17
+ require 'version_info/module_storage'
18
+ extend(ModuleStorage)
13
19
  end
20
+ reset
21
+ file_name = nil
14
22
  end
15
23
 
16
24
  def file_name
17
- @file_name ||= Dir.pwd + '/' + 'version_info.yml'
25
+ @file_name ||= Dir.pwd + '/' + default_file_name
18
26
  end
19
27
 
20
28
  def file_name=(value)
21
29
  @file_name = value
22
- load if File.exist?(@file_name)
30
+ load if self.file_name && File.exist?(self.file_name)
23
31
  end
24
32
 
25
33
  def reset
26
- marshal_load(get_defaults)
34
+ assign(get_defaults)
35
+ end
36
+
37
+ def assign(hash)
38
+ marshal_load(hash)
27
39
  end
28
40
 
29
41
  def bump(key)
@@ -65,23 +77,14 @@ module VersionInfo
65
77
  @tag_format = value
66
78
  end
67
79
 
68
- protected
69
- def get_defaults
70
- VersionInfo.segments[0..2].inject({}){|h, k| h[k] = 0; h}
71
- end
72
-
73
- def load_from(io)
74
- values = YAML.load(io)
75
- # force keys as symbols
76
- values.keys.each{|k| values[k.to_sym] = values.delete(k)}
77
- marshal_load(values)
78
- self
80
+ def set_version_info(tag_str)
81
+ values = tag_str.split('.')
82
+ VersionInfo.segments.each{|sgm| self.send("#{sgm}=", values.shift.match(/(\d+)/).to_s.to_i) }
79
83
  end
80
84
 
81
- def save_to(io)
82
- values = self.marshal_dump.keys.compact.inject({}){|r, k| r[k.to_s] = send(k); r }
83
- YAML.dump(values, io)
84
- self
85
- end
85
+ def get_defaults
86
+ VersionInfo.segments[0..2].inject({}){|h, k| h[k] = 0; h}
87
+ end
86
88
  end
87
89
  end
90
+
@@ -0,0 +1,33 @@
1
+
2
+ module VersionInfo
3
+ # Version data is stored in a ruby file into the project top module :
4
+
5
+ # module MyProject
6
+ # VERSION = "0.0.1"
7
+ # VERSION.author = "jcangas"
8
+ # VERSION.email = "jorge.cangas@gmail.com"
9
+ # end
10
+ #
11
+ # The convenion is to name this file "version.rb"
12
+
13
+ module ModuleStorage
14
+
15
+ def default_file_name
16
+ 'version.rb'
17
+ end
18
+
19
+ def load_from(io)
20
+ self
21
+ end
22
+
23
+ def save
24
+ content = File.read(file_name)
25
+ content.gsub!(/(\s*VERSION\s*=\s*)('|").*('|")/, "\\1\\2#{tag}\\3")
26
+ File.open(file_name, 'w' ) {|out| out.print content}
27
+ self
28
+ end
29
+
30
+ end
31
+
32
+ end
33
+
@@ -3,7 +3,6 @@ module VersionInfo
3
3
  include Rake::DSL
4
4
 
5
5
  def self.install(opts = {})
6
- #dir = caller.find{|c| /Rakefile:/}[/^(.*?)\/Rakefile:/, 1]
7
6
  dir = File.dirname(Rake.application.rakefile_location)
8
7
  self.new(dir, opts).install
9
8
  end
@@ -13,18 +12,23 @@ module VersionInfo
13
12
 
14
13
  def initialize(root_path, opts)
15
14
  @root_path = root_path
16
- @target = opts[:class]
15
+ @target = opts[:target]
17
16
  end
18
17
 
19
18
  def install
20
19
  namespace :vinfo do
21
20
 
21
+ desc "Show version file format & name"
22
+ task :file do
23
+ puts "#{VersionInfo.file_format.to_s} format: #{target::VERSION.file_name}"
24
+ end
25
+
22
26
  desc "Show complete version info"
23
27
  task :inspect do
24
28
  puts target::VERSION.inspect
25
29
  end
26
30
 
27
- desc "Show current version tag and create version_info.yml if missing"
31
+ desc "Show tag. Create version file if none"
28
32
  task :show do
29
33
  puts target::VERSION.tag
30
34
  target::VERSION.save unless File.exist?(target::VERSION.file_name)
@@ -0,0 +1,31 @@
1
+
2
+ module VersionInfo
3
+ # Version data is stored in a text file with this structure
4
+ # 2.2.3 # => numeric segments at first line
5
+ # author: jcangas # => custom key after, one per line
6
+ # email: jorge.cangas@gmail.com # => another custom key
7
+ #
8
+ # The convenion is to name this file "VERSION"
9
+
10
+ module TextStorage
11
+
12
+ def default_file_name
13
+ 'VERSION'
14
+ end
15
+
16
+ def load_from(io)
17
+ content = io.readlines
18
+ str = content.shift
19
+ custom = content.inject({}) {|result, line| k, v = line.chomp.split(':'); result[k.strip.to_sym] = v.strip; result}
20
+ self.to_hash.merge!(custom)
21
+ self.set_version_info(str)
22
+ self
23
+ end
24
+
25
+ def save_to(io)
26
+ io.puts VersionInfo.segments.map{|sgm| send(sgm)}.join('.')
27
+ to_hash.each {|k, v| io.puts "#{k}: #{v}" unless VersionInfo.segments.include?(k) }
28
+ self
29
+ end
30
+ end
31
+ end
@@ -2,13 +2,18 @@ module VersionInfo
2
2
  module ThorTasks
3
3
  def self.install(opts = {})
4
4
  Class.new(::Thor) do
5
- @target = opts[:class]
5
+ @target = opts[:target]
6
6
  class << self
7
7
  attr_reader :target
8
8
  end
9
9
  namespace :vinfo
10
10
 
11
- desc 'show', "Show version tag and create version_info.yml if missing"
11
+ desc 'file, '"Show version file format & name"
12
+ def file
13
+ puts "#{VersionInfo.file_format.to_s} format: #{target::VERSION.file_name}"
14
+ end
15
+
16
+ desc 'show', "Show tag. Create version file if none"
12
17
  def show
13
18
  puts target::VERSION.tag
14
19
  target::VERSION.save unless File.exist?(target::VERSION.file_name)
@@ -1,5 +1,7 @@
1
+
1
2
  module VersionInfo
2
- VERSION = Data.new
3
- VERSION.file_name = 'lib/version_info/version_info.yml'
3
+ VERSION = "1.7.0"
4
+ versionable(self)
5
+ VERSION.file_name = __FILE__
4
6
  end
5
7
 
@@ -0,0 +1,31 @@
1
+ require 'yaml'
2
+
3
+ module VersionInfo
4
+ # Version data is stored in a yaml file as a simple hash, i.e. :
5
+
6
+ # ---
7
+ # major: 1
8
+ # minor: 1
9
+ # patch: 4
10
+ # author: jcangas
11
+
12
+ module YamlStorage
13
+ def default_file_name
14
+ 'version_info.yml'
15
+ end
16
+
17
+ def load_from(io)
18
+ values = YAML.load(io)
19
+ # force keys as symbols
20
+ values.keys.each{|k| values[k.to_sym] = values.delete(k)}
21
+ assign(values)
22
+ self
23
+ end
24
+
25
+ def save_to(io)
26
+ values = self.to_hash.keys.compact.inject({}){|r, k| r[k.to_s] = send(k); r }
27
+ YAML.dump(values, io)
28
+ self
29
+ end
30
+ end
31
+ end
data/lib/version_info.rb CHANGED
@@ -11,13 +11,46 @@ module VersionInfo
11
11
  def self.segments=(values)
12
12
  @segments = values
13
13
  end
14
-
14
+
15
+ def self.file_format
16
+ @file_format ||= :module
17
+ end
18
+
19
+ def self.install_tasks(options)
20
+ if defined?(:Rake)
21
+ require 'version_info/rake_tasks'
22
+ RakeTasks.install(options)
23
+ elsif defined?(:Thor)
24
+ require 'version_info/thor_tasks'
25
+ ThorTasks.install(options)
26
+ end
27
+ end
28
+
29
+ def self.file_format=(value)
30
+ @file_format = value
31
+ end
32
+
15
33
  def self.included(other)
16
- other.const_set('VERSION', Data.new)
34
+ self.versionable(other)
17
35
  end
18
36
 
19
- autoload :RakeTasks, 'version_info/rake_tasks'
20
- autoload :ThorTasks, 'version_info/thor_tasks'
37
+ def self.versionable(other)
38
+ if other.const_defined?(:VERSION, false)
39
+ old_const = other.const_get(:VERSION, false)
40
+ other.send(:remove_const, :VERSION) rescue true
41
+ end
42
+ other.const_set(:VERSION, Data.new)
43
+ singleton = other.singleton_class
44
+ singleton.class_eval do
45
+ define_method :VERSION do
46
+ @data ||= self::VERSION
47
+ end
48
+ define_method :"VERSION=" do |value_str|
49
+ self.VERSION.set_version_info(value_str)
50
+ end
51
+ end
52
+ other.VERSION= old_const if old_const
53
+ end
21
54
 
22
55
  end
23
56
 
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Module file format" do
4
+ before :each do
5
+ VersionInfo.file_format = :module
6
+
7
+ @test_module = Module.new
8
+ @test_module.send :include, VersionInfo # force new VERSION value
9
+ @test_module::VERSION.file_name = nil
10
+ end
11
+
12
+ it "has accessor " do
13
+ @test_module.should respond_to("VERSION")
14
+ end
15
+
16
+ it "has mutator " do
17
+ @test_module.should respond_to("VERSION=")
18
+ end
19
+
20
+ it "has default filename" do
21
+ @test_module.VERSION.file_name.should == Dir.pwd + '/' + 'version.rb'
22
+ end
23
+
24
+ it "is initalized" do
25
+ @test_module.VERSION.to_hash.should == {:major => 0, :minor => 0, :patch => 0 }
26
+ end
27
+
28
+ it "has segmentes" do
29
+ @test_module.VERSION.major.should == 0
30
+ @test_module.VERSION.minor.should == 0
31
+ @test_module.VERSION.patch.should == 0
32
+ end
33
+
34
+ it "can assign VERSION" do
35
+ @test_module.VERSION = '1.2.4'
36
+ @test_module.VERSION.author = 'jcangas'
37
+ @test_module.VERSION.email = 'jorge.cangas@gmail.com'
38
+ @test_module.VERSION.class.name.should == 'VersionInfo::Data'
39
+ @test_module.VERSION.to_hash.should == {major: 1, minor: 2, patch: 4, author: 'jcangas', email: 'jorge.cangas@gmail.com' }
40
+ end
41
+
42
+ end
@@ -0,0 +1,57 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Text file format" do
4
+ before :each do
5
+ VersionInfo.file_format = :text
6
+ @test_module = Module.new
7
+ @test_module.send :include, VersionInfo
8
+ @test_module::VERSION.file_name = nil
9
+ end
10
+
11
+
12
+ it "has default filename" do
13
+ @test_module::VERSION.file_name.should == Dir.pwd + '/' + 'VERSION'
14
+ end
15
+
16
+ it "is initalized" do
17
+ @test_module::VERSION.to_hash.should == {:major => 0, :minor => 0, :patch => 0 }
18
+ end
19
+
20
+ it "can save " do
21
+ io = StringIO.new
22
+ File.stub!(:open).and_yield(io)
23
+ @test_module::VERSION.bump(:minor)
24
+ @test_module::VERSION.save
25
+ io.string.should == "0.1.0\n"
26
+ end
27
+
28
+ it "can save custom data " do
29
+ io = StringIO.new
30
+ File.stub!(:open).and_yield(io)
31
+ @test_module::VERSION.bump(:minor)
32
+ @test_module::VERSION.author = 'jcangas'
33
+ @test_module::VERSION.email = 'jorge.cangas@gmail.com'
34
+ @test_module::VERSION.save
35
+ io.string.should == <<END
36
+ 0.1.0
37
+ author: jcangas
38
+ email: jorge.cangas@gmail.com
39
+ END
40
+
41
+ end
42
+
43
+ it "can load " do
44
+ io = StringIO.new("1.2.3")
45
+ File.should_receive(:read).and_return{io}
46
+ @test_module::VERSION.load
47
+ @test_module::VERSION.to_hash.should == {:major => 1, :minor => 2, :patch => 3 }
48
+ end
49
+
50
+ it "can load custom data " do
51
+ io = StringIO.new("1.2.3\nauthor: jcangas\n")
52
+ File.should_receive(:read).and_return{io}
53
+ @test_module::VERSION.load
54
+ @test_module::VERSION.to_hash.should == {:major => 1, :minor => 2, :patch => 3, :author => 'jcangas' }
55
+ end
56
+
57
+ end
@@ -1,99 +1,52 @@
1
1
  require 'spec_helper'
2
2
 
3
- require 'version_info/test_file'
3
+ #require 'version_info/test_file'
4
4
 
5
5
  describe "VersionInfo defaults" do
6
6
 
7
7
  before :each do
8
- module TestFile
9
- include VersionInfo # force new VERSION value
10
- end
11
- end
8
+ @test_module = Module.new
9
+ @test_module.send :include, VersionInfo
12
10
 
13
- after :each do
14
- module TestFile
15
- remove_const :VERSION
16
- end
17
- end
18
-
19
- it "is initalized" do
20
- TestFile::VERSION.marshal_dump.should == {:major => 0, :minor => 0, :patch => 0 }
11
+ @test_module::VERSION.file_name = nil
21
12
  end
22
13
 
23
- it "has default filename" do
24
- TestFile::VERSION.file_name.should == Dir.pwd + '/version_info.yml'
14
+ it "is initalized" do
15
+ @test_module::VERSION.to_hash.should == {:major => 0, :minor => 0, :patch => 0 }
25
16
  end
26
17
 
27
18
  it "can assign filename" do
28
- TestFile::VERSION.file_name = 'test_file.vinfo'
29
- TestFile::VERSION.file_name.should == 'test_file.vinfo'
19
+ @test_module::VERSION.file_name = 'test_file.vinfo'
20
+ @test_module::VERSION.file_name.should == 'test_file.vinfo'
30
21
  end
31
22
 
32
23
  it "has a minor property" do
33
- TestFile::VERSION.minor.should == 0
24
+ lambda {@test_module::VERSION.minor}.should_not raise_error
34
25
  end
35
26
 
36
27
  it "has a tag property" do
37
- TestFile::VERSION.tag.should == '0.0.0'
28
+ lambda {@test_module::VERSION.tag}.should_not raise_error
38
29
  end
39
30
 
40
31
  it "tag has format" do
41
- TestFile::VERSION.tag.should == '0.0.0'
32
+ @test_module::VERSION.tag.should == '0.0.0'
42
33
  end
34
+
43
35
  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'
36
+ @test_module::VERSION.build_flag = 'pre'
37
+ @test_module::VERSION.tag_format = @test_module::VERSION.tag_format + "--%<build_flag>s"
38
+ @test_module::VERSION.tag.should == '0.0.0--pre'
47
39
  end
48
40
 
49
41
  it "can bump a segment" do
50
- TestFile::VERSION.bump(:patch)
51
- TestFile::VERSION.tag.should == '0.0.1'
42
+ @test_module::VERSION.bump(:patch)
43
+ @test_module::VERSION.tag.should == '0.0.1'
52
44
  end
53
45
 
54
46
  it "bump a segment reset sublevels " do
55
- TestFile::VERSION.bump(:patch)
56
- TestFile::VERSION.bump(:minor)
57
- TestFile::VERSION.tag.should == '0.1.0'
58
- end
59
-
60
- it "can save " do
61
- io = StringIO.new
62
- File.stub!(:open).and_yield(io)
63
- TestFile::VERSION.bump(:minor)
64
- TestFile::VERSION.save
65
- if RUBY_PATCHLEVEL >= 290 # asume ruby 1.9.2
66
- io.string.should == "---\nmajor: 0\nminor: 1\npatch: 0\n"
67
- else
68
- io.string.should == "--- \nmajor: 0\nminor: 1\npatch: 0\n"
69
- end
70
- end
71
-
72
- it "can save custom data " do
73
- io = StringIO.new
74
- File.stub!(:open).and_yield(io)
75
- TestFile::VERSION.bump(:minor)
76
- TestFile::VERSION.author = 'jcangas'
77
- TestFile::VERSION.save
78
- if RUBY_PATCHLEVEL >= 290 # asume ruby 1.9.2
79
- io.string.should == "---\nmajor: 0\nminor: 1\npatch: 0\nauthor: jcangas\n"
80
- else
81
- io.string.should == "--- \nmajor: 0\nminor: 1\npatch: 0\nauthor: jcangas\n"
82
- end
83
- end
84
-
85
- it "can load " do
86
- io = StringIO.new("--- \nmajor: 1\nminor: 2\npatch: 3\n")
87
- File.should_receive(:read).and_return{io}
88
- TestFile::VERSION.load
89
- TestFile::VERSION.marshal_dump.should == {:major => 1, :minor => 2, :patch => 3 }
90
- end
91
-
92
- it "can load custom data " do
93
- io = StringIO.new("--- \nmajor: 1\nminor: 2\npatch: 3\nauthor: jcangas\n")
94
- File.should_receive(:read).and_return{io}
95
- TestFile::VERSION.load
96
- TestFile::VERSION.marshal_dump.should == {:major => 1, :minor => 2, :patch => 3, :author => 'jcangas' }
47
+ @test_module::VERSION.bump(:patch)
48
+ @test_module::VERSION.bump(:minor)
49
+ @test_module::VERSION.tag.should == '0.1.0'
97
50
  end
98
51
 
99
52
  end
@@ -101,28 +54,27 @@ end
101
54
  describe "VersionInfo custom segments" do
102
55
  before :each do
103
56
  VersionInfo.segments = [:a, :b, :c]
104
- module TestFile
105
- include VersionInfo # force new VERSION value
106
- end
57
+ @test_module = Module.new
58
+ @test_module.send :include, VersionInfo
107
59
  end
108
60
 
109
61
  after :each do
110
- module TestFile
111
- remove_const :VERSION
112
- end
62
+ VersionInfo.segments = nil # reset defaults
113
63
  end
114
64
 
115
65
  it "can be assigned" do
116
- TestFile::VERSION.marshal_dump.should == {:a => 0, :b => 0, :c => 0 }
66
+ @test_module::VERSION.to_hash.should == {:a => 0, :b => 0, :c => 0 }
117
67
  end
118
68
 
119
69
  it "segments are properties" do
120
- TestFile::VERSION.a.should == 0
70
+ lambda{@test_module::VERSION.a}.should_not raise_error
121
71
  end
122
72
 
123
73
  it "can bump a custom segment" do
124
- TestFile::VERSION.bump(:c)
125
- TestFile::VERSION.bump(:b)
126
- TestFile::VERSION.tag.should == '0.1.0'
74
+ @test_module::VERSION.bump(:c)
75
+ @test_module::VERSION.bump(:b)
76
+ @test_module::VERSION.tag.should == '0.1.0'
127
77
  end
128
78
  end
79
+
80
+
@@ -0,0 +1,61 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Yaml file format" do
4
+ before :each do
5
+ VersionInfo.file_format = :yaml
6
+ @test_module = Module.new
7
+ @test_module.send :include, VersionInfo
8
+ @test_module::VERSION.file_name = nil
9
+ end
10
+
11
+ it "has default filename" do
12
+ @test_module::VERSION.file_name.should == Dir.pwd + '/' + 'version_info.yml'
13
+ end
14
+
15
+ it "is initalized" do
16
+ @test_module::VERSION.to_hash.should == {:major => 0, :minor => 0, :patch => 0 }
17
+ end
18
+
19
+ it "can save " do
20
+ io = StringIO.new
21
+ File.stub!(:open).and_yield(io)
22
+ @test_module::VERSION.bump(:minor)
23
+ @test_module::VERSION.save
24
+ # Seems like YAML has removed one space in ruby 1.9.2p290
25
+ # TODO: check for ruby 1.9.2
26
+ if RUBY_PATCHLEVEL >= 290
27
+ io.string.should == "---\nmajor: 0\nminor: 1\npatch: 0\n"
28
+ else
29
+ io.string.should == "--- \nmajor: 0\nminor: 1\npatch: 0\n"
30
+ end
31
+ end
32
+
33
+ it "can save custom data " do
34
+ io = StringIO.new
35
+ File.stub!(:open).and_yield(io)
36
+ @test_module::VERSION.bump(:minor)
37
+ @test_module::VERSION.author = 'jcangas'
38
+ @test_module::VERSION.save
39
+ if RUBY_PATCHLEVEL >= 290 # asume ruby 1.9.2
40
+ io.string.should == "---\nmajor: 0\nminor: 1\npatch: 0\nauthor: jcangas\n"
41
+ else
42
+ io.string.should == "--- \nmajor: 0\nminor: 1\npatch: 0\nauthor: jcangas\n"
43
+ end
44
+ end
45
+
46
+ it "can load " do
47
+ io = StringIO.new("--- \nmajor: 1\nminor: 2\npatch: 3\n")
48
+ File.should_receive(:read).and_return{io}
49
+ @test_module::VERSION.load
50
+ @test_module::VERSION.to_hash.should == {:major => 1, :minor => 2, :patch => 3 }
51
+ end
52
+
53
+ it "can load custom data " do
54
+ io = StringIO.new("--- \nmajor: 1\nminor: 2\npatch: 3\nauthor: jcangas\n")
55
+ File.should_receive(:read).and_return{io}
56
+ @test_module::VERSION.load
57
+ @test_module::VERSION.to_hash.should == {:major => 1, :minor => 2, :patch => 3, :author => 'jcangas' }
58
+ end
59
+
60
+ end
61
+
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: version_info
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.1.4
5
+ version: 1.7.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jorge L. Cangas
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-09-05 00:00:00 Z
13
+ date: 2011-09-19 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -76,13 +76,18 @@ files:
76
76
  - autotest/discover.rb
77
77
  - lib/version_info.rb
78
78
  - lib/version_info/data.rb
79
+ - lib/version_info/module_storage.rb
79
80
  - lib/version_info/rake_tasks.rb
81
+ - lib/version_info/text_storage.rb
80
82
  - lib/version_info/thor_tasks.rb
81
83
  - lib/version_info/version.rb
82
- - lib/version_info/version_info.yml
84
+ - lib/version_info/yaml_storage.rb
83
85
  - spec/spec_helper.rb
86
+ - spec/version_info/module_format_spec.rb
84
87
  - spec/version_info/test_file.rb
88
+ - spec/version_info/text_format_spec.rb
85
89
  - spec/version_info/version_info_spec.rb
90
+ - spec/version_info/yaml_format_spec.rb
86
91
  - version_info.gemspec
87
92
  homepage: http://github.com/jcangas/version_info
88
93
  licenses: []
@@ -1,4 +0,0 @@
1
- ---
2
- major: 1
3
- minor: 1
4
- patch: 4