versionomy 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,15 +1,15 @@
1
1
  # -----------------------------------------------------------------------------
2
- #
2
+ #
3
3
  # Versionomy standard format implementation
4
- #
4
+ #
5
5
  # -----------------------------------------------------------------------------
6
6
  # Copyright 2008-2009 Daniel Azuma
7
- #
7
+ #
8
8
  # All rights reserved.
9
- #
9
+ #
10
10
  # Redistribution and use in source and binary forms, with or without
11
11
  # modification, are permitted provided that the following conditions are met:
12
- #
12
+ #
13
13
  # * Redistributions of source code must retain the above copyright notice,
14
14
  # this list of conditions and the following disclaimer.
15
15
  # * Redistributions in binary form must reproduce the above copyright notice,
@@ -18,7 +18,7 @@
18
18
  # * Neither the name of the copyright holder, nor the names of any other
19
19
  # contributors to this software, may be used to endorse or promote products
20
20
  # derived from this software without specific prior written permission.
21
- #
21
+ #
22
22
  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
23
  # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
24
  # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -35,55 +35,55 @@
35
35
 
36
36
 
37
37
  module Versionomy
38
-
38
+
39
39
  module Format
40
-
41
-
40
+
41
+
42
42
  # Get the rubygems format.
43
43
  # This is identical to calling <tt>get('rubygems')</tt>.
44
- #
44
+ #
45
45
  # The rubygems format is designed to be parse-compatible with the
46
46
  # Gem::Version class used in rubygems. The only caveat is, whereas
47
47
  # Gem::Version handles an arbitrary number of fields, this format is
48
48
  # limited to a maximum of 8.
49
- #
49
+ #
50
50
  # For the exact annotated definition of the rubygems schema and format,
51
51
  # see the source code for Versionomy::Format::Rubygems#create.
52
-
52
+
53
53
  def self.rubygems
54
54
  get('rubygems')
55
55
  end
56
-
57
-
56
+
57
+
58
58
  # This is a namespace for the implementation of the Rubygems schema
59
59
  # and format.
60
-
60
+
61
61
  module Rubygems
62
-
63
-
62
+
63
+
64
64
  # Extra methods added to version values that use the rubygems schema.
65
-
65
+
66
66
  module ExtraMethods
67
-
68
-
67
+
68
+
69
69
  # Returns true if the version is a prerelease version-- that is,
70
70
  # if any of the fields is non-numeric.
71
- #
71
+ #
72
72
  # This behaves the same as the Gem::Version#prerelease? method
73
73
  # in rubygems.
74
-
74
+
75
75
  def prerelease?
76
76
  values_array.any?{ |val_| val_.kind_of?(::String) }
77
77
  end
78
-
79
-
78
+
79
+
80
80
  # Returns the release for this version.
81
81
  # For example, converts "1.2.0.a.1" to "1.2.0".
82
82
  # Non-prerelease versions return themselves.
83
- #
83
+ #
84
84
  # This behaves the same as the Gem::Version#release method
85
85
  # in rubygems.
86
-
86
+
87
87
  def release
88
88
  values_ = []
89
89
  self.each_field_object do |field_, val_|
@@ -92,14 +92,14 @@ module Versionomy
92
92
  end
93
93
  Value.new(values_, self.format, self.unparse_params)
94
94
  end
95
-
96
-
95
+
96
+
97
97
  # Returns a list of the field values, in field order, with
98
98
  # trailing zeroes stripped off.
99
- #
99
+ #
100
100
  # This behaves the same as the Gem::Version#parts method
101
101
  # in rubygems.
102
-
102
+
103
103
  def parts
104
104
  unless @parts
105
105
  @parts = values_array
@@ -107,23 +107,23 @@ module Versionomy
107
107
  end
108
108
  @parts
109
109
  end
110
-
111
-
110
+
111
+
112
112
  end
113
-
114
-
113
+
114
+
115
115
  # Create the rubygems format.
116
116
  # This method is called internally when Versionomy loads the rubygems
117
117
  # format, and you should not need to call it again. It is documented
