versionomy 0.2.5 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -71,8 +71,8 @@ module Versionomy
71
71
  @_unparse_params = unparse_params_
72
72
  @_field_path = []
73
73
  @_values = {}
74
- schema_ = @_format.schema
75
- field_ = schema_.root_field
74
+ values_ = _canonicalize_values_hash(values_) if values_.kind_of?(::Hash)
75
+ field_ = @_format.schema.root_field
76
76
  while field_
77
77
  value_ = values_.kind_of?(::Hash) ? values_[field_.name] : values_.shift
78
78
  value_ = value_ ? field_.canonicalize_value(value_) : field_.default_value
@@ -80,7 +80,7 @@ module Versionomy
80
80
  @_values[field_.name] = value_
81
81
  field_ = field_.child(value_)
82
82
  end
83
- modules_ = schema_.modules
83
+ modules_ = @_format.schema.modules
84
84
  extend(*modules_) if modules_.size > 0
85
85
  end
86
86
 
@@ -150,7 +150,9 @@ module Versionomy
150
150
  end
151
151
 
152
152
 
153
+ # YAML tags. The last one is the canonical one.
153
154
  yaml_as "tag:danielazuma.com,2009:version"
155
+ yaml_as "tag:verse15.com,2009:version"
154
156
 
155
157
 
156
158
  # Deserialize a version number from YAML
@@ -259,7 +261,7 @@ module Versionomy
259
261
  when ::Integer
260
262
  @_field_path.size > field_ && field_ >= 0
261
263
  when ::String, ::Symbol
262
- @_values.has_key?(field_.to_sym)
264
+ @_values.has_key?(@_format.schema.canonical_name(field_))
263
265
  else
264
266
  raise ::ArgumentError
265
267
  end
@@ -271,9 +273,7 @@ module Versionomy
271
273
  # or field index.
272
274
 
273
275
  def [](field_)
274
- field_ = @_field_path[field_] if field_.kind_of?(::Integer)
275
- field_ = field_.name if field_.kind_of?(Schema::Field)
276
- field_ ? @_values[field_.to_sym] : nil
276
+ @_values[_interpret_field(field_)]
277
277
  end
278
278
 
279
279
 
@@ -298,17 +298,14 @@ module Versionomy
298
298
  # Returns self unchanged if the field was not recognized or could not
299
299
  # be modified.
300
300
 
301
- def bump(name_)
302
- name_ = @_field_path[name_] if name_.kind_of?(::Integer)
303
- name_ = name_.name if name_.kind_of?(Schema::Field)
304
- return self unless name_
305
- name_ = name_.to_sym
306
- return self unless @_values.include?(name_)
301
+ def bump(field_)
302
+ name_ = _interpret_field(field_)
303
+ return self unless name_ && @_values.include?(name_)
307
304
  values_ = []
308
- @_field_path.each do |field_|
309
- oldval_ = @_values[field_.name]
310
- if field_.name == name_
311
- newval_ = field_.bump_value(oldval_)
305
+ @_field_path.each do |fld_|
306
+ oldval_ = @_values[fld_.name]
307
+ if fld_.name == name_
308
+ newval_ = fld_.bump_value(oldval_)
312
309
  return self if newval_ == oldval_
313
310
  values_ << newval_
314
311
  return Value.new(values_, @_format, @_unparse_params)
@@ -320,6 +317,28 @@ module Versionomy
320
317
  end
321
318
 
322
319
 
320
+ # Returns a new version number created by resetting the given field. The
321
+ # field may be specified as a field object, field name, or field index.
322
+ # Returns self unchanged if the field was not recognized or could not
323
+ # be modified.
324
+
325
+ def reset(field_)
326
+ name_ = _interpret_field(field_)
327
+ return self unless name_ && @_values.include?(name_)
328
+ values_ = []
329
+ @_field_path.each do |fld_|
330
+ oldval_ = @_values[fld_.name]
331
+ if fld_.name == name_
332
+ values_ << fld_.default_value
333
+ return Value.new(values_, @_format, @_unparse_params)
334
+ else
335
+ values_ << oldval_
336
+ end
337
+ end
338
+ self
339
+ end
340
+
341
+
323
342
  # Returns a new version number created by cloning this version number
324
343
  # and changing the given field values.
325
344
  #
@@ -334,6 +353,7 @@ module Versionomy
334
353
 
335
354
  def change(values_={}, unparse_params_={})
336
355
  unparse_params_ = @_unparse_params.merge(unparse_params_) if @_unparse_params
356
+ values_ = _canonicalize_values_hash(values_)
337
357
  Value.new(@_values.merge(values_), @_format, unparse_params_)
338
358
  end
339
359
 
@@ -456,6 +476,32 @@ module Versionomy
456
476
  end
