versionomy 0.4.1 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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,27 +35,27 @@
35
35
 
36
36
 
37
37
  module Versionomy
38
-
38
+
39
39
  module Format
40
-
41
-
40
+
41
+
42
42
  # Get the standard format.
43
43
  # This is identical to calling <tt>get('standard')</tt>.
44
- #
44
+ #
45
45
  # The standard format is designed to handle most commonly-used version
46
46
  # number forms, and allow parsing and comparison between them.
47
- #
47
+ #
48
48
  # The standard schema is the heart of this format, providing a
49
49
  # common structure for most version numbers.
50
- #
50
+ #
51
51
  # It begins with four numeric fields:
52
52
  # "<tt>major.minor.tiny.tiny2</tt>".
53
- #
53
+ #
54
54
  # The next field, <tt>:release_type</tt>, defines the remaining
55
55
  # structure. The release type can be one of these symbolic values:
56
56
  # <tt>:development</tt>, <tt>:alpha</tt>, <tt>:beta</tt>,
57
57
  # <tt>:preview</tt>, <tt>:release_candidate</tt>, <tt>:release</tt>.
58
- #
58
+ #
59
59
  # Depending on that value, additional fields become available. For
60
60
  # example, the <tt>:alpha</tt> value enables the fields
61
61
  # <tt>:alpha_version</tt> and <tt>:alpha_minor</tt>, which represent
@@ -65,11 +65,11 @@ module Versionomy
65
65
  # <tt>:beta_version</tt> and <tt>:beta_minor</tt>. A release_type
66
66
  # of <tt>:release</tt> enables <tt>:patchlevel</tt> and
67
67
  # <tt>:patchlevel_minor</tt>, to support versions like "1.8.7p72".
68
- #
68
+ #
69
69
  # The format itself is a delimiter-based format that understands a
70
70
  # wide variety of string representations of this version schema.
71
71
  # Examples of supported syntax include:
72
- #
72
+ #
73
73
  # 2.0
74
74
  # 2.0.42.10
75
75
  # 2.0b2
@@ -79,11 +79,11 @@ module Versionomy
79
79
  # 2.0 Alpha 1
80
80
  # 2.0a5.3
81
81
  # 2.1.42.10-4.3
82
- #
82
+ #
83
83
  # Because the standard format is based on Versionomy::Format::Delimiter,
84
84
  # a number of parameters are available for parsing and unparsing. See
85
85
  # the documentation for the delimiter class for more information.
86
- #
86
+ #
87
87
  # Two of the fields have styles that can be set when unparsing.
88
88
  # The <tt>:release_type</tt> field can be unparsed as either
89
89
  # <tt>:long</tt> style (e.g. "1.0alpha2") or <tt>:short</tt> style
@@ -91,57 +91,57 @@ module Versionomy
91
91
  # <tt>:number</tt> style (e.g. "2.1-1") or <tt>:letter</tt> style
92
92
  # (e.g. "2.1a"). Most fields can have their delimiter specified during
93
93
  # unparsing as well.
94
- #
94
+ #
95
95
  # For the exact annotated definition of the standard schema and format,
96
96
  # see the source code for Versionomy::Format::Standard#create.
97
-
97
+
98
98
  def self.standard
99
99
  get('standard')
100
100
  end
101
-
102
-
101
+
102
+
103
103
  # This is a namespace for the implementation of the Standard schema
104
104
  # and format.
105
-
105
+
106
106
  module Standard
107
-
108
-
107
+
108
+
109
109
  # Extra methods added to version values that use the standard schema.
110
-
110
+
111
111
  module ExtraMethods
112
-
113
-
112
+
113
+
114
114
  # Returns true if the version is a prerelease version
115
-
115
+
116
116
  def prerelease?
117
117
  self.release_type != :final
118
118
  end
119
-
120
-
119
+
120
+
121
121
  # Returns the release for this version.
122
122
  # For example, converts "1.2.0a1" to "1.2.0".
123
123
  # Non-prerelease versions return themselves.
124
-
124
+
125
125
  def release
126
126
  self.change(:release_type => :final)
127
127
  end
128
-
129
-
128
+
129
+
130
130
  end
131
-
132
-
131
+
132
+
133
133
  # Create the standard format.
134
134
  # This method is called internally when Versionomy loads the standard
135
135
  # format, and you should not need to call it again. It is documented
136
136
  # so that you can inspect its source code from RDoc, since the source