118
118
  # so that you can inspect its source code from RDoc, since the source
119
119
  # contains useful examples of how to use the schema and format
120
120
  # definition DSLs.
121
-
121
+
122
122
  def self.create
123
-
123
+
124
124
  # The following is the definition of the rubygems schema
125
125
  schema_ = Schema.create do
126
-
126
+
127
127
  # Global comparison function
128
128
  to_compare_type(:string) do |a_, b_|
129
129
  if a_.kind_of?(::Integer)
@@ -140,7 +140,7 @@ module Versionomy
140
140
  end
141
141
  end
142
142
  end
143
-
143
+
144
144
  # Global canonicalization function
145
145
  to_canonicalize_type(:string) do |val_|
146
146
  if val_.kind_of?(::Integer)
@@ -154,7 +154,7 @@ module Versionomy
154
154
  end
155
155
  end
156
156
  end
157
-
157
+
158
158
  # The first field has the default value of 1. All other fields
159
159
  # have a default value of 0. Thus, the default version number
160
160
  # overall is "1.0".
@@ -173,25 +173,25 @@ module Versionomy
173
173
  end
174
174
  end
175
175
  end
176
-
176
+
177
177
  # Some field aliases providing alternate names for major fields
178
178
  alias_field(:major, :field0)
179
179
  alias_field(:minor, :field1)
180
-
180
+
181
181
  # Add the methods in this module to each value
182
182
  add_module(Format::Rubygems::ExtraMethods)
183
183
  end
184
-
184
+
185
185
  # The following is the definition of the rubygems format. It
186
186
  # understands the rubygems schema defined above.
187
187
  format_ = Format::Delimiter.new(schema_) do
188
-
188
+
189
189
  # All version number strings must start with the major version.
190
190
  # Unlike other fields, it is not preceded by any delimiter.
191
191
  field(:field0) do
192
192
  recognize_number(:delimiter_regexp => '', :default_delimiter => '')
193
193
  end
194
-
194
+
195
195
  # The remainder of the version number are represented as strings
196
196
  # or integers delimited by periods by default. Each is also
197
197
  # dependent on the presence of the previous field, so
@@ -219,50 +219,50 @@ module Versionomy
219
219
  field(:field7) do
220
220
  recognize_regexp('[0-9a-zA-Z]+', :default_value_optional => true)
221
221
  end
222
-
222
+
223
223
  # By default, we require that at least the first two fields
224
224
  # appear in an unparsed version string.
225
225
  default_unparse_params(:required_fields => [:field1])
226
226
  end
227
227
  end
228
-
229
-
228
+
229
+
230
230
  end
231
-
232
-
231
+
232
+
233
233
  register('rubygems', Format::Rubygems.create, true)
234
-
235
-
234
+
235
+
236
236
  end
237
-
238
-
237
+
238
+
239
239
  module Conversion
240
-
241
-
240
+
241
+
242
242
  # This is a namespace for the implementation of the conversion between
243
243
  # the rubygems and standard formats.
244
-
244
+
245
245
  module Rubygems
246
-
247
-
246
+
247
+
248
248
  # Create the conversion from standard to rubygems format.
249
249
  # This method is called internally when Versionomy loads the rubygems
250
250
  # format, and you should not need to call it again. It is documented
251
251
  # so that you can inspect its source code from RDoc, since the source
252
252
  # contains useful examples of how to use the conversion DSLs.
253
-
253
+
254
254
  def self.create_standard_to_rubygems
255
-
255
+
256
256
  # We'll use a parsing conversion.
257
257
  Conversion::Parsing.new do
258
-
258
+
259
259
  # We're going to modify how the standard format version is
260
260
  # unparsed, so the rubygems format will have a better chance
261
261
  # of parsing it.
262
262
  to_modify_unparse_params do |params_, convert_params_|
263
-
263
+
264
264
  params_ ||= {}
265
-
265
+
266
266
  # If the standard format version has a prerelease notation,
267
267
  # make sure it is set off using a delimiter that the rubygems
268
268
  # format can recognize. So instead of "1.0b2", we force the