457
477
 
458
478
 
479
+ private
480
+
481
+ def _interpret_field(field_) # :nodoc:
482
+ case field_
483
+ when Schema::Field
484
+ @_format.schema.canonical_name(field_.name)
485
+ when ::Integer
486
+ field_ = @_field_path[field_]
487
+ field_ ? field_.name : nil
488
+ when ::String, ::Symbol
489
+ @_format.schema.canonical_name(field_)
490
+ end
491
+ end
492
+
493
+
494
+ def _canonicalize_values_hash(values_) # :nodoc:
495
+ schema_ = @_format.schema
496
+ new_values_ = {}
497
+ values_.each do |k_,v_|
498
+ k_ = schema_.canonical_name(k_)
499
+ new_values_[k_] = v_ if k_
500
+ end
501
+ new_values_
502
+ end
503
+
504
+
459
505
  end
460
506
 
461
507
 
@@ -37,7 +37,7 @@
37
37
  module Versionomy
38
38
 
39
39
  # Current gem version, as a frozen string.
40
- VERSION_STRING = '0.2.5'.freeze
40
+ VERSION_STRING = '0.3.0'.freeze
41
41
 
42
42
  # Current gem version, as a Versionomy::Value.
43
43
  VERSION = ::Versionomy.parse(VERSION_STRING, :standard)
@@ -76,6 +76,23 @@ module Versionomy
76
76
  end
77
77
 
78
78
 
79
+ # Test aliases
80
+
81
+ def test_alias_fields
82
+ value_ = ::Versionomy.create([1, 9, 2, 'a', 2], :rubygems)
83
+ assert_equal(1, value_.major)
84
+ assert_equal(9, value_.minor)
85
+ end
86
+
87
+
88
+ # Test construction using aliases
89
+
90
+ def test_alias_field_construction
91
+ value_ = ::Versionomy.create({:major => 1, :minor => 9, :field2 => 2}, :rubygems)
92
+ assert_equal([1, 9, 2, 0, 0, 0, 0, 0], value_.values_array)
93
+ end
94
+
95
+
79
96
  # Test comparison of numeric values.
80
97
 
81
98
  def test_numeric_comparison
@@ -153,6 +170,24 @@ module Versionomy
153
170
  end
154
171
 
155
172
 
173
+ # Test bumping an alias field.
174
+
175
+ def test_bump_alias
176
+ value_ = ::Versionomy.create([1, 9, 2, 'a', 2], :rubygems)
177
+ value_ = value_.bump(:minor)
178
+ assert_equal([1, 10, 0, 0, 0, 0, 0, 0], value_.values_array)
179
+ end
180
+
181
+
182
+ # Test changing an alias field.
183
+
184
+ def test_change_alias
185
+ value_ = ::Versionomy.create([1, 8, 7, 'a', 2], :rubygems)
186
+ value_ = value_.change(:minor => 9)
187
+ assert_equal([1, 9, 7, 'a', 2, 0, 0, 0], value_.values_array)
188
+ end
189
+
190
+
156
191
  # Test "prerelase?" custom method
157
192
 
158
193
  def test_method_prereleasep