137
137
  # contains useful examples of how to use the schema and format
138
138
  # definition DSLs.
139
-
139
+
140
140
  def self.create
141
-
141
+
142
142
  # The following is the definition of the standard schema
143
143
  schema_ = Schema.create do
144
-
144
+
145
145
  # The major field has the default value of 1. Most other fields
146
146
  # have a default value of 0. Thus, the default version number
147
147
  # overall is "1.0".
@@ -150,46 +150,46 @@ module Versionomy
150
150
  field(:minor) do
151
151
  field(:tiny) do
152
152
  field(:tiny2) do
153
-
153
+
154
154
  # The next field is a symbolic field that specifies the
155
155
  # release type: e.g. beta, release candidate, release, etc.
156
156
  field(:release_type, :type => :symbol) do
157
-
157
+
158
158
  # Development releases are typically expressed like
159
159
  # "1.0d3" and are intended for unstable development
160
160
  # progress. Bumping the release type will change it to
161
161
  # alpha.
162
162
  symbol(:development, :bump => :alpha)
163
-
163
+
164
164
  # Alpha releases are typically expressed like "1.0a2" and
165
165
  # are intended for internal testing.
166
166
  # Bumping the release type advances to beta.
167
167
  symbol(:alpha, :bump => :beta)
168
-
168
+
169
169
  # Beta releases are typically expressed like "1.0b2" and
170
170
  # are intended for external or public testing.
171
171
  # Bumping the release type advances to release candidate.
172
172
  symbol(:beta, :bump => :release_candidate)
173
-
173
+
174
174
  # Release candidate releases are typically expressed like
175
175
  # "1.0rc2" and are intended for final public testing
176
176
  # prior to release.
177
177
  # Bumping the release type advances to final release.
178
178
  symbol(:release_candidate, :bump => :final)
179
-
179
+
180
180
  # Preview releases represent an alternative release type
181
181
  # progression, and are typically used for public testing
182
182
  # similar to beta or release candidate.
183
183
  # Bumping the release type advances to final release.
184
184
  symbol(:preview, :bump => :final)
185
-
185
+
186
186
  # This type represents a final release. This is the
187
187
  # default value for the release_type field if no value is
188
188
  # explicitly provided.
189
189
  # Bumping the release type has no effect.
190
190
  symbol(:final, :bump => :final)
191
191
  default_value(:final)
192
-
192
+
193
193
  # If the release type is development, these fields are
194
194
  # made available to indicate which development release
195
195
  # is being represented.
@@ -197,21 +197,21 @@ module Versionomy
197
197
  :default_value => 1) do
198
198
  field(:development_minor)
199
199
  end
200
-
200
+
201
201
  # If the release type is alpha, these fields are made
202
202
  # available to indicate which alpha release is being
203
203
  # represented.
204
204
  field(:alpha_version, :only => :alpha, :default_value => 1) do
205
205
  field(:alpha_minor)
206
206
  end
207
-
207
+
208
208
  # If the release type is beta, these fields are made
209
209
  # available to indicate which beta release is being
210
210
  # represented.
211
211
  field(:beta_version, :only => :beta, :default_value => 1) do
212
212
  field(:beta_minor)
213
213
  end
214
-
214
+
215
215
  # If the release type is release candidate, these fields
216
216
  # are made available to indicate which release candidate
217
217
  # is being represented.
@@ -219,14 +219,14 @@ module Versionomy
219
219
  :default_value => 1) do
220
220
  field(:release_candidate_minor)
221
221
  end
222
-
222
+
223
223
  # If the release type is preview, these fields are made
224
224
  # available to indicate which preview release is being
225
225
  # represented.
226
226
  field(:preview_version, :only => :preview, :default_value => 1) do
227
227
  field(:preview_minor)
228
228
  end
229
-
229
+
230
230
  # If the release type is final, these fields are made
231
231
  # available to indicate an optional patchlevel.
232
232
  field(:patchlevel, :only => :final) do
@@ -237,22 +237,22 @@ module Versionomy
237
237
  end
238
238
  end
239
239
  end
240
-
240
+
241
241
  # Add the methods in this module to each value
242
242
  add_module(Format::Standard::ExtraMethods)
243
243
  end
244
-
244
+
245
245
  # The following is the definition of the standard format. It
246
246
  # understands the standard schema defined above.
247
247
  format_ = Format::Delimiter.new(schema_) do
248
-
248
+
249
249
  # All version number strings must start with the major version.
