version_info 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -48,5 +48,26 @@ Also you can bump any segment. With the same sample:
48
48
 
49
49
  => 1.0.0
50
50
 
51
- Note the other segments are reset to 0 after bump.
52
-
51
+ Note the other (lower) segments are reset to 0 after bump.
52
+
53
+
54
+ ### Rake tasks
55
+
56
+ Put in your rake file:
57
+
58
+ VersionInfo::Tasks.install
59
+
60
+ And you get a few tasks within namespace vinfo:
61
+
62
+ rake -T
63
+ =>
64
+ rake build # Build version_info-0.4.0.gem into the pkg directory
65
+ rake install # Build and install version_info-0.4.0.gem into system gems
66
+ rake release # Create tag v0.4.0 and build and push version_info-0.4.0.gem to Rubygems
67
+ rake vinfo:build # Bumps version segment BUILD
68
+ rake vinfo:major # Bumps version segment MAJOR
69
+ rake vinfo:minor # Bumps version segment MINOR
70
+ rake vinfo:patch # Bumps version segment PATCH
71
+ rake vinfo:pre # Bumps version segment PRE
72
+ rake vinfo:show # Show current version tag and create version_info.yml if missing
73
+
data/Rakefile CHANGED
@@ -1,4 +1,13 @@
1
1
  require 'bundler'
2
2
 
3
+ # Use vinfo tasks onto it self
4
+
5
+ $LOAD_PATH.unshift File.expand_path('./lib', File.dirname(__FILE__))
6
+
7
+ require 'version_info'
8
+ require 'version_info/version'
9
+
10
+ VersionInfo::Tasks.install
11
+ # now we have VersionInfo::VERSION defined, can load this
3
12
  Bundler::GemHelper.install_tasks
4
13
 
@@ -1,21 +1,24 @@
1
1
  require 'ostruct'
2
+ require 'yaml'
3
+
2
4
  module VersionInfo
3
5
  class Data < OpenStruct
4
- attr_accessor :file_name
6
+ class << self
7
+ attr_accessor :file_name
8
+ def file_name
9
+ @file_name ||= Dir.pwd + '/' + underscore(self.name) + '_info.yml'
10
+ end
11
+ end
5
12
 
6
13
  def initialize
7
14
  super
8
- if File.exist?(file_name)
15
+ if File.exist?(self.class.file_name)
9
16
  load
10
17
  else
11
18
  marshal_load(get_defaults)
12
19
  end
13
20
  end
14
21
 
15
- def file_name
16
- @file_name ||= 'version_info.yml'
17
- end
18
-
19
22
  def bump(key)
20
23
  idx = VersionInfo.segments.index(key.to_sym) + 1
21
24
  return unless idx
@@ -26,15 +29,19 @@ module VersionInfo
26
29
  end
27
30
 
28
31
  def load
29
- load_from(File.read(file_name))
32
+ load_from(File.read(self.class.file_name))
30
33
  self
31
34
  end
32
35
 
33
36
  def save
34
- File.open( file_name, 'w' ) {|out| save_to(out)}
37
+ File.open(self.class.file_name, 'w' ) {|out| save_to(out)}
35
38
  self
36
39
  end
37
40
 
41
+ def to_s
42
+ tag
43
+ end
44
+
38
45
  def tag
39
46
  VersionInfo.segments.map { |k| send(k) }.compact.join('.')
40
47
  end
@@ -53,8 +60,18 @@ module VersionInfo
53
60
 
54
61
  def save_to(io)
55
62
  values = self.marshal_dump.keys.compact.inject({}){|r, k| r[k.to_s] = send(k); r }
56
- YAML.dump(values, io )
63
+ YAML.dump(values, io)
57
64
  self
58
65
  end
66
+
67
+ def self.underscore(camel_cased_word)
68
+ word = camel_cased_word.to_s.dup
69
+ word.gsub!(/::/, '/')
70
+ word.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
71
+ word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
72
+ word.tr!("-", "_")
73
+ word.downcase!
74
+ word
75
+ end
59
76
  end
60
77
  end
@@ -1,18 +1,34 @@
1
1
  module VersionInfo
2
2
  class Tasks
3
3
  def self.install(opts = nil)