@@ -0,0 +1,106 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # Versionomy bump tests on standard schema
4
+ #
5
+ # This file contains tests for the bump function on the standard schema
6
+ #
7
+ # -----------------------------------------------------------------------------
8
+ # Copyright 2008-2009 Daniel Azuma
9
+ #
10
+ # All rights reserved.
11
+ #
12
+ # Redistribution and use in source and binary forms, with or without
13
+ # modification, are permitted provided that the following conditions are met:
14
+ #
15
+ # * Redistributions of source code must retain the above copyright notice,
16
+ # this list of conditions and the following disclaimer.
17
+ # * Redistributions in binary form must reproduce the above copyright notice,
18
+ # this list of conditions and the following disclaimer in the documentation
19
+ # and/or other materials provided with the distribution.
20
+ # * Neither the name of the copyright holder, nor the names of any other
21
+ # contributors to this software, may be used to endorse or promote products
22
+ # derived from this software without specific prior written permission.
23
+ #
24
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
28
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34
+ # POSSIBILITY OF SUCH DAMAGE.
35
+ # -----------------------------------------------------------------------------
36
+
37
+
38
+ require 'rubygems'
39
+ require 'test/unit'
40
+ require ::File.expand_path("#{::File.dirname(__FILE__)}/../lib/versionomy.rb")
41
+
42
+
43
+ module Versionomy
44
+ module Tests # :nodoc:
45
+
46
+ class TestStandardReset < ::Test::Unit::TestCase # :nodoc:
47
+
48
+
49
+ # Test resetting a minor patchlevel.
50
+
51
+ def test_reset_patchlevel_minor
52
+ value_ = ::Versionomy.create(:major => 2, :tiny => 1, :patchlevel => 3, :patchlevel_minor => 1)
53
+ value_ = value_.reset(:patchlevel_minor)
54
+ assert_equal([2,0,1,0,:final,3,0], value_.values_array)
55
+ end
56
+
57
+
58
+ # Test resetting a major patchlevel.
59
+
60
+ def test_reset_patchlevel
61
+ value_ = ::Versionomy.create(:major => 2, :tiny => 1, :patchlevel => 3, :patchlevel_minor => 1)
62
+ value_ = value_.reset(:patchlevel)
63
+ assert_equal([2,0,1,0,:final,0,0], value_.values_array)
64
+ end
65
+
66
+
67
+ # Test resetting a beta release type.
68
+
69
+ def test_reset_beta_release_type
70
+ value_ = ::Versionomy.create(:major => 2, :tiny => 1, :release_type => :beta, :beta_version => 2)
71
+ value_ = value_.reset(:release_type)
72
+ assert_equal([2,0,1,0,:final,0,0], value_.values_array)
73
+ end
74
+
75
+
76
+ # Test resetting a final release type.
77
+
78
+ def test_reset_final_release_type
79
+ value_ = ::Versionomy.create(:major => 2, :tiny => 1, :patchlevel => 2)
80
+ value_ = value_.reset(:release_type)
81
+ assert_equal([2,0,1,0,:final,0,0], value_.values_array)
82
+ end
83
+
84
+
85
+ # Test resetting tiny.
86
+
87
+ def test_reset_tiny
88
+ value_ = ::Versionomy.create(:major => 2, :tiny => 1, :tiny2 => 3, :release_type => :release_candidate, :release_candidate_version => 2)
89
+ value_ = value_.reset(:tiny)
90
+ assert_equal([2,0,0,0,:final,0,0], value_.values_array)
91
+ end
92
+
93
+
94
+ # Test resetting major.
95
+
96
+ def test_reset_major
97
+ value_ = ::Versionomy.create(:major => 2, :tiny => 1, :tiny2 => 3, :release_type => :release_candidate, :release_candidate_version => 2)
98
+ value_ = value_.reset(:major)
99
+ assert_equal([1,0,0,0,:final,0,0], value_.values_array)
100
+ end
101
+
102
+
103
+ end
104
+
105
+ end
106
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: versionomy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Azuma
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-24 00:00:00 -08:00
12
+ date: 2009-11-30 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -30,18 +30,18 @@ extensions: []
30
30
 
31
31
  extra_rdoc_files:
32
32
  - README.rdoc
33
+ - Versionomy.rdoc
33
34
  - History.rdoc
34
35
  files:
35
36
  - lib/versionomy/conversion/base.rb
36
37
  - lib/versionomy/conversion/parsing.rb
37
- - lib/versionomy/conversion/rubygems.rb
38
38
  - lib/versionomy/conversion.rb
39
39
  - lib/versionomy/errors.rb
40
40
  - lib/versionomy/format/base.rb
41
41
  - lib/versionomy/format/delimiter.rb
42
- - lib/versionomy/format/rubygems.rb
43
- - lib/versionomy/format/standard.rb
44
42
  - lib/versionomy/format.rb
43
+ - lib/versionomy/format_definitions/rubygems.rb
44
+ - lib/versionomy/format_definitions/standard.rb
45
45
  - lib/versionomy/interface.rb
46
46
  - lib/versionomy/schema/field.rb
47
47
  - lib/versionomy/schema/wrapper.rb
@@ -59,8 +59,10 @@ files:
59
59
  - tests/tc_standard_comparison.rb
60
60
  - tests/tc_standard_misc.rb
61
61
  - tests/tc_standard_parse.rb
62
+ - tests/tc_standard_reset.rb
62
63
  - History.rdoc
63
64
  - README.rdoc
65
+ - Versionomy.rdoc
64
66
  - Rakefile
65
67
  has_rdoc: true
66
68
  homepage: http://virtuoso.rubyforge.org/versionomy
@@ -101,3 +103,4 @@ test_files:
101
103
  - tests/tc_standard_comparison.rb
102
104
  - tests/tc_standard_misc.rb
103
105
  - tests/tc_standard_parse.rb
