version 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,27 @@
1
+ === Version 0.6.0 / 2010-02-04
2
+
3
+ * bug fixes
4
+ * when autozeroing version components, use strings, not integers
5
+
6
+ * enhancements
7
+ * readme and history files
8
+ * extended documentation
9
+ * support for easy version-file management through rake
10
+ * see rdoc for Rake::VersionTask
11
+ * support auto-setting VERSION constant in classes
12
+ * see rdoc for Class::Versioned()
13
+ * eating own dogfood with Rake::VersionTask
14
+ * make Version#to_hash exclude keys with nil values
15
+
16
+ * todo for 1.0.0
17
+ * full suite of specs
18
+ * remove duplication in Class::Version() and Rake::VersionTask
19
+ * get rid of gem task warnings
20
+
21
+ === Version 0.5.0 / 2010-02-04
22
+
23
+ * initial release
24
+
25
+ * todo for 1.0.0
26
+ * full suite of specs
27
+ * version-bumping rake tasks
@@ -0,0 +1,72 @@
1
+ = Version
2
+
3
+ * http://github.com/stouset/version
4
+ * http://rdoc.info/projects/stouset/version
5
+ * http://getcaliper.com/caliper/project?repo=git%3A%2F%2Fgithub.com%2Fstouset%2Fversion.git
6
+
7
+ == Description
8
+
9
+ Version is a simple wrapper around the concept of version-numbering schemes.
10
+
11
+ == Features
12
+
13
+ * Rake::VersionTask provides tasks for simple version bumping
14
+ * Version smartly handles several versioning schemes, abstracting the details
15
+
16
+ == Examples
17
+
18
+
19
+ === Rake Tasks
20
+
21
+ Version comes with a Rake::VersionTask that lets you manage version numbering
22
+ automatically. Place the following in a Rakefile:
23
+
24
+ require 'rake/version_task'
25
+ Rake::VersionTask.new
26
+
27
+ You're all set up.
28
+
29
+ $ rake version:create VERSION=0.1.0 # => 0.1.0
30
+ $ rake version # => 0.1.0
31
+ $ rake version:bump # => 0.1.1
32
+ $ rake version:bump:minor # => 0.2.0
33
+ $ rake version:bump:revision # => 0.2.1
34
+ $ rake version:bump:major # => 1.0.0
35
+ $ cat VERSION # => 1.0.0
36
+
37
+ Version also supports a .yml VERSION file. See the VersionTask rdoc for
38
+ details.
39
+
40
+ === Library Versioning
41
+
42
+ Version lets you automatically keep an in-class VERSION constant in sync with
43
+ the contents of the version file on disk.
44
+
45
+ require 'version'
46
+
47
+ class Foo
48
+ Version()
49
+ end
50
+
51
+ Foo::VERSION # => 1.0.0
52
+
53
+ The Class::Version method takes a filename parameter if you use a different
54
+ location for the VERSION file. See the Class::Version rdoc for details.
55
+
56
+ === Manipulation in Code
57
+
58
+ All the above functionality is performed behind-the-scenes by the Version
59
+ library. It's simple to use, but I'll be surprised if there's much point
60
+ beyond doing the legwork for the Rake task and class versioning.
61
+
62
+ v = "1.2.0".to_version
63
+ v.to_s # => 1.2.0
64
+ v.bump! # => 1.2.1
65
+ v.bump!(1) # => 1.3.0
66
+ v.bump!(1, true) # => 1.3
67
+ v.major = 2 # => 2.0
68
+ v.to_a # => ['2', '0']
69
+
70
+ == Install
71
+
72
+ [sudo] gem install version
data/Rakefile CHANGED
@@ -1,6 +1,7 @@
1
1
  $: << 'lib'
2
2
 
3
3
  require 'version'
4
+ require 'rake/version_task'
4
5
 
5
6
  require 'rubygems'
6
7
  require 'rake/gempackagetask'
