Permalink
Browse files

A few more fixes and doc updates

  • Loading branch information...
1 parent 014f6c9 commit b59f4d979b5b18c27e4896a9d4bb19395d73dfbf @dazuma committed Nov 5, 2009
View
@@ -10,7 +10,7 @@
* Schemas can now add custom methods to value objects. Added "prerelease?" and "release" methods to rubygems and standard format values.
* Added default field settings to schema DSL.
* Implemented #=== for schemas and formats.
-* Many minor bug fixes.
+* Many minor bug fixes and documentation updates.
=== 0.1.3 / 2009-10-29
@@ -43,16 +43,19 @@ module Conversion
# The base conversion class.
#
# This base class defines the API for a conversion. All conversions must
- # define the method <tt>convert_value</tt>. Actual objects need not
- # extend this base class, as long as they duck-type this method.
+ # define the method <tt>convert_value</tt> documented here. Conversions
+ # need not actually extend this base class, as long as they duck-type
+ # this method. However, this base class does provide a few convenience
+ # methods such as a sane implementation of inspect.
class Base
- # Returns a value equivalent to the given value in the given format.
+ # Convert the given value to the given format and return the converted
+ # value.
#
- # The convert_params may be interpreted differently for different
- # conversion implementations.
+ # The convert_params may be interpreted however the particular
+ # conversion wishes.
#
# Raises Versionomy::Errors::ConversionError if the conversion failed.
@@ -61,11 +64,16 @@ def convert_value(value_, format_, convert_params_=nil)
end
- def inspect # :nodoc:
+ # Inspect this conversion.
+
+ def inspect
"#<#{self.class}:0x#{object_id.to_s(16)}>"
end
- def to_s # :nodoc:
+
+ # The default to_s implementation just calls inspect.
+
+ def to_s
inspect
end
@@ -44,7 +44,7 @@ module Conversion
# Essentially, it unparses the value and then attempts to parse it with
# the new format.
- class Parsing
+ class Parsing < Base
# Create a parsing conversion.
@@ -53,7 +53,7 @@ class Parsing
# parse settings. In some cases, this may be enough, but you may
# wish to improve the reliability of the conversion by tweaking the
# parsing settings. To do so, pass a block to the new method, and
- # call methds of Versionomy::Conversion::Parsing::Builder in that
+ # call methods of Versionomy::Conversion::Parsing::Builder in that
# block.
def initialize(&block_)
@@ -67,15 +67,6 @@ def initialize(&block_)
end
- def inspect # :nodoc:
- "#<#{self.class}:0x#{object_id.to_s(16)}>"
- end
-
- def to_s # :nodoc:
- inspect
- end
-
-
# Returns a value equivalent to the given value in the given format.
#
# The convert_params are passed to this conversion's customization
@@ -44,7 +44,7 @@ module Conversion
module Rubygems
-
+
# Create the conversion from standard to rubygems format.
# This method is called internally when Versionomy initializes itself,
# and you should not need to call it again. It is documented, however,
@@ -53,7 +53,7 @@ module Rubygems
def self.create_standard_to_rubygems
- # We'll use a parsing conversion to do this conversion.
+ # We'll use a parsing conversion.
Conversion::Parsing.new do
# We're going to modify how the standard format version is
@@ -105,10 +105,19 @@ def self.create_standard_to_rubygems
def self.create_rubygems_to_standard
- # We'll use a parsing conversion to do this conversion.
- # The standard format generally understands the rubygems format
- # already, so we don't need to do any special configuration.
- Conversion::Parsing.new
+ # We'll use a parsing conversion.
+ Conversion::Parsing.new do
+
+ # Handle the case where the rubygems version ends with a string
+ # field, e.g. "1.0.b". We want to treat this like "1.0b0" rather
+ # than "1.0-2" since the rubygems semantic states that this is a
+ # prerelease version. So we add 0 to the end of the parsed string
+ # if it ends in a letter.
+ to_modify_string do |str_, convert_params_|
+ str_.gsub(/([[:alpha:]])\z/, '\10')
+ end
+
+ end
end
@@ -109,7 +109,7 @@ class TypeMismatchError < SchemaCreationError
# This exception is raised during schema creation if you try to
- # create a circular dependency.
+ # create a circular graph.
class CircularDescendantError < SchemaCreationError
end
@@ -155,12 +155,6 @@ class ConversionRedefinedError < VersionomyError
end
- # Raised when serialization or deserialization fails.
-
- class SerializationError < VersionomyError
- end
-
-
end
end
@@ -96,7 +96,7 @@ def get(name_, strict_=false)
def register(name_, format_)
name_ = name_.to_s
- unless name_ =~ /^[\w.-]+$/
+ unless name_ =~ /\A[\w.-]+\z/
raise ::ArgumentError, "Illegal name: #{name_.inspect}"
end
if @names_to_formats.include?(name_)
@@ -70,15 +70,12 @@ def test_standard_to_rubygems_simple
def test_standard_to_rubygems_with_patchlevel
value_ = ::Versionomy.parse('1.2-3')
value2_ = value_.convert(:rubygems)
- assert_equal(@rubygems_format, value2_.format)
assert_equal([1, 2, 3, 0, 0, 0, 0, 0], value2_.values_array)
value_ = ::Versionomy.parse('1.2p3')
value2_ = value_.convert(:rubygems)
- assert_equal(@rubygems_format, value2_.format)
assert_equal([1, 2, 3, 0, 0, 0, 0, 0], value2_.values_array)
value_ = ::Versionomy.parse('1.2c')
value2_ = value_.convert(:rubygems)
- assert_equal(@rubygems_format, value2_.format)
assert_equal([1, 2, 3, 0, 0, 0, 0, 0], value2_.values_array)
end
@@ -88,11 +85,9 @@ def test_standard_to_rubygems_with_patchlevel
def test_standard_to_rubygems_beta
value_ = ::Versionomy.parse('1.2b3')
value2_ = value_.convert(:rubygems)
- assert_equal(@rubygems_format, value2_.format)
assert_equal([1, 2, 'b', 3, 0, 0, 0, 0], value2_.values_array)
value_ = ::Versionomy.parse('1.2 beta 3.4')
value2_ = value_.convert(:rubygems)
- assert_equal(@rubygems_format, value2_.format)
assert_equal([1, 2, 'beta', 3, 4, 0, 0, 0], value2_.values_array)
end
@@ -116,16 +111,16 @@ def test_rubygems_to_standard_simple
def test_rubygems_to_standard_beta
value_ = ::Versionomy.parse('1.2.b.3', :rubygems)
value2_ = value_.convert(:standard)
- assert_equal(@standard_format, value2_.format)
assert_equal([1, 2, 0, 0, :beta, 3, 0], value2_.values_array)
value_ = ::Versionomy.parse('1.2.b3', :rubygems)
value2_ = value_.convert(:standard)
- assert_equal(@standard_format, value2_.format)
assert_equal([1, 2, 0, 0, :beta, 3, 0], value2_.values_array)
value_ = ::Versionomy.parse('1.2.beta3', :rubygems)
value2_ = value_.convert(:standard)
- assert_equal(@standard_format, value2_.format)
assert_equal([1, 2, 0, 0, :beta, 3, 0], value2_.values_array)
+ value_ = ::Versionomy.parse('1.2.b', :rubygems)
+ value2_ = value_.convert(:standard)
+ assert_equal([1, 2, 0, 0, :beta, 0, 0], value2_.values_array)
end

0 comments on commit b59f4d9

Please sign in to comment.