4
- dir = caller.find{|c| /Rakefile:/}[/^(.*?)\/Rakefile:/, 1]
5
- self.new(dir, opts && opts[:name]).install
4
+ #dir = caller.find{|c| /Rakefile:/}[/^(.*?)\/Rakefile:/, 1]
5
+ dir = File.dirname(Rake.application.rakefile_location)
6
+ self.new(dir).install
6
7
  end
7
8
 
9
+ attr_reader :root_path
10
+
11
+ def initialize(root_path)
12
+ @root_path = root_path
13
+ end
14
+
8
15
  def install
9
16
  namespace :vinfo do
10
- desc "bump SEGMENT , Bumps a version info segment ('major','minor','patch','state','build')"
11
- task 'bump' do
12
- puts "Wow!"
17
+ desc "Show current version tag and create version_info.yml if missing"
18
+ task :show do
19
+ puts VERSION.tag
20
+ VERSION.save unless File.exist?(VERSION.class.file_name)
21
+ end
22
+
23
+ VersionInfo.segments.each do |sgm|
24
+ desc "Bumps version segment #{sgm.upcase}"
25
+ task sgm.to_sym do
26
+ VERSION.bump(sgm)
27
+ puts "version changed to #{VERSION.tag}"
28
+ VERSION.save
29
+ end
13
30
  end
14
31
  end
15
32
  end
16
-
17
33
  end
18
34
  end
@@ -1,3 +1,7 @@
1
1
  module VersionInfo
2
- VERSION = "0.3.0"
2
+ Version = Class.new(Data)
3
+ Version.file_name = 'lib/version_info/version_info.yml'
4
+
5
+ VERSION = Version.new
3
6
  end
7
+
@@ -0,0 +1,4 @@
1
+ ---
2
+ major: 0
3
+ minor: 4
4
+ patch: 0
data/lib/version_info.rb CHANGED
@@ -7,8 +7,10 @@ module VersionInfo
7
7
  [:major, :minor, :patch, :pre, :build]
8
8
  end
9
9
 
10
- def self.included(other)
11
- other.const_set('VERSION', Data.new)
10
+ def self.included(other)
11
+ data = Class.new(Data)
12
+ other.const_set('Version', data)
13
+ other.const_set('VERSION', data.new)
12
14
  end
13
15
 
14
16
  autoload :Tasks, 'version_info/tasks'
@@ -14,7 +14,7 @@ describe "VersionInfo" do
14
14
  end
15
15
 
16
16
  it "has default filename" do
17
- TestFile::VERSION.file_name.should == 'version_info.yml'
17
+ TestFile::Version.file_name.should == Dir.pwd + '/test_file/version_info.yml'
18
18
  end
19
19
 
20
20
  it "can assign filename" do
data/version_info.gemspec CHANGED
@@ -1,5 +1,6 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  $:.push File.expand_path("../lib", __FILE__)
3
+ require "version_info"
3
4
  require "version_info/version"
4
5
 
5
6
  Gem::Specification.new do |s|
@@ -9,7 +10,7 @@ Gem::Specification.new do |s|
9
10
  s.authors = ["Jorge L. Cangas"]
10
11
  s.email = ["jorge.cangas@gmail.com"]
11
12
  s.homepage = "http://github.com/jcangas/version_info"
12
- s.summary = %q{A Ruby gem to manage your project version data}
13
+ s.summary = %q{A Ruby gem to manage your project version data. Rake tasks included!}
13
14
  s.description = %q{Easy way to get version label, bump the segments (major, minor, patch), and you can include custom version data}
14
15
 
15
16
  s.rubyforge_project = "version_info"
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 3
7
+ - 4
8
8
  - 0
9
- version: 0.3.0
9
+ version: 0.4.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Jorge L. Cangas
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-12-31 00:00:00 +01:00
17
+ date: 2011-01-04 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -63,6 +63,7 @@ files:
63
63
  - lib/version_info/data.rb
64
64
  - lib/version_info/tasks.rb
65
65
  - lib/version_info/version.rb
66
+ - lib/version_info/version_info.yml
66
67
  - spec/spec_helper.rb
67
68
  - spec/version_info/test_file.rb
68
69
  - spec/version_info/version_info_spec.rb
@@ -98,6 +99,6 @@ rubyforge_project: version_info
98
99
  rubygems_version: 1.3.7
99
100
  signing_key:
100
101
  specification_version: 3
101
- summary: A Ruby gem to manage your project version data
102
+ summary: A Ruby gem to manage your project version data. Rake tasks included!
102
103
  test_files: []
103
104