Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Bug fixes & new sync task #15

Closed
wants to merge 9 commits into from

2 participants

Malachi Griffie Stephen Touset
Malachi Griffie
  1. Removed to_version extension
    The to_version extension was causing some strange issues in our rake tasks (and I therefore presumed in others') so in lieu of determining the cause I just removed them.
  2. Added a sync task
    This is run after every version bump, very useful if other files updates or tasks need to occur when the project version in changed.
  3. Misc minor fixes
Stephen Touset
Owner

I will not merge a pull request that makes sweeping, backward-incompatible changes like this all in one go.

If you'd like to make significant changes, please contact me first and discuss your ideas. Or at the very least, submit multiple pull requests with independent changes that can be accepted or rejected individually rather than wholesale.

Stephen Touset stouset closed this April 17, 2012
Malachi Griffie

Hahaha, I really wouldn't categorize these changes as "sweeping" but whatever.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
6  Rakefile
... ...
@@ -1,10 +1,9 @@
1 1
 $: << 'lib'
2 2
 
3  
-require 'rake/version_task'
4  
-
  3
+require 'version/version_task'
5 4
 require 'rubygems'
6 5
 require 'rake/gempackagetask'
7  
-require 'rake/rdoctask'
  6
+require 'rdoc/task'
8 7
 require 'spec/rake/spectask'
9 8
 
10 9
 spec = Gem::Specification.new do |s|
@@ -40,7 +39,6 @@ Spec::Rake::SpecTask.new(:spec) do |task|
40 39
 end
41 40
 
42 41
 Rake::VersionTask.new do |v|
43  
-  v.with_git_tag = true
44 42
   v.with_gemspec = spec
45 43
 end
46 44
 
2  VERSION
... ...
@@ -1 +1 @@
1  
-1.0.0
  1
+1.1.0
21  lib/version.rb
... ...
@@ -1,8 +1,4 @@
1  
-require 'version/ext/array'
2 1
 require 'version/ext/module'
3  
-require 'version/ext/hash'
4  
-require 'version/ext/string'
5  
-
6 2
 require 'pathname'
7 3
 
8 4
 #
@@ -29,8 +25,8 @@ def self.current(path = nil)
29 25
     return nil unless path
30 26
     
31 27
     case path.extname
32  
-      when ''      then path.read.strip.to_version
33  
-      when '.yml'  then YAML::load(path.read).to_version
  28
+      when ''      then Version.to_version(path.read.strip)
  29
+      when '.yml'  then Version.to_version(YAML::load(path.read))
34 30
     end
35 31
   end
36 32
   
@@ -45,6 +41,19 @@ def self.version_file(filename)
45 41
       break d.join('VERSION.yml') if d.join('VERSION.yml').file?
46 42
     end
47 43
   end
  44
+
  45
+  # 
  46
+  # Converts a String, Hash, or Array into a Version instance
  47
+  #
  48
+  def self.to_version(obj)
  49
+    if obj.kind_of? String
  50
+      Version.new *obj.split(%r{\.})
  51
+    elsif obj.kind_of? Hash
  52
+      Version.new *obj.values_at(:major, :minor, :revision, :rest)
  53
+    elsif obj.kind_of? Array
  54
+      Version.new *obj
  55
+    end
  56
+  end
48 57
   
49 58
   #
50 59
   # Creates a new version number, with a +major+ version number, +minor+
10  lib/version/ext/array.rb
... ...
@@ -1,10 +0,0 @@
1  
-require 'version'
2  
-
3  
-class Array
4  
-  #
5  
-  # Converts the Array into a version number.
6  
-  #
7  
-  def to_version
8  
-    Version.new *self
9  
-  end
10  
-end
10  lib/version/ext/hash.rb
... ...
@@ -1,10 +0,0 @@
1  
-require 'version'
2  
-
3  
-class Hash
4  
-  #
5  
-  # Converts the Hash into a version number.
6  
-  #
7  
-  def to_version
8  
-    Version.new *self.values_at(:major, :minor, :revision, :rest)
9  
-  end
10  
-end
10  lib/version/ext/string.rb
... ...
@@ -1,10 +0,0 @@
1  
-require 'version'
2  
-
3  
-class String
4  
-  #
5  
-  # Converts the String into a version number.
6  
-  #
7  
-  def to_version
8  
-    Version.new *self.split(%r{\.})
9  
-  end
10  
-end
132  lib/rake/version_task.rb → lib/version/version_task.rb
... ...
@@ -1,5 +1,4 @@
1 1
 require 'version'
2  
-
3 2
 require 'rake/tasklib'
4 3
 require 'pathname'
5 4
 
@@ -38,82 +37,111 @@ class Rake::VersionTask < Rake::TaskLib
38 37
   #
39 38
   def initialize(filename = 'VERSION')
40 39
     self.filename = filename
41  
-    self.with_git = File.exist?('.git')
42  
-    self.with_hg = File.exist?('.hg')
43  
-    self.with_svn = File.exist?('.svn')
44 40
     
45 41
     yield(self) if block_given?
46 42
     
47  
-    self.define
48  
-  end
49  
-  
50  
-  #
51  
-  # The +filetype+ of the file to be generated. Is determined automatically
52  
-  # if not set.
53  
-  #
54  
-  def filetype
55  
-    @filetype || self.path.extname[1..-1]
56  
-  end
57  
-  
58  
-  def gemspec
59  
-    Pathname("#{with_gemspec.name}.gemspec") if with_gemspec
60  
-  end
61  
-  
62  
-  protected
63  
-  
64  
-  #
65  
-  # The path for the +filename+.
66  
-  #
67  
-  def path
68  
-    Pathname.new(self.filename)
69  
-  end
70  
-  
71  
-  #
72  
-  # Defines the rake tasks.
73  
-  #
74  
-  def define
  43
+    self.with_git = self.with_git && File.exist?('.git')
  44
+    self.with_hg = self.with_hg && File.exist?('.hg')
  45
+    self.with_svn = self.with_svn && File.exist?('.svn')
  46
+
75 47
     fail 'Filename required' if self.filename.nil?
76 48
     
77 49
     file filename
78 50
     
79 51
     desc "Print the current version number (#{read})"
80  
-    task(:version => filename) { puts read }
  52
+    task :version => filename do
  53
+      puts read
  54
+    end
81 55
     
82 56
     namespace :version do
83  
-      desc 'Creates a version file with an optional VERSION parameter'
84  
-      task(:create) do
85  
-        version = (ENV['VERSION'] || '0.0.0').to_version
86  
-        puts write(version)
87  
-      end
88  
-      
  57
+
  58
+      #add to this task to perform some operation post-bump
  59
+      @sync = task :sync
  60
+
89 61
       desc "Bump to #{read.bump!}"
90  
-      task(:bump => filename) { puts write(read.bump!) }
  62
+      task :bump => filename do |t|
  63
+        puts write(read.bump!)
  64
+        @sync.execute()
  65
+      end
91 66
       
92 67
       namespace :bump do
  68
+
93 69
         desc "Bump to #{read.bump!(:major)}"
94  
-        task(:major => filename) { puts write(read.bump!(:major)) }
  70
+        task :major => filename do
  71
+          puts write(read.bump!(:major))
  72
+          @sync.execute()
  73
+        end
95 74
         
96 75
         desc "Bump to #{read.bump!(:minor)}"
97  
-        task(:minor => filename) { puts write(read.bump!(:minor)) }
  76
+        task :minor => filename do
  77
+          puts write(read.bump!(:minor))
  78
+          @sync.execute()
  79
+        end
98 80
         
99 81
         desc "Bump to #{read.bump!(:revision)}"
100  
-        task(:revision => filename) { puts write(read.bump!(:revision)) }
  82
+        task :revision => filename do
  83
+          puts write(read.bump!(:revision))
  84
+          @sync.execute()
  85
+        end
101 86
         
102 87
         desc "Bump to #{read.bump!(:pre)}"
103  
-        task(:pre => filename) { puts write(read.bump!(:pre)) }
  88
+        task :pre => filename do
  89
+          puts write(read.bump!(:pre))
  90
+          @sync.execute()
  91
+        end
104 92
         
105 93
         namespace :pre do
  94
+          
106 95
           desc "Bump to #{read.bump!(:major, true)}"
107  
-          task(:major => filename) { puts write(read.bump!(:major, true)) }
  96
+          task :major => filename do
  97
+            puts write(read.bump!(:major, true))
  98
+            @sync.execute()
  99
+          end
108 100
           
109 101
           desc "Bump to #{read.bump!(:minor, true)}"
110  
-          task(:minor => filename) { puts write(read.bump!(:minor, true)) }
  102
+          task :minor => filename do |t|
  103
+            puts write(read.bump!(:minor, true))
  104
+            @sync.execute()
  105
+          end
111 106
           
112 107
           desc "Bump to #{read.bump!(:revision, true)}"
113  
-          task(:revision => filename) { puts write(read.bump!(:revision, true)) }
114  
-        end
  108
+          task :revision => filename do
  109
+            puts write(read.bump!(:revision, true))
  110
+            @sync.execute()
  111
+          end
  112
+
  113
+        end#namespace :pre do
  114
+      end#namespace :bump do
  115
+
  116
+      desc 'Creates a version file with an optional VERSION parameter'
  117
+      task :create do
  118
+        version = Version.to_version(ENV['VERSION'] || '0.0.0')
  119
+        puts write(version)
115 120
       end
116  
-    end
  121
+
  122
+    end#namespace :version do
  123
+
  124
+  end
  125
+  
  126
+  #
  127
+  # The +filetype+ of the file to be generated. Is determined automatically
  128
+  # if not set.
  129
+  #
  130
+  def filetype
  131
+    @filetype || self.path.extname[1..-1]
  132
+  end
  133
+  
  134
+  def gemspec
  135
+    Pathname("#{with_gemspec.name}.gemspec") if with_gemspec
  136
+  end
  137
+  
  138
+  protected
  139
+  
  140
+  #
  141
+  # The path for the +filename+.
  142
+  #
  143
+  def path
  144
+    Pathname.new(self.filename)
117 145
   end
118 146
   
119 147
   private
@@ -125,8 +153,8 @@ def read
125 153
     contents = path.read rescue '0.0.0'
126 154
     
127 155
     case filetype.to_s
128  
-      when ''    then contents.chomp.to_version
129  
-      when 'yml' then YAML::load(contents).to_version
  156
+      when ''    then Version.to_version(contents.chomp)
  157
+      when 'yml' then Version.to_version(YAML::load(contents))
130 158
     end
131 159
   end
132 160
   
@@ -134,7 +162,7 @@ def read
134 162
   # Writes out +version+ to the file at +filename+ with the correct format.
135 163
   #
136 164
   def write(version)
137  
-    return if version == read
  165
+    return if path.exist? && version == read
138 166
     
139 167
     path.open('w') do |io|
140 168
       io << case filetype.to_s
16  version.gemspec
... ...
@@ -1,19 +1,19 @@
1 1
 # -*- encoding: utf-8 -*-
2 2
 
3 3
 Gem::Specification.new do |s|
4  
-  s.name = %q{version}
5  
-  s.version = "1.0.0"
  4
+  s.name = "version"
  5
+  s.version = "1.1.0"
6 6
 
7  
-  s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
  7
+  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8 8
   s.authors = ["Stephen Touset"]
9  
-  s.date = %q{2011-05-10}
10  
-  s.email = %q{stephen@touset.org}
  9
+  s.date = "2012-03-08"
  10
+  s.email = "stephen@touset.org"
11 11
   s.extra_rdoc_files = ["History.rdoc", "README.rdoc", "TODO.rdoc"]
12  
-  s.files = ["History.rdoc", "License.txt", "Rakefile", "README.rdoc", "TODO.rdoc", "VERSION", "lib/rake/version_task.rb", "lib/version/component.rb", "lib/version/ext/array.rb", "lib/version/ext/hash.rb", "lib/version/ext/module.rb", "lib/version/ext/string.rb", "lib/version.rb", "spec/spec.opts", "spec/spec_helper.rb", "spec/version_spec.rb"]
  12
+  s.files = ["History.rdoc", "lib", "License.txt", "Rakefile", "README.rdoc", "spec", "TODO.rdoc", "VERSION", "version.gemspec", "lib/version/component.rb", "lib/version/ext/module.rb", "lib/version/version_task.rb", "lib/version.rb", "spec/spec.opts", "spec/spec_helper.rb", "spec/version_spec.rb"]
13 13
   s.rdoc_options = ["--main", "README.rdoc"]
14 14
   s.require_paths = ["lib"]
15  
-  s.rubygems_version = %q{1.6.2}
16  
-  s.summary = %q{simple version-number encapsulation}
  15
+  s.rubygems_version = "1.8.11"
  16
+  s.summary = "simple version-number encapsulation"
17 17
 
18 18
   if s.respond_to? :specification_version then
19 19
     s.specification_version = 3
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.