@@ -273,49 +273,49 @@ module Versionomy
273
273
  params_[:beta_version_delim] = '.'
274
274
  params_[:release_candidate_version_delim] = '.'
275
275
  params_[:preview_version_delim] = '.'
276
-
276
+
277
277
  # If the standard format version has a patchlevel notation,
278
278
  # force it to use the default number rather than letter style.
279
279
  # So instead of "1.2c", we force the unparsing to generate
280
280
  # "1.2-3".
281
281
  params_[:patchlevel_style] = nil
282
-
282
+
283
283
  # If the standard format version has a patchlevel notation,
284
284
  # force it to use the default delimiter of "-" so the rubygems
285
285
  # format will recognize it. So instead of "1.9.1p243", we force
286
286
  # the unparsing to generate "1.9.1-243".
287
287
  params_[:patchlevel_delim] = nil
288
-
288
+
289
289
  # If the standard format version includes a "v" prefix, strip
290
290
  # it because rubygems doesn't like it.
291
291
  params_[:major_delim] = nil
292
-
292
+
293
293
  params_
294
294
  end
295
-
295
+
296
296
  # Standard formats sometimes allow hyphens and spaces in field
297
297
  # delimiters, but the rubygems format requires periods. So modify
298
298
  # the unparsed string to conform to rubygems's expectations.
299
299
  to_modify_string do |str_, convert_params_|
300
300
  str_.gsub(/[\.\s-]+/, '.')
301
301
  end
302
-
302
+
303
303
  end
304
-
304
+
305
305
  end
306
-
307
-
306
+
307
+
308
308
  # Create the conversion from rubygems to standard format.
309
309
  # This method is called internally when Versionomy loads the rubygems
310
310
  # format, and you should not need to call it again. It is documented
311
311
  # so that you can inspect its source code from RDoc, since the source
312
312
  # contains useful examples of how to use the conversion DSLs.
313
-
313
+
314
314
  def self.create_rubygems_to_standard
315
-
315
+
316
316
  # We'll use a parsing conversion.
317
317
  Conversion::Parsing.new do
318
-
318
+
319
319
  # Handle the case where the rubygems version ends with a string
320
320
  # field, e.g. "1.0.b". We want to treat this like "1.0b0" rather
321
321
  # than "1.0-2" since the rubygems semantic states that this is a
@@ -324,20 +324,20 @@ module Versionomy
324
324
  to_modify_string do |str_, convert_params_|
325
325
  str_.gsub(/([[:alpha:]])\z/, '\10')
326
326
  end
327
-
327
+
328
328
  end
329
-
329
+
330
330
  end
331
-
332
-
331
+
332
+
333
333
  end
334
-
335
-
334
+
335
+
336
336
  register(:standard, :rubygems, Conversion::Rubygems.create_standard_to_rubygems, true)
337
337
  register(:rubygems, :standard, Conversion::Rubygems.create_rubygems_to_standard, true)
338
-
339
-
338
+
339
+
340
340
  end
341
-
342
-
341
+
342
+
343
343
  end
@@ -1,15 +1,15 @@
1
1
  # -----------------------------------------------------------------------------
2
- #
2
+ #
3
3
  # Versionomy semver format implementation
4
- #
4
+ #
5
5
  # -----------------------------------------------------------------------------
6
6
  # Copyright 2010 Daniel Azuma
7
- #
7
+ #
8
8
  # All rights reserved.
9
- #
9
+ #
10
10
  # Redistribution and use in source and binary forms, with or without
11
11
  # modification, are permitted provided that the following conditions are met:
12
- #
12
+ #
13
13
  # * Redistributions of source code must retain the above copyright notice,
14
14
  # this list of conditions and the following disclaimer.
15
15
  # * Redistributions in binary form must reproduce the above copyright notice,
@@ -18,7 +18,7 @@
18
18
  # * Neither the name of the copyright holder, nor the names of any other
19
19
  # contributors to this software, may be used to endorse or promote products
20
20
  # derived from this software without specific prior written permission.
21
- #
21
+ #
22
22
  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
23
  # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
24
  # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -35,78 +35,78 @@
35
35
 