250
250
  # Unlike other fields, it is not preceded by the usual "dot"
251
251
  # delimiter, but it can be preceded by a "v" indicator.
252
252
  field(:major) do
253
253
  recognize_number(:delimiter_regexp => '(v\s?)?', :default_delimiter => '')
254
254
  end
255
-
255
+
256
256
  # The remainder of the core version number are represented as
257
257
  # integers delimited by periods by default. Each is also dependent
258
258
  # on the presence of the previous field, so :requires_previous_field
@@ -267,7 +267,7 @@ module Versionomy
267
267
  field(:tiny2) do
268
268
  recognize_number(:default_value_optional => true)
269
269
  end
270
-
270
+
271
271
  # The release type field is the most complex field because of the
272
272
  # variety of syntaxes we support. The basic strategy is to map
273
273
  # a few specific sets of characters as signaling particular release
@@ -293,7 +293,7 @@ module Versionomy
293
293
  # because that value is signaled by the absence of any syntax in
294
294
  # the version string, including the absence of any delimiters.
295
295
  # So we just allow it to fall through to the default.
296
-
296
+
297
297
  recognize_regexp_map(:style => :long, :default_delimiter => '',
298
298
  :delimiter_regexp => '-|_|\.|\s?') do
299
299
  map(:development, 'dev')
@@ -318,7 +318,7 @@ module Versionomy
318
318
  map(:beta, 'b')
319
319
  end
320
320
  end
321
-
321
+
322
322
  # The main prerelease version may sometimes be optional, so we
323
323
  # mark it as optional here. If it is required, that will be
324
324
  # signalled by requires_next_field on the release_type field.
@@ -363,7 +363,7 @@ module Versionomy
363
363
  field(:preview_minor) do
364
364
  recognize_number(:default_value_optional => true)
365
365
  end
366
-
366
+
367
367
  # The patchlevel field does not require the previous field (which is
368
368
  # release_type). Here we also set up two styles: a numeric style and
369
369
  # a letter style. So "1.0a" and "1.0-1" are equivalent.
@@ -378,21 +378,21 @@ module Versionomy
378
378
  field(:patchlevel_minor) do
379
379
  recognize_number(:default_value_optional => true)
380
380
  end
381
-
381
+
382
382
  # By default, we require that at least the major and minor fields
383
383
  # appear in an unparsed version string.
384
384
  default_unparse_params(:required_fields => [:minor, :development_version, :alpha_version,
385
385
  :beta_version, :release_candidate_version, :preview_version])
386
386
  end
387
387
  end
388
-
389
-
388
+
389
+
390
390
  end
391
-
392
-
391
+
392
+
393
393
  register('standard', Format::Standard.create, true)
394
-
395
-
394
+
395
+
396
396
  end
397
-
397
+
398
398
  end
@@ -1,15 +1,15 @@
1
1
  # -----------------------------------------------------------------------------
2
- #
2
+ #
3
3
  # Versionomy convenience interface
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,61 +35,61 @@
35
35
 
36
36
 
37
37
  # == Versionomy
38
- #
38
+ #
39
39
  # The Versionomy module contains some convenience methods for creating and
40
40
  # parsing version numbers.
41
41
 
42
42
  module Versionomy
43
-
43
+
44
44
  @default_format = nil
45
-
46
-
45
+
46
+
47
47
  class << self
48
-
49
-
48
+
49
+
50
50
  # Gets the current default format. Usually this is the "standard"
51
51
  # format returned by Versionomy::Format.standard.
52
-
52
+
53
53
  def default_format
54
54
  @default_format ||= Format.standard
55
55
  end
56
-
57
-
56
+
57
+
58
58
  # Sets the default format used by other methods of this convenience
59
59
  # interface. Usually, this is set to the "standard" format returned by
60
60
  # Versionomy::Format.standard and should not be changed.
61
- #
61
+ #
62
62
  # The format can be specified as a format object or the name of a format
63
63
  # registered with Versionomy::Format. If the format is set to nil, the
64
64
  # default_format will be reset to the "standard" format.
65
- #
65
+ #
66
66
  # Raises Versionomy::Errors::UnknownFormatError if a name is given that
67
67
  # is not registered.
68
-
68
+
69
69
  def default_format=(format_)
70
70
  if format_.kind_of?(::String) || format_.kind_of?(::Symbol)
71
71
  format_ = Format.get(format_, true)
72
72
  end
73
73
  @default_format = format_
