Permalink
Browse files

Initial changes for 0.3.0 alpha release

  • Loading branch information...
1 parent 4c3f102 commit 57c5ebe3c514b942687fc15aff0b8ea59027c417 @dazuma committed Nov 30, 2009
View
@@ -1,3 +1,12 @@
+=== 0.3.0 / 2009-12-??
+
+* Alpha release, opened for public feedback
+* Autoloading of format definitions using a load path.
+* Format and conversion registry/lookup is now thread-safe.
+* Implemented resetting a particular field in the value.
+* Implemented aliases for field names.
+* Documentation updates
+
=== 0.2.5 / 2009-11-24
* Preserve minimum width of a field, if the field has leading zeros. For example, "2.01".
View
@@ -47,13 +47,10 @@
'format',
'format/base',
'format/delimiter',
- 'format/standard',
- 'format/rubygems',
'value',
'conversion',
'conversion/base',
'conversion/parsing',
- 'conversion/rubygems',
'interface',
'version',
]
@@ -34,6 +34,9 @@
;
+require 'thread'
+
+
module Versionomy
@@ -60,7 +63,8 @@ module Versionomy
module Conversion
- @registry = ::Hash.new
+ @registry = {}
+ @mutex = ::Mutex.new
class << self
@@ -95,7 +99,7 @@ def convert(value_, format_, convert_params_=nil)
def get(from_schema_, to_schema_, strict_=false)
key_ = _get_key(from_schema_, to_schema_)
- conversion_ = @registry[key_]
+ conversion_ = @mutex.synchronize{ @registry[key_] }
if strict_ && conversion_.nil?
raise Errors::UnknownConversionError
end
@@ -114,12 +118,17 @@ def get(from_schema_, to_schema_, strict_=false)
# Raises Versionomy::Errors::UnknownFormatError if a format was
# specified by name but the name is not known.
- def register(from_schema_, to_schema_, conversion_)
+ def register(from_schema_, to_schema_, conversion_, silent_=false)
key_ = _get_key(from_schema_, to_schema_)
- if @registry.include?(key_)
- raise Errors::ConversionRedefinedError
+ @mutex.synchronize do
+ if @registry.include?(key_)
+ unless silent_
+ raise Errors::ConversionRedefinedError
+ end
+ else
+ @registry[key_] = conversion_
+ end
end
- @registry[key_] = conversion_
end
@@ -1,146 +0,0 @@
-# -----------------------------------------------------------------------------
-#
-# Versionomy standard format implementation
-#
-# -----------------------------------------------------------------------------
-# Copyright 2008-2009 Daniel Azuma
-#
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions are met:
-#
-# * Redistributions of source code must retain the above copyright notice,
-# this list of conditions and the following disclaimer.
-# * Redistributions in binary form must reproduce the above copyright notice,
-# this list of conditions and the following disclaimer in the documentation
-# and/or other materials provided with the distribution.
-# * Neither the name of the copyright holder, nor the names of any other
-# contributors to this software, may be used to endorse or promote products
-# derived from this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
-# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-# POSSIBILITY OF SUCH DAMAGE.
-# -----------------------------------------------------------------------------
-;
-
-
-module Versionomy
-
- module Conversion
-
-
- # This is a namespace for the implementation of the conversion between
- # the rubygems and standard formats.
-
- 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,
- # so that you can inspect its source code from RDoc, since the source
- # contains useful examples of how to use the conversion DSLs.
-
- def self.create_standard_to_rubygems
-
- # We'll use a parsing conversion.
- Conversion::Parsing.new do
-
- # We're going to modify how the standard format version is
- # unparsed, so the rubygems format will have a better chance
- # of parsing it.
- to_modify_unparse_params do |params_, convert_params_|
-
- params_ ||= {}
-
- # If the standard format version has a prerelease notation,
- # make sure it is set off using a delimiter that the rubygems
- # format can recognize. So instead of "1.0b2", we force the
- # unparsing to generate "1.0.b.2".
- params_[:release_type_delim] = '.'
- params_[:development_version_delim] = '.'
- params_[:alpha_version_delim] = '.'
- params_[:beta_version_delim] = '.'
- params_[:release_candidate_version_delim] = '.'
- params_[:preview_version_delim] = '.'
-
- # If the standard format version has a patchlevel notation,
- # force it to use the default number rather than letter style.
- # So instead of "1.2c", we force the unparsing to generate
- # "1.2-3".
- params_[:patchlevel_style] = nil
-
- # If the standard format version has a patchlevel notation,
- # force it to use the default delimiter of "-" so the rubygems
- # format will recognize it. So instead of "1.9.1p243", we force
- # the unparsing to generate "1.9.1-243".
- params_[:patchlevel_delim] = nil
-
- # If the standard format version includes a "v" prefix, strip
- # it because rubygems doesn't like it.
- params_[:major_delim] = nil
-
- params_
- end
-
- # Standard formats sometimes allow hyphens and spaces in field
- # delimiters, but the rubygems format requires periods. So modify
- # the unparsed string to conform to rubygems's expectations.
- to_modify_string do |str_, convert_params_|
- str_.gsub(/[\.\s-]+/, '.')
- end
-
- end
-
- end
-
-
- # Create the conversion from rubygems to standard format.
- # This method is called internally when Versionomy initializes itself,
- # and you should not need to call it again. It is documented, however,
- # so that you can inspect its source code from RDoc, since the source
- # contains useful examples of how to use the conversion DSLs.
-
- def self.create_rubygems_to_standard
-
- # 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
-
-
- unless Conversion.get(:standard, :rubygems)
- Conversion.register(:standard, :rubygems, create_standard_to_rubygems)
- end
- unless Conversion.get(:rubygems, :standard)
- Conversion.register(:rubygems, :standard, create_rubygems_to_standard)
- end
-
-
- end
-
-
- end
-
-end
Oops, something went wrong.

0 comments on commit 57c5ebe

Please sign in to comment.