36
36
 
37
37
  module Versionomy
38
-
38
+
39
39
  module Format
40
-
41
-
40
+
41
+
42
42
  # Get the semver format.
43
43
  # This is identical to calling <tt>get('semver')</tt>.
44
- #
44
+ #
45
45
  # The semver format is designed to conform to the Semantic Versioning
46
46
  # spec by Tom Preston-Warner. See http://semver.org/
47
- #
47
+ #
48
48
  # For the exact annotated definition of the semver schema and format,
49
49
  # see the source code for Versionomy::Format::Semver#create.
50
-
50
+
51
51
  def self.semver
52
52
  get('semver')
53
53
  end
54
-
55
-
54
+
55
+
56
56
  # This is a namespace for the implementation of the semver schema
57
57
  # and format.
58
-
58
+
59
59
  module Semver
60
-
61
-
60
+
61
+
62
62
  # Extra methods added to version values that use the semver schema.
63
-
63
+
64
64
  module ExtraMethods
65
-
66
-
65
+
66
+
67
67
  # Returns true if the version is a prerelease version-- that is,
68
68
  # if the prerelease_suffix is nonempty.
69
-
69
+
70
70
  def prerelease?
71
71
  prerelease_suffix.length > 0
72
72
  end
73
-
74
-
73
+
74
+
75
75
  # Returns the release for this version.
76
76
  # For example, converts "1.2.0a1" to "1.2.0".
77
77
  # Non-prerelease versions return themselves unchanged.
78
-
78
+
79
79
  def release
80
80
  prerelease? ? self.change(:prerelease_suffix => '') : self
81
81
  end
82
-
83
-
82
+
83
+
84
84
  # Returns true if this version is compatible with the given version,
85
85
  # according to the Semantic Versioning specification.
86
86
  # For example, 1.1.0 is compatible with 1.0.0 but not vice versa,
87
87
  # 1.1.1 and 1.1.0 are compatible with each other, while 1.0.0 and
88
88
  # 2.0.0 are mutually incompatible.
89
-
89
+
90
90
  def compatible_with?(version_)
91
91
  self.major == version_.major ? self.minor >= version_.minor : false
92
92
  end
93
-
94
-
93
+
94
+
95
95
  end
96
-
97
-
96
+
97
+
98
98
  # Create the semver format.
99
99
  # This method is called internally when Versionomy loads the semver
100
100
  # format, and you should not need to call it again. It is documented
101
101
  # so that you can inspect its source code from RDoc, since the source
102
102
  # contains useful examples of how to use the schema and format
103
103
  # definition DSLs.
104
-
104
+
105
105
  def self.create
106
-
106
+
107
107
  # The following is the definition of the semver schema
108
108
  schema_ = Schema.create do
109
-
109
+
110
110
  # The first field has the default value of 1. All other fields
111
111
  # have a default value of 0. Thus, the default version number
112
112
  # overall is "1.0".
@@ -121,25 +121,25 @@ module Versionomy
121
121
  end
122
122
  end
123
123
  end
124
-
124
+
125
125
  # An alias
126
126
  alias_field(:special_suffix, :prerelease_suffix)
127
-
127
+
128
128
  # Add the methods in this module to each value
129
129
  add_module(Format::Semver::ExtraMethods)
130
130
  end
131
-
131
+
132
132
  # The following is the definition of the standard format. It
133
133
  # understands the standard schema defined above.
134
134
  format_ = Format::Delimiter.new(schema_) do
135
-
135
+
136
136
  # All version number strings must start with the major version.
137
137
  # Unlike other fields, it is not preceded by the usual "dot"
138
138
  # delimiter, but it can be preceded by a "v" indicator.
139
139
  field(:major) do
140
140
  recognize_number(:delimiter_regexp => 'v?', :default_delimiter => '')
141
141
  end
142
-
142
+
143
143
  # The remainder of the core version number are represented as
144
144
  # integers delimited by periods. These fields are required.
145
145
  field(:minor) do
@@ -148,7 +148,7 @@ module Versionomy
148
148
  field(:patch) do
149
149
  recognize_number