106
+ - tests/tc_standard_reset.rb
@@ -1,146 +0,0 @@
1
- # -----------------------------------------------------------------------------
2
- #
3
- # Versionomy standard format implementation
4
- #
5
- # -----------------------------------------------------------------------------
6
- # Copyright 2008-2009 Daniel Azuma
7
- #
8
- # All rights reserved.
9
- #
10
- # Redistribution and use in source and binary forms, with or without
11
- # modification, are permitted provided that the following conditions are met:
12
- #
13
- # * Redistributions of source code must retain the above copyright notice,
14
- # this list of conditions and the following disclaimer.
15
- # * Redistributions in binary form must reproduce the above copyright notice,
16
- # this list of conditions and the following disclaimer in the documentation
17
- # and/or other materials provided with the distribution.
18
- # * Neither the name of the copyright holder, nor the names of any other
19
- # contributors to this software, may be used to endorse or promote products
20
- # derived from this software without specific prior written permission.
21
- #
22
- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
- # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
- # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25
- # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26
- # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27
- # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
- # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
- # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
- # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
- # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
- # POSSIBILITY OF SUCH DAMAGE.
33
- # -----------------------------------------------------------------------------
34
- ;
35
-
36
-
37
- module Versionomy
38
-
39
- module Conversion
40
-
41
-
42
- # This is a namespace for the implementation of the conversion between
43
- # the rubygems and standard formats.
44
-
45
- module Rubygems
46
-
47
-
48
- # Create the conversion from standard to rubygems format.
49
- # This method is called internally when Versionomy initializes itself,
50
- # and you should not need to call it again. It is documented, however,
51
- # so that you can inspect its source code from RDoc, since the source
52
- # contains useful examples of how to use the conversion DSLs.
53
-
54
- def self.create_standard_to_rubygems
55
-
56
- # We'll use a parsing conversion.
57
- Conversion::Parsing.new do
58
-
59
- # We're going to modify how the standard format version is
60
- # unparsed, so the rubygems format will have a better chance
61
- # of parsing it.
62
- to_modify_unparse_params do |params_, convert_params_|
63
-
64
- params_ ||= {}
65
-
66
- # If the standard format version has a prerelease notation,
67
- # make sure it is set off using a delimiter that the rubygems
68
- # format can recognize. So instead of "1.0b2", we force the
69
- # unparsing to generate "1.0.b.2".
70
- params_[:release_type_delim] = '.'
71
- params_[:development_version_delim] = '.'
72
- params_[:alpha_version_delim] = '.'
73
- params_[:beta_version_delim] = '.'
74
- params_[:release_candidate_version_delim] = '.'
75
- params_[:preview_version_delim] = '.'
76
-
77
- # If the standard format version has a patchlevel notation,
78
- # force it to use the default number rather than letter style.
79
- # So instead of "1.2c", we force the unparsing to generate
80
- # "1.2-3".
81
- params_[:patchlevel_style] = nil
82
-
83
- # If the standard format version has a patchlevel notation,
84
- # force it to use the default delimiter of "-" so the rubygems
85
- # format will recognize it. So instead of "1.9.1p243", we force
86
- # the unparsing to generate "1.9.1-243".
87
- params_[:patchlevel_delim] = nil
88
-
89
- # If the standard format version includes a "v" prefix, strip
90
- # it because rubygems doesn't like it.
91
- params_[:major_delim] = nil
92
-
93
- params_
94
- end
95
-
96
- # Standard formats sometimes allow hyphens and spaces in field
97
- # delimiters, but the rubygems format requires periods. So modify
98
- # the unparsed string to conform to rubygems's expectations.
99
- to_modify_string do |str_, convert_params_|
100
- str_.gsub(/[\.\s-]+/, '.')
101
- end
102
-
103
- end
104
-
105
- end
106
-
107
-
108
- # Create the conversion from rubygems to standard format.
109
- # This method is called internally when Versionomy initializes itself,
110
- # and you should not need to call it again. It is documented, however,
111
- # so that you can inspect its source code from RDoc, since the source
112
- # contains useful examples of how to use the conversion DSLs.
113
-
114
- def self.create_rubygems_to_standard
115
-
116
- # We'll use a parsing conversion.
117
- Conversion::Parsing.new do
118
-
119
- # Handle the case where the rubygems version ends with a string
120
- # field, e.g. "1.0.b". We want to treat this like "1.0b0" rather
121
- # than "1.0-2" since the rubygems semantic states that this is a
122
- # prerelease version. So we add 0 to the end of the parsed string
123
- # if it ends in a letter.
124
- to_modify_string do |str_, convert_params_|
125
- str_.gsub(/([[:alpha:]])\z/, '\10')
126
- end
127
-
128
- end
129
-
130
- end
131
-
132
-
133
- unless Conversion.get(:standard, :rubygems)
134
- Conversion.register(:standard, :rubygems, create_standard_to_rubygems)
135
- end
136
- unless Conversion.get(:rubygems, :standard)
137
- Conversion.register(:rubygems, :standard, create_rubygems_to_standard)
138
- end
139
-
140
-
141
- end
142
-
143
-
144
- end
145
-
146
- end