74
74
  end
75
-
76
-
75
+
76
+
77
77
  # Create a new version number given a hash or array of values, and an
78
78
  # optional format.
79
- #
79
+ #
80
80
  # The values should either be a hash of field names and values, or an
81
81
  # array of values that will be interpreted in field order.
82
- #
82
+ #
83
83
  # The format can be specified as a format object or the name of a format
84
84
  # registered with Versionomy::Format. If the format is omitted or set
85
85
  # to nil, the default_format will be used.
86
- #
86
+ #
87
87
  # You can also optionally provide default parameters to be used when
88
88
  # unparsing this value or any derived from it.
89
- #
89
+ #
90
90
  # Raises Versionomy::Errors::UnknownFormatError if a name is given that
91
91
  # is not registered.
92
-
92
+
93
93
  def create(values_=nil, format_=nil, unparse_params_=nil)
94
94
  if format_.kind_of?(::Hash) && unparse_params_.nil?
95
95
  unparse_params_ = format_
@@ -101,23 +101,23 @@ module Versionomy
101
101
  format_ ||= default_format
102
102
  Value.new(values_ || [], format_, unparse_params_)
103
103
  end
104
-
105
-
104
+
105
+
106
106
  # Create a new version number given a string to parse, and an optional
107
107
  # format.
108
- #
108
+ #
109
109
  # The format can be specified as a format object or the name of a format
110
110
  # registered with Versionomy::Format. If the format is omitted or set
111
111
  # to nil, the default_format will be used.
112
- #
112
+ #
113
113
  # The parameter hash, if present, will be passed as parsing parameters
114
114
  # to the format.
115
- #
115
+ #
116
116
  # Raises Versionomy::Errors::UnknownFormatError if a name is given that
117
117
  # is not registered.
118
- #
118
+ #
119
119
  # May raise Versionomy::Errors::ParseError if parsing failed.
120
-
120
+
121
121
  def parse(str_, format_=nil, parse_params_=nil)
122
122
  if format_.kind_of?(::Hash) && parse_params_.nil?
123
123
  parse_params_ = format_
@@ -129,11 +129,11 @@ module Versionomy
129
129
  format_ ||= default_format
130
130
  format_.parse(str_, parse_params_)
131
131
  end
132
-
133
-
132
+
133
+
134
134
  # Convenience method for creating a version number using the Semantic
135
135
  # Versioning format (see http://semver.org/).
136
- #
136
+ #
137
137
  # You may pass a string to parse, or a hash with the following keys, all
138
138
  # of which are optional:
139
139
  # <tt>:major</tt>::
@@ -144,9 +144,9 @@ module Versionomy
144
144
  # Patch version number
145
145
  # <tt>:prerelease_suffix</tt>::
146
146
  # A prerelease suffix (e.g. "b2")
147
- #
147
+ #
148
148
  # May raise Versionomy::Errors::ParseError if parsing failed.
149
-
149
+
150
150
  def semver(input_)
151
151
  if input_.kind_of?(::Hash)
152
152
  create(input_, :semver)
@@ -154,15 +154,15 @@ module Versionomy
154
154
  parse(input_.to_s, :semver)
155
155
  end
156
156
  end
157
-
158
-
157
+
158
+
159
159
  # Get the version of the given module as a Versionomy::Value.
160
160
  # Tries a number of common approaches to embedding version numbers into
161
161
  # modules, such as string or array constants, submodules containing
162
162
  # constants, or module method calls.
163
163
  # Returns the version number, or nil if it wasn't found or couldn't
164
164
  # be interpreted.
165
-
165
+
166
166
  def version_of(mod_)
167
167
  version_ = nil
168
168
  [:VERSION, :VERSION_STRING, :GemVersion].each do |sym_|
@@ -197,11 +197,11 @@ module Versionomy
197
197
  end
198
198
  version_
199
199
  end
200
-
201
-
200
+
201
+
202
202
  # Get the ruby version as a Versionomy::Value, using the builtin
203
203
  # constants RUBY_VERSION and RUBY_PATCHLEVEL.
204
-
204
+
205
205
  def ruby_version
206
206
  @ruby_version ||= begin
207
207
  version_ = parse(::RUBY_VERSION, :standard)
@@ -212,8 +212,8 @@ module Versionomy
212
212
  version_
213
213
  end
214
214
  end
215
-
216
-
215
+
216
+
217
217
  end
218
-
218
+
219
219
  end