Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Changes for 0.1.2

  • Loading branch information...
commit 7ce555bd671f837c541e1126dc4b4e706c30b139 1 parent b882c4e
@dazuma authored
View
5 History.rdoc
@@ -1,3 +1,8 @@
+=== 0.1.2 / 2009-10-28
+
+* You can now specify fields by index in methods of Versionomy::Value.
+* Minor rakefile and documentation updates.
+
=== 0.1.1 / 2009-10-19
* Formats can now be specified by name in the convenience interface.
View
9 Rakefile
@@ -33,6 +33,7 @@
# -----------------------------------------------------------------------------
+require 'rubygems'
require 'rake'
require 'rake/clean'
require 'rake/gempackagetask'
@@ -88,7 +89,7 @@ gemspec_ = Gem::Specification.new do |s_|
s_.has_rdoc = true
s_.test_files = FileList['tests/tc_*.rb']
s_.platform = Gem::Platform::RUBY
- s_.add_dependency('blockenspiel', '>= 0.2.1')
+ s_.add_dependency('blockenspiel', '>= 0.2.2')
end
Rake::GemPackageTask.new(gemspec_) do |task_|
task_.need_zip = false
@@ -106,7 +107,7 @@ end
# Publish gem
-task :publish_gem_to_rubyforge => [:package] do |t_|
+task :release_gem_to_rubyforge => [:package] do |t_|
v_ = ENV["VERSION"]
abort "Must supply VERSION=x.y.z" unless v_
if v_ != Versionomy::VERSION_STRING
@@ -131,7 +132,7 @@ end
# Publish gem
-task :publish_gem_to_gemcutter => [:package] do |t_|
+task :release_gem_to_gemcutter => [:package] do |t_|
v_ = ENV["VERSION"]
abort "Must supply VERSION=x.y.z" unless v_
if v_ != Versionomy::VERSION_STRING
@@ -143,4 +144,4 @@ end
# Publish everything
-task :publish => [:publish_gem_to_gemcutter, :publish_gem_to_rubyforge, :publish_rdoc_to_rubyforge]
+task :release => [:release_gem_to_gemcutter, :release_gem_to_rubyforge, :publish_rdoc_to_rubyforge]
View
4 lib/versionomy.rb
@@ -36,13 +36,13 @@
begin
require 'blockenspiel'
-rescue LoadError
+rescue ::LoadError
require 'rubygems'
require 'blockenspiel'
end
-dir_ = File.expand_path('versionomy', File.dirname(__FILE__))
+dir_ = ::File.expand_path('versionomy', ::File.dirname(__FILE__))
includes_ = [
'errors',
View
4 lib/versionomy/format.rb
@@ -1,6 +1,6 @@
# -----------------------------------------------------------------------------
#
-# Versionomy format module
+# Versionomy format namespace
#
# -----------------------------------------------------------------------------
# Copyright 2008-2009 Daniel Azuma
@@ -49,7 +49,7 @@ module Versionomy
#
# Under many circumstances, you should use the standard format, which
# can be retrieved by calling Versionomy::Formats#standard. This format
- # understands most of the common version numbers, including prerelease
+ # understands most common version numbers, including prerelease
# (e.g. alpha, beta, release candidate, etc.) forms and patchlevels.
#
# You may also create your own formats, either by implementing the
View
2  lib/versionomy/formats.rb
@@ -1,6 +1,6 @@
# -----------------------------------------------------------------------------
#
-# Versionomy format module
+# Versionomy format registry
#
# -----------------------------------------------------------------------------
# Copyright 2008-2009 Daniel Azuma
View
2  lib/versionomy/formats/standard.rb
@@ -1,6 +1,6 @@
# -----------------------------------------------------------------------------
#
-# Versionomy format registry
+# Versionomy standard format implementation
#
# -----------------------------------------------------------------------------
# Copyright 2008-2009 Daniel Azuma
View
4 lib/versionomy/schema.rb
@@ -1,6 +1,6 @@
# -----------------------------------------------------------------------------
#
-# Versionomy schema module
+# Versionomy schema namespace
#
# -----------------------------------------------------------------------------
# Copyright 2008-2009 Daniel Azuma
@@ -83,7 +83,7 @@ module Versionomy
# The Versionomy::Schema::Wrapper class represents a full schema object.
#
# Generally, you should create schemas using Versionomy::Schema#create.
- # This method provides a DSL that lets you quickly create the fields.
+ # That method provides a DSL that lets you quickly create the fields.
module Schema
end
View
20 lib/versionomy/value.rb
@@ -165,12 +165,14 @@ def field_names
# Returns true if this value contains the given field, which may be specified
- # as a field object or name.
+ # as a field object, name, or index.
def has_field?(field_)
case field_
when Schema::Field
@field_path.include?(field_)
+ when ::Integer
+ @field_path.size > field_ && field_ >= 0
when ::String, ::Symbol
@values.has_key?(field_.to_sym)
else
@@ -179,12 +181,14 @@ def has_field?(field_)
end
- # Returns the value of the given field, or nil if the field is not recognized.
- # The field may be specified as a field object or field name.
+ # Returns the value of the given field, or nil if the field is not
+ # recognized. The field may be specified as a field object, field name,
+ # or field index.
def [](field_)
+ field_ = @field_path[field_] if field_.kind_of?(::Integer)
field_ = field_.name if field_.kind_of?(Schema::Field)
- @values[field_.to_sym]
+ field_ ? @values[field_.to_sym] : nil
end
@@ -202,11 +206,17 @@ def values_hash
end
- # Returns a new version number created by bumping the given field.
+ # Returns a new version number created by bumping the given field. The
+ # field may be specified as a field object, field name, or field index.
+ # Returns self if value could not be changed.
+ # Returns nil if the field was not recognized.
def bump(name_)
+ name_ = @field_path[name_] if name_.kind_of?(::Integer)
name_ = name_.name if name_.kind_of?(Schema::Field)
+ return nil unless name_
name_ = name_.to_sym
+ return nil unless @values.include?(name_)
values_ = []
@field_path.each do |field_|
oldval_ = @values[field_.name]
View
2  lib/versionomy/version.rb
@@ -37,7 +37,7 @@
module Versionomy
# Current gem version, as a frozen string.
- VERSION_STRING = '0.1.1'.freeze
+ VERSION_STRING = '0.1.2'.freeze
# Current gem version, as a Versionomy::Value.
VERSION = ::Versionomy.parse(VERSION_STRING, :standard)
View
28 tests/tc_standard_basic.rb
@@ -141,6 +141,34 @@ def test_beta_value
end
+ # Test specifying fields by index.
+
+ def test_field_get_index
+ value_ = Versionomy.create(:major => 2, :tiny => 1, :release_type => :beta, :beta_version => 3)
+ assert_equal(2, value_[0])
+ assert_equal(0, value_[1])
+ assert_equal(1, value_[2])
+ assert_equal(0, value_[3])
+ assert_equal(:beta, value_[4])
+ assert_equal(3, value_[5])
+ assert_equal(0, value_[6])
+ end
+
+
+ # Test specifying fields by name.
+
+ def test_field_get_name
+ value_ = Versionomy.create(:major => 2, :tiny => 1, :release_type => :beta, :beta_version => 3)
+ assert_equal(2, value_[:major])
+ assert_equal(0, value_[:minor])
+ assert_equal(1, value_[:tiny])
+ assert_equal(0, value_[:tiny2])
+ assert_equal(:beta, value_[:release_type])
+ assert_equal(3, value_[:beta_version])
+ assert_equal(0, value_[:beta_minor])
+ end
+
+
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.