150
150
  end
151
-
151
+
152
152
  # The optional prerelease field is represented as a string
153
153
  # beginning with an alphabetic character.
154
154
  field(:prerelease_suffix) do
@@ -157,37 +157,37 @@ module Versionomy
157
157
  end
158
158
  end
159
159
  end
160
-
161
-
160
+
161
+
162
162
  end
163
-
164
-
163
+
164
+
165
165
  register('semver', Format::Semver.create, true)
166
-
167
-
166
+
167
+
168
168
  end
169
-
170
-
169
+
170
+
171
171
  module Conversion
172
-
173
-
172
+
173
+
174
174
  # This is a namespace for the implementation of the conversion between
175
175
  # the semver and standard formats.
176
-
176
+
177
177
  module Semver
178
-
179
-
178
+
179
+
180
180
  # Create the conversion from standard to semver format.
181
181
  # This method is called internally when Versionomy loads the semver
182
182
  # format, and you should not need to call it again. It is documented
183
183
  # so that you can inspect its source code from RDoc, since the source
184
184
  # contains useful examples of how to use the conversion DSLs.
185
-
185
+
186
186
  def self.create_standard_to_semver
187
-
187
+
188
188
  # We'll use a parsing conversion.
189
189
  Conversion::Parsing.new do
190
-
190
+
191
191
  # Sanity check the original value and make sure it doesn't
192
192
  # include fields that we don't support.
193
193
  to_modify_original_value do |value_, convert_params_|
@@ -199,16 +199,16 @@ module Versionomy
199
199
  end
200
200
  value_
201
201
  end
202
-
202
+
203
203
  # We're going to modify how the standard format version is
204
204
  # unparsed, so the semver format will have a better chance
205
205
  # of parsing it.
206
206
  to_modify_unparse_params do |params_, convert_params_|
207
-
207
+
208
208
  # All three fields are required
209
209
  params_[:minor_required] = true
210
210
  params_[:tiny_required] = true
211
-
211
+
212
212
  # If the standard format version has a prerelease notation,
213
213
  # make sure it isn't set off using a delimiter.
214
214
  params_[:release_type_delim] = ''
@@ -222,29 +222,29 @@ module Versionomy
222
222
  params_[:release_candidate_minor_delim] = '-'
223
223
  params_[:preview_version_delim] = ''
224
224
  params_[:preview_minor_delim] = '-'
225
-
225
+
226
226
  # If the standard format version includes a "v" prefix, strip it
227
227
  params_[:major_delim] = nil
228
-
228
+
229
229
  params_
230
230
  end
231
-
231
+
232
232
  end
233
-
233
+
234
234
  end
235
-
236
-
235
+
236
+
237
237
  # Create the conversion from semver to standard format.
238
238
  # This method is called internally when Versionomy loads the semver
239
239
  # format, and you should not need to call it again. It is documented
240
240
  # so that you can inspect its source code from RDoc, since the source
241
241
  # contains useful examples of how to use the conversion DSLs.
242
-
242
+
243
243
  def self.create_semver_to_standard
244
-
244
+
245
245
  # We'll use a parsing conversion.
246
246
  Conversion::Parsing.new do
247
-
247
+
248
248
  # Handle the case where the semver version ends with a string
249
249
  # field, e.g. "1.0b". We want to treat this like "1.0b0" rather
250
250
  # than "1.0-2" since the semver semantic states that this is a
@@ -253,20 +253,20 @@ module Versionomy
253
253
  to_modify_string do |str_, convert_params_|
254
254
  str_.gsub(/([[:alpha:]])\z/, '\10')
255
255
  end
256
-
256
+
257
257
  end
258
-
258
+
259
259
  end
260
-
261
-
260
+
261
+
262
262
  end
263
-
264
-
263
+
264
+
265
265
  register(:standard, :semver, Conversion::Semver.create_standard_to_semver, true)
266
266
  register(:semver, :standard, Conversion::Semver.create_semver_to_standard, true)
267
-
268
-
267
+
268
+
269
269
  end
270
-
271
-
270
+
271
+
272
272
  end