version 0.7.1 → 0.8.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.
@@ -1,3 +1,13 @@
1
+ === Version 0.8.0 / (unreleased)
2
+
3
+ * bug fixes
4
+ * fixed README documentation to properly reflect is_versioned
5
+ * put core class extensions in a subdirectory of version, to avoid filename
6
+ collisions with other gems
7
+
8
+ * enhancements
9
+ * Added Version.current method (closes #2)
10
+
1
11
  === Version 0.7.1 / 2010-02-05
2
12
 
3
13
  * bug fixes
@@ -32,7 +32,8 @@ You're all set up.
32
32
  $ rake version:bump:minor # => 0.2.0
33
33
  $ rake version:bump:revision # => 0.2.1
34
34
  $ rake version:bump:major # => 1.0.0
35
- $ cat VERSION # => 1.0.0
35
+ $ rake version:bump:minor # => 1.0.1
36
+ $ cat VERSION # => 1.0.1
36
37
 
37
38
  Version also supports a .yml VERSION file. See the VersionTask rdoc for
38
39
  details.
@@ -40,15 +41,19 @@ details.
40
41
  === Library Versioning
41
42
 
42
43
  Version lets you automatically keep an in-class VERSION constant in sync with
43
- the contents of the version file on disk.
44
+ the contents of the version file on disk. Version also provides a class-level
45
+ +current+ method which lets you get the current version without setting a
46
+ class-level constant.
44
47
 
45
48
  require 'version'
46
49
 
50
+ Version.current # => 1.0.1
51
+
47
52
  class Foo
48
- Version()
53
+ is_versioned
49
54
  end
50
55
 
51
- Foo::VERSION # => 1.0.0
56
+ Foo::VERSION # => 1.0.1
52
57
 
53
58
  The Class::Version method takes a filename parameter if you use a different
54
59
  location for the VERSION file. See the Class::Version rdoc for details.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.1
1
+ 0.8.0
@@ -1,7 +1,9 @@
1
- require 'ext/array'
2
- require 'ext/class'
3
- require 'ext/hash'
4
- require 'ext/string'
1
+ require 'version/ext/array'
2
+ require 'version/ext/class'
3
+ require 'version/ext/hash'
4
+ require 'version/ext/string'
5
+
6
+ require 'pathname'
5
7
 
6
8
  #
7
9
  # Encodes version-numbering logic into a convenient class.
@@ -9,6 +11,39 @@ require 'ext/string'
9
11
  class Version
10
12
  include Comparable
11
13
 
14
+ #
15
+ # Searches through the parent directories of the calling method and looks
16
+ # for a VERSION or VERSION.yml file to parse out the current version. Pass
17
+ #
18
+ # Pass a filename to +path+ to override autodetection, or pass a directory
19
+ # name as +path+ to autodetect within a given directory
20
+ #
21
+ def self.current(path = nil)
22
+ # if path is nil, detect automatically; if path is a directory, detect
23
+ # automatically in the directory; if path is a filename, use it directly
24
+ path = path ? Pathname.new(path) : self.version_file(caller.first)
25
+ path = self.version_file(path) unless path.file?
26
+
27
+ raise 'no VERSION or VERSION.yml found' unless path
28
+
29
+ case path.extname
30
+ when '' then path.read.strip.to_version
31
+ when '.yml' then YAML::load(path.read).to_version
32
+ end
33
+ end
34
+
35
+ #
36
+ # Attempts to detect the version file for the passed +filename+. Looks up
37
+ # the directory hierarchy for a file named VERSION or VERSION.yml. Returns
38
+ # a Pathname for the file if found, otherwise nil.
39
+ #
40
+ def self.version_file(filename)
41
+ Pathname(filename).dirname.expand_path.ascend do |d|
42
+ break d.join('VERSION') if d.join('VERSION').exist?
43
+ break d.join('VERSION.yml') if d.join('VERSION.yml').exist?
44
+ end
45
+ end
46
+
12
47
  #
13
48
  # Creates a new version number, with a +major+ version number, +minor+
14
49
  # revision number, +revision+ number, and optionally more (unnamed)
@@ -1,3 +1,5 @@
1
+ require 'version'
2
+
1
3
  class Array
2
4
  #
3
5
  # Converts the Array into a version number.
@@ -0,0 +1,11 @@
1
+ require 'version'
2
+
3
+ class Class
4
+ #
5
+ # Automagically sets a VERSION constant in the current class according to
6
+ # the results of Version.current.
7
+ #
8
+ def is_versioned
9
+ const_set :VERSION, Version.current(File.dirname(caller.first))
10
+ end
11
+ end
@@ -1,3 +1,5 @@
1
+ require 'version'
2
+
1
3
  class Hash
2
4
  #
3
5
  # Converts the Hash into a version number.
@@ -1,3 +1,5 @@
1
+ require 'version'
2
+
1
3
  class String
2
4
  #
3
5
  # Converts the String into a version number.
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.7.1
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Touset
@@ -36,11 +36,11 @@ files:
36
36
  - README.rdoc
37
37
  - TODO.rdoc
38
38
  - VERSION
39
- - lib/ext/array.rb
40
- - lib/ext/class.rb
41
- - lib/ext/hash.rb
42
- - lib/ext/string.rb
43
39
  - lib/rake/version_task.rb
40
+ - lib/version/ext/array.rb
41
+ - lib/version/ext/class.rb
42
+ - lib/version/ext/hash.rb
43
+ - lib/version/ext/string.rb
44
44
  - lib/version.rb
45
45
  - spec/spec.opts
46
46
  - spec/spec_helper.rb
@@ -1,29 +0,0 @@
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 of the VERSION
7
- # file by looking for VERSION or VERSION.yml files in the directories above
8
- # the caller
9
- #
10
- def is_versioned(filename = nil)
11
- # attempt to guess the filename if none given
12
- if filename.nil?
13
- filename = Pathname.new(caller.first).dirname.expand_path.ascend do |d|
14
- break d.join('VERSION') if d.join('VERSION').exist?
15
- break d.join('VERSION.yml') if d.join('VERSION.yml').exist?
16
- end
17
- end
18
-
19
- raise 'no VERSION or VERSION.yml found' unless filename
20
-
21
- path = Pathname.new(filename)
22
- contents = path.read
23
-
24
- const_set :VERSION, case path.extname
25
- when '' then contents.strip.to_version
26
- when '.yml' then YAML::load(contents).to_version
27
- end
28
- end
29
- end