@@ -12,7 +13,7 @@ spec = Gem::Specification.new do |s|
12
13
  s.author = 'Stephen Touset'
13
14
  s.email = 'stephen@touset.org'
14
15
  s.summary = 'simple version-number encapsulation'
15
- s.version = '0.5.0'
16
+ s.version = Version::VERSION
16
17
  s.files = FileList['[A-Z]*', 'lib/**/*.rb', 'spec/**/*']
17
18
 
18
19
  s.add_development_dependency 'rspec'
@@ -23,9 +24,7 @@ Rake::GemPackageTask.new(spec) do |gem|
23
24
  end
24
25
 
25
26
  Rake::RDocTask.new do |doc|
26
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
27
-
28
- doc.title = 'emcien-engine #{version}'
27
+ doc.title = "emcien-engine #{Version::VERSION}"
29
28
  doc.rdoc_dir = 'doc'
30
29
  doc.rdoc_files.include('README*')
31
30
  doc.rdoc_files.include('lib/**/*.rb')
@@ -35,4 +34,6 @@ Spec::Rake::SpecTask.new(:spec) do |spec|
35
34
  spec.spec_files = FileList['spec/**/*_spec.rb']
36
35
  end
37
36
 
37
+ Rake::VersionTask.new
38
+
38
39
  task :default => :spec
@@ -0,0 +1,4 @@
1
+ * fully spec all functionality
2
+ * remove file parsing duplication between Class::Version() and
3
+ Rake::VersionTask
4
+ * get rid of gem task warnings
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.6.0
@@ -0,0 +1,28 @@
1
+ require 'pathname'
2
+
3
+ class Class
4
+ #
5
+ # Automagically sets a VERSION constant in the current class, populated by
6
+ # the Version in +filename+. Attempts to guess the filename if none given.
7
+ # Can read both .yml files and plain text.
8
+ #
9
+ def Version(filename = nil)
10
+ # attempt to guess the filename if none given
11
+ if filename.nil?
12
+ filename = Pathname.new('.').expand_path.ascend do |d|
13
+ break d.join('VERSION') if d.join('VERSION').exist?
14
+ break d.join('VERSION.yml') if d.join('VERSION.yml').exist?
15
+ end
16
+ end
17
+
18
+ raise 'no VERSION or VERSION.yml found' unless filename
19
+
20
+ path = Pathname.new(filename)
21
+ contents = path.read
22
+
23
+ const_set :VERSION, case path.extname
24
+ when '' then contents.strip.to_version
25
+ when '.yml' then YAML::load(contents).to_version
26
+ end
27
+ end
28
+ end
@@ -1,2 +1,98 @@
1
- require 'rake'
1
+ require 'rake/tasklib'
2
+ require 'pathname'
2
3
 
4
+ class Rake::VersionTask < Rake::TaskLib
5
+ attr_accessor :filename
6
+ attr_writer :filetype
7
+
8
+ #
9
+ # Creates a new VersionTask with the given +filename+. Attempts to
10
+ # autodetect the +filetype+.
11
+ #
12
+ def initialize(filename = 'VERSION')
13
+ self.filename = filename
14
+
15
+ yield(self) if block_given?
16
+
17
+ self.define
18
+ end
19
+
20
+ #
21
+ # The +filetype+ of the file to be generated. Is determined automatically
22
+ # if not set.
23
+ #
24
+ def filetype
25
+ @filetype || self.path.extname[1..-1]
26
+ end
27
+
28
+ protected
29
+
30
+ #
31
+ # The path for the +filename+.
32
+ #
33
+ def path
34
+ Pathname.new(self.filename)
35
+ end
36
+
37
+ #
38
+ # Defines the rake tasks.
39
+ #
40
+ def define
41
+ fail 'Filename required' if self.filename.nil?
42
+
43
+ file filename
44
+
45
+ desc 'Print the current version number'
46
+ task(:version => filename) { puts read }
47
+
48
+ namespace :version do
49
+ desc 'Creates a version file with an optional VERSION parameter'
50
+ task(:create ) do
51
+ version = (ENV['VERSION'] || '0.0.0').to_version
52
+ puts write(version)
53
+ end
54
+
55
+ desc 'Bump the least-significant version number'
56
+ task(:bump => filename) { puts write(read.bump!) }
57
+
58
+ namespace :bump do
59
+ desc 'Bump the major version number'
60
+ task(:major => filename) { puts write(read.bump!(0)) }
61
+
62
+ desc 'Bump the minor version number'
63
+ task(:minor => filename) { puts write(read.bump!(1)) }
64
+
65
+ desc 'Bump the revision number'
66
+ task(:revision => filename) { puts write(read.bump!(2)) }
67
+ end
68
+ end
69
+ end
70
+
71
+ private
72
+
73
+ #
74
+ # Returns the Version contained in the file at +filename+.
75
+ #
76
+ def read
77
+ contents = path.read
78
+
79
+ case filetype.to_s
80
+ when '' then contents.chomp.to_version
81
+ when 'yml' then YAML::load(contents).to_version
82
+ end
83
+ end
84
+
85
+ #
86
+ # Writes out +version+ to the file at +filename+ with the correct format.
87
+ #
88
+ def write(version)
89
+ path.open('w') do |io|
90
+ io << case filetype.to_s
91
+ when '' then version.to_s + "\n"
92
+ when 'yml' then version.to_yaml
93
+ end
94
+ end
95
+
96
+ version
97
+ end
98
+ end
@@ -1,4 +1,5 @@
1
1
  require 'ext/array'
2
+ require 'ext/class'
2
3
  require 'ext/hash'
3
4
  require 'ext/string'
4
5
 
@@ -56,13 +57,13 @@ class Version
56
57
 
57
58
  if index < self.length
58
59
  length = self.length - index
59
- zeroes = Array.new(length, 0)
60
+ zeroes = Array.new(length, '0')
60
61
 
61
62
  self.components[index, length] = zeroes
62
63
  self.components[index] = value
63
64
  else
64
65
  length = index - self.length
65
- zeroes = Array.new(length, 0)
66
+ zeroes = Array.new(length, '0')
66
67
 
67
68
  self.components += zeroes
68
69
  self.components << value
@@ -121,7 +122,8 @@ class Version
121
122
  { :major => self.major,
122
123
  :minor => self.minor,
123
124
  :revision => self.revision,
124
- :rest => self.length > 3 ? self.components.drop(3) : nil }
125
+ :rest => self.length > 3 ? self.components.drop(3) : nil }.
126
+ delete_if {|k,v| v.nil? }
125
127
  end
126
128
 
127
129
  #
@@ -138,6 +140,13 @@ class Version
138
140
  self
139
141
  end
140
142
 
143
+ #
144
+ # Returns a YAML representation of the version number.
145
+ #
146
+ def to_yaml
147
+ YAML::dump(self.to_hash)
148
+ end
149
+
141
150
  #
142
151
  # Aliased from +to_s+.
143
152
  #
@@ -147,3 +156,7 @@ class Version
147
156
 
148
157
  attr_accessor :components
149
158
  end
159
+
160
+ class Version
161
+ Version()
162
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: version
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Touset
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-02-04 00:00:00 -05:00
12
+ date: 2010-02-05 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -31,8 +31,13 @@ extensions: []
31
31
  extra_rdoc_files: []
32
32
 
33
33
  files:
34
+ - History.rdoc
34
35
  - Rakefile
36
+ - README.rdoc
37
+ - TODO.rdoc
38
+ - VERSION
35
39
  - lib/ext/array.rb
40
+ - lib/ext/class.rb
36
41
  - lib/ext/hash.rb
37
42
  - lib/ext/string.rb
38
43
  - lib/rake/version_task.rb