Skip to content

Commit

Permalink
Changes for 0.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
dazuma committed Oct 28, 2009
1 parent b882c4e commit 7ce555b
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 18 deletions.
5 changes: 5 additions & 0 deletions 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.
Expand Down
9 changes: 5 additions & 4 deletions Rakefile
Expand Up @@ -33,6 +33,7 @@
# -----------------------------------------------------------------------------


require 'rubygems'
require 'rake'
require 'rake/clean'
require 'rake/gempackagetask'
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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]
4 changes: 2 additions & 2 deletions lib/versionomy.rb
Expand Up @@ -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',
Expand Down
4 changes: 2 additions & 2 deletions lib/versionomy/format.rb
@@ -1,6 +1,6 @@
# -----------------------------------------------------------------------------
#
# Versionomy format module
# Versionomy format namespace
#
# -----------------------------------------------------------------------------
# Copyright 2008-2009 Daniel Azuma
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/versionomy/formats.rb
@@ -1,6 +1,6 @@
# -----------------------------------------------------------------------------
#
# Versionomy format module
# Versionomy format registry
#
# -----------------------------------------------------------------------------
# Copyright 2008-2009 Daniel Azuma
Expand Down
2 changes: 1 addition & 1 deletion lib/versionomy/formats/standard.rb
@@ -1,6 +1,6 @@
# -----------------------------------------------------------------------------
#
# Versionomy format registry
# Versionomy standard format implementation
#
# -----------------------------------------------------------------------------
# Copyright 2008-2009 Daniel Azuma
Expand Down
4 changes: 2 additions & 2 deletions lib/versionomy/schema.rb
@@ -1,6 +1,6 @@
# -----------------------------------------------------------------------------
#
# Versionomy schema module
# Versionomy schema namespace
#
# -----------------------------------------------------------------------------
# Copyright 2008-2009 Daniel Azuma
Expand Down Expand Up @@ -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
Expand Down
20 changes: 15 additions & 5 deletions lib/versionomy/value.rb
Expand Up @@ -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
Expand All @@ -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


Expand All @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion lib/versionomy/version.rb
Expand Up @@ -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)
Expand Down
28 changes: 28 additions & 0 deletions tests/tc_standard_basic.rb
Expand Up @@ -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
Expand Down

0 comments on commit 7ce555b

Please sign in to comment.