versionomy 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,11 @@
1
+ === 0.4.0 / 2010-05-24
2
+
3
+ * Included Semantic Version (http://semver.org/) format called "semver".
4
+ * Parsing conversions can now prescreen or premodify the original format value.
5
+ * Conversion algorithm tries to convert through the standard format if a direct conversion isn't found. For example, there is currently no direct conversion between semver and rubygems formats, but the converter can nevertheless convert the two because both can convert to and from standard.
6
+ * Expanded the module version detection to include VERSION submodules.
7
+ * Some Rakefile fixes to match RDoc and Ruby 1.9 changes.
8
+
1
9
  === 0.3.0 / 2009-11-30
2
10
 
3
11
  * Alpha release, opened for public feedback
@@ -65,7 +73,6 @@
65
73
 
66
74
  === 0.1.0 / 2009-10-14
67
75
 
68
- * Alpha release, opened for public feedback
69
76
  * General rearchitecture. Better distinction between format and schema. Schema split into schema and field objects so the API makes more sense. Values are tighter and easier to use. Formats can now be built using a DSL. A bunch of API changes and bug fixes accompanied this-- too many to list.
70
77
  * In the standard schema, renamed release type "release" to "final". Also renamed release type "prerelease" to "preview", now sorted between "release candidate" and "final".
71
78
  * Documentation is much more complete.
@@ -143,7 +143,7 @@ Versionomy is written by Daniel Azuma (http://www.daniel-azuma.com/).
143
143
 
144
144
  == LICENSE:
145
145
 
146
- Copyright 2008-2009 Daniel Azuma.
146
+ Copyright 2008-2010 Daniel Azuma.
147
147
 
148
148
  All rights reserved.
149
149
 
data/Rakefile CHANGED
@@ -39,9 +39,11 @@ require 'rake/clean'
39
39
  require 'rake/gempackagetask'
40
40
  require 'rake/testtask'
41
41
  require 'rake/rdoctask'
42
+ require 'rdoc'
43
+ require 'rdoc/rdoc'
42
44
  require 'rdoc/generator/darkfish'
43
45
 
44
- require File.expand_path("#{File.dirname(__FILE__)}/lib/versionomy.rb")
46
+ require ::File.expand_path('lib/versionomy.rb', ::File.dirname(__FILE__))
45
47
 
46
48
 
47
49
  # Configuration
@@ -57,41 +59,41 @@ CLEAN.include(['doc', 'pkg'])
57
59
 
58
60
 
59
61
  # Test task
60
- Rake::TestTask.new('test') do |task_|
62
+ ::Rake::TestTask.new('test') do |task_|
61
63
  task_.pattern = 'tests/tc_*.rb'
62
64
  end
63
65
 
64
66
 
65
67
  # RDoc task
66
- Rake::RDocTask.new do |task_|
68
+ ::Rake::RDocTask.new do |task_|
67
69
  task_.main = 'README.rdoc'
68
70
  task_.rdoc_files.include(*extra_rdoc_files_)
69
71
  task_.rdoc_files.include('lib/versionomy/**/*.rb')
70
72
  task_.rdoc_dir = 'doc'
71
- task_.title = "Versionomy #{Versionomy::VERSION_STRING} documentation"
73
+ task_.title = "Versionomy #{::Versionomy::VERSION_STRING} documentation"
72
74
  task_.options << '-f' << 'darkfish'
73
75
  end
74
76
 
75
77
 
76
78
  # Gem task
77
- gemspec_ = Gem::Specification.new do |s_|
79
+ gemspec_ = ::Gem::Specification.new do |s_|
78
80
  s_.name = 'versionomy'
79
81
  s_.summary = 'Versionomy is a generalized version number library.'
80
- s_.version = Versionomy::VERSION_STRING
82
+ s_.version = ::Versionomy::VERSION_STRING.dup
81
83
  s_.author = 'Daniel Azuma'
82
84
  s_.email = 'dazuma@gmail.com'
83
85
  s_.description = 'Versionomy is a generalized version number library. It provides tools to represent, manipulate, parse, and compare version numbers in the wide variety of versioning schemes in use.'
84
86
  s_.homepage = 'http://virtuoso.rubyforge.org/versionomy'
85
87
  s_.rubyforge_project = 'virtuoso'
86
88
  s_.required_ruby_version = '>= 1.8.6'
87
- s_.files = FileList['lib/**/*.rb', 'tests/**/*.rb', '*.rdoc', 'Rakefile'].to_a
89
+ s_.files = ::FileList['lib/**/*.rb', 'tests/**/*.rb', '*.rdoc', 'Rakefile'].to_a
88
90
  s_.extra_rdoc_files = extra_rdoc_files_
89
91
  s_.has_rdoc = true
90
- s_.test_files = FileList['tests/tc_*.rb']
91
- s_.platform = Gem::Platform::RUBY
92
+ s_.test_files = ::FileList['tests/tc_*.rb']
93
+ s_.platform = ::Gem::Platform::RUBY
92
94
  s_.add_dependency('blockenspiel', '>= 0.3.1')
93
95
  end
94
- Rake::GemPackageTask.new(gemspec_) do |task_|
96
+ ::Rake::GemPackageTask.new(gemspec_) do |task_|
95
97
  task_.need_zip = false
96
98
  task_.need_tar = true
97
99
  end
@@ -100,7 +102,7 @@ end
100
102
  # Publish RDocs
101
103
  desc 'Publishes RDocs to RubyForge'
102
104
  task :publish_rdoc_to_rubyforge => [:rerdoc] do
103
- config_ = YAML.load(File.read(File.expand_path("~/.rubyforge/user-config.yml")))
105
+ config_ = ::YAML.load(::File.read(::File.expand_path("~/.rubyforge/user-config.yml")))
104
106
  username_ = config_['username']
105
107
  sh "rsync -av --delete doc/ #{username_}@rubyforge.org:/var/www/gforge-projects/virtuoso/versionomy"
106
108
  end
@@ -108,18 +110,18 @@ end
108
110
 
109
111
  # Publish gem
110
112
  task :release_gem_to_rubyforge => [:package] do |t_|
111
- v_ = ENV["VERSION"]
113
+ v_ = ::ENV["VERSION"]
112
114
  abort "Must supply VERSION=x.y.z" unless v_
113
- if v_ != Versionomy::VERSION_STRING
114
- abort "Versions don't match: #{v_} vs #{Versionomy::VERSION_STRING}"
115
+ if v_ != ::Versionomy::VERSION_STRING
116
+ abort "Versions don't match: #{v_} vs #{::Versionomy::VERSION_STRING}"
115
117
  end
116
118
  gem_pkg_ = "pkg/versionomy-#{v_}.gem"
117
119
  tgz_pkg_ = "pkg/versionomy-#{v_}.tgz"
118
- release_notes_ = File.read("README.rdoc").split(/^(==.*)/)[2].strip
119
- release_changes_ = File.read("History.rdoc").split(/^(===.*)/)[1..2].join.strip
120
+ release_notes_ = ::File.read("README.rdoc").split(/^(==.*)/)[2].strip
121
+ release_changes_ = ::File.read("History.rdoc").split(/^(===.*)/)[1..2].join.strip
120
122
 
121
123
  require 'rubyforge'
122
- rf_ = RubyForge.new.configure
124
+ rf_ = ::RubyForge.new.configure
123
125
  puts "Logging in to RubyForge"
124
126
  rf_.login
125
127
  config_ = rf_.userconfig
@@ -133,10 +135,10 @@ end
133
135
 
134
136
  # Publish gem
135
137
  task :release_gem_to_gemcutter => [:package] do |t_|
136
- v_ = ENV["VERSION"]
138
+ v_ = ::ENV["VERSION"]
137
139
  abort "Must supply VERSION=x.y.z" unless v_
138
- if v_ != Versionomy::VERSION_STRING
139
- abort "Versions don't match: #{v_} vs #{Versionomy::VERSION_STRING}"
140
+ if v_ != ::Versionomy::VERSION_STRING
141
+ abort "Versions don't match: #{v_} vs #{::Versionomy::VERSION_STRING}"
140
142
  end
141
143
  puts "Releasing versionomy #{v_} to GemCutter"
142
144
  `cd pkg && gem push versionomy-#{v_}.gem`
@@ -51,6 +51,16 @@ module Versionomy
51
51
  class Base
52
52
 
53
53
 
54
+ # Create a conversion using a simple DSL.
55
+ # You can pass a block to the initializer that takes the same
56
+ # parameters as convert_value, and the conversion will use that block
57
+ # to perform the conversion.
58
+
59
+ def initialize(&block_)
60
+ @_converter = block_
61
+ end
62
+
63
+
54
64
  # Convert the given value to the given format and return the converted
55
65
  # value.
56
66
  #
@@ -60,7 +70,11 @@ module Versionomy
60
70
  # Raises Versionomy::Errors::ConversionError if the conversion failed.
61
71
 
62
72
  def convert_value(value_, format_, convert_params_=nil)
63
- raise Errors::ConversionError, "Conversion not implemented"
73
+ if @_converter
74
+ @_converter.call(value_, format_, convert_params_)
75
+ else
76
+ raise Errors::ConversionError, "Conversion not implemented"
77
+ end
64
78
  end
65
79
 
66
80
 
@@ -60,6 +60,7 @@ module Versionomy
60
60
  if block_
61
61
  builder_ = Builder.new
62
62
  ::Blockenspiel.invoke(block_, builder_)
63
+ @original_value_modifier = builder_._get_original_value_modifier
63
64
  @string_modifier = builder_._get_string_modifier
64
65
  @unparse_params_modifier = builder_._get_unparse_params_modifier
65
66
  @parse_params_generator ||= builder_._get_parse_params_generator
@@ -77,7 +78,11 @@ module Versionomy
77
78
 
78
79
  def convert_value(value_, format_, convert_params_=nil)
79
80
  begin
80
- unparse_params_ = value_.unparse_params
81
+ convert_params_ ||= {}
82
+ if @original_value_modifier
83
+ value_ = @original_value_modifier.call(value_, convert_params_)
84
+ end
85
+ unparse_params_ = value_.unparse_params || {}
81
86
  if @unparse_params_modifier
82
87
  unparse_params_ = @unparse_params_modifier.call(unparse_params_, convert_params_)
83
88
  end
@@ -110,6 +115,7 @@ module Versionomy
110
115
 
111
116
 
112
117
  def initialize # :nodoc:
118
+ @original_value_modifier = nil
113
119
  @string_modifier = nil
114
120
  @parse_params_generator = nil
115
121
  @unparse_params_modifier = nil
@@ -138,6 +144,20 @@ module Versionomy
138
144
  end
139
145
 
140
146
 
147
+ # Provide a block that can modify the original value prior to it
148
+ # being unparsed. The block should take two parameters: first, the
149
+ # original value to be converted, and second, the convert_params
150
+ # passed to convert_value (which may be nil). It should return the
151
+ # value to be unparsed, which may be the same as the value
152
+ # originally passed in. This method may fail-fast by raising a
153
+ # Versionomy::Errors::ConversionError if it determines that the
154
+ # value passed in cannot be converted as is.
155
+
156
+ def to_modify_original_value(&block_)
157
+ @original_value_modifier = block_
158
+ end
159
+
160
+
141
161
  # Provide a block that can modify the unparsed string prior to
142
162
  # it being passed to the parser. The block should take two
143
163
  # parameters: first, the string resulting from unparsing the old
@@ -150,6 +170,10 @@ module Versionomy
150
170
  end
151
171
 
152
172
 
173
+ def _get_original_value_modifier # :nodoc:
174
+ @original_value_modifier
175
+ end
176
+
153
177
  def _get_string_modifier # :nodoc:
154
178
  @string_modifier
155
179
  end
@@ -113,8 +113,8 @@ module Versionomy
113
113
 
114
114
 
115
115
  # Create the rubygems format.
116
- # This method is called internally when Versionomy initializes itself,
117
- # and you should not need to call it again. It is documented, however,
116
+ # This method is called internally when Versionomy loads the rubygems
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.
@@ -182,8 +182,8 @@ module Versionomy
182
182
  add_module(Format::Rubygems::ExtraMethods)
183
183
  end
184
184
 
185
- # The following is the definition of the standard format. It
186
- # understands the standard schema defined above.
185
+ # The following is the definition of the rubygems format. It
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.
@@ -246,8 +246,8 @@ module Versionomy
246
246
 
247
247
 
248
248
  # Create the conversion from standard to rubygems format.
249
- # This method is called internally when Versionomy initializes itself,
250
- # and you should not need to call it again. It is documented, however,
249
+ # This method is called internally when Versionomy loads the rubygems
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
 
@@ -306,8 +306,8 @@ module Versionomy
306
306
 
307
307
 
308
308
  # Create the conversion from rubygems to standard format.
309
- # This method is called internally when Versionomy initializes itself,
310
- # and you should not need to call it again. It is documented, however,
309
+ # This method is called internally when Versionomy loads the rubygems
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
 
@@ -0,0 +1,272 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # Versionomy semver format implementation
4
+ #
5
+ # -----------------------------------------------------------------------------
6
+ # Copyright 2010 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 Format
40
+
41
+
42
+ # Get the semver format.
43
+ # This is identical to calling <tt>get('semver')</tt>.
44
+ #
45
+ # The semver format is designed to conform to the Semantic Versioning
46
+ # spec by Tom Preston-Warner. See http://semver.org/
47
+ #
48
+ # For the exact annotated definition of the semver schema and format,
49
+ # see the source code for Versionomy::Format::Semver#create.
50
+
51
+ def self.semver
52
+ get('semver')
53
+ end
54
+
55
+
56
+ # This is a namespace for the implementation of the semver schema
57
+ # and format.
58
+
59
+ module Semver
60
+
61
+
62
+ # Extra methods added to version values that use the semver schema.
63
+
64
+ module ExtraMethods
65
+
66
+
67
+ # Returns true if the version is a prerelease version-- that is,
68
+ # if the prerelease_suffix is nonempty.
69
+
70
+ def prerelease?
71
+ prerelease_suffix.length > 0
72
+ end
73
+
74
+
75
+ # Returns the release for this version.
76
+ # For example, converts "1.2.0a1" to "1.2.0".
77
+ # Non-prerelease versions return themselves unchanged.
78
+
79
+ def release
80
+ prerelease? ? self.change(:prerelease_suffix => '') : self
81
+ end
82
+
83
+
84
+ # Returns true if this version is compatible with the given version,
85
+ # according to the Semantic Versioning specification.
86
+ # For example, 1.1.0 is compatible with 1.0.0 but not vice versa,
87
+ # 1.1.1 and 1.1.0 are compatible with each other, while 1.0.0 and
88
+ # 2.0.0 are mutually incompatible.
89
+
90
+ def compatible_with?(version_)
91
+ self.major == version_.major ? self.minor >= version_.minor : false
92
+ end
93
+
94
+
95
+ end
96
+
97
+
98
+ # Create the semver format.
99
+ # This method is called internally when Versionomy loads the semver
100
+ # format, and you should not need to call it again. It is documented
101
+ # so that you can inspect its source code from RDoc, since the source
102
+ # contains useful examples of how to use the schema and format
103
+ # definition DSLs.
104
+
105
+ def self.create
106
+
107
+ # The following is the definition of the semver schema
108
+ schema_ = Schema.create do
109
+
110
+ # The first field has the default value of 1. All other fields
111
+ # have a default value of 0. Thus, the default version number
112
+ # overall is "1.0".
113
+ field(:major, :type => :integer, :default_value => 1) do
114
+ field(:minor, :type => :integer) do
115
+ field(:patch, :type => :integer) do
116
+ field(:prerelease_suffix, :type => :string) do
117
+ to_compare do |a_, b_|
118
+ a_.length == 0 ? (b_.length == 0 ? 0 : 1) : (b_.length == 0 ? -1 : a_ <=> b_)
119
+ end
120
+ end
121
+ end
122
+ end
123
+ end
124
+
125
+ # An alias
126
+ alias_field(:special_suffix, :prerelease_suffix)
127
+
128
+ # Add the methods in this module to each value
129
+ add_module(Format::Semver::ExtraMethods)
130
+ end
131
+
132
+ # The following is the definition of the standard format. It
133
+ # understands the standard schema defined above.
134
+ format_ = Format::Delimiter.new(schema_) do
135
+
136
+ # All version number strings must start with the major version.
137
+ # Unlike other fields, it is not preceded by the usual "dot"
138
+ # delimiter, but it can be preceded by a "v" indicator.
139
+ field(:major) do
140
+ recognize_number(:delimiter_regexp => 'v?', :default_delimiter => '')
141
+ end
142
+
143
+ # The remainder of the core version number are represented as
144
+ # integers delimited by periods. These fields are required.
145
+ field(:minor) do
146
+ recognize_number
147
+ end
148
+ field(:patch) do
149
+ recognize_number
150
+ end
151
+
152
+ # The optional prerelease field is represented as a string
153
+ # beginning with an alphabetic character.
154
+ field(:prerelease_suffix) do
155
+ recognize_regexp('[a-zA-Z][0-9a-zA-Z-]*', :default_value_optional => true,
156
+ :delimiter_regexp => '', :default_delimiter => '')
157
+ end
158
+ end
159
+ end
160
+
161
+
162
+ end
163
+
164
+
165
+ register('semver', Format::Semver.create, true)
166
+
167
+
168
+ end
169
+
170
+
171
+ module Conversion
172
+
173
+
174
+ # This is a namespace for the implementation of the conversion between
175
+ # the semver and standard formats.
176
+
177
+ module Semver
178
+
179
+
180
+ # Create the conversion from standard to semver format.
181
+ # This method is called internally when Versionomy loads the semver
182
+ # format, and you should not need to call it again. It is documented
183
+ # so that you can inspect its source code from RDoc, since the source
184
+ # contains useful examples of how to use the conversion DSLs.
185
+
186
+ def self.create_standard_to_semver
187
+
188
+ # We'll use a parsing conversion.
189
+ Conversion::Parsing.new do
190
+
191
+ # Sanity check the original value and make sure it doesn't
192
+ # include fields that we don't support.
193
+ to_modify_original_value do |value_, convert_params_|
194
+ if value_.has_field?(:patchlevel) && value_.patchlevel != 0
195
+ raise Errors::ConversionError, 'Cannot convert a version with a patchlevel to semver'
196
+ end
197
+ if value_.tiny2 != 0
198
+ raise Errors::ConversionError, 'Cannot convert a version more than three fields to semver'
199
+ end
200
+ value_
201
+ end
202
+
203
+ # We're going to modify how the standard format version is
204
+ # unparsed, so the semver format will have a better chance
205
+ # of parsing it.
206
+ to_modify_unparse_params do |params_, convert_params_|
207
+
208
+ # All three fields are required
209
+ params_[:minor_required] = true
210
+ params_[:tiny_required] = true
211
+
212
+ # If the standard format version has a prerelease notation,
213
+ # make sure it isn't set off using a delimiter.
214
+ params_[:release_type_delim] = ''
215
+ params_[:development_version_delim] = ''
216
+ params_[:development_minor_delim] = '-'
217
+ params_[:alpha_version_delim] = ''
218
+ params_[:alpha_minor_delim] = '-'
219
+ params_[:beta_version_delim] = ''
220
+ params_[:beta_minor_delim] = '-'
221
+ params_[:release_candidate_version_delim] = ''
222
+ params_[:release_candidate_minor_delim] = '-'
223
+ params_[:preview_version_delim] = ''
224
+ params_[:preview_minor_delim] = '-'
225
+
226
+ # If the standard format version includes a "v" prefix, strip it
227
+ params_[:major_delim] = nil
228
+
229
+ params_
230
+ end
231
+
232
+ end
233
+
234
+ end
235
+
236
+
237
+ # Create the conversion from semver to standard format.
238
+ # This method is called internally when Versionomy loads the semver
239
+ # format, and you should not need to call it again. It is documented
240
+ # so that you can inspect its source code from RDoc, since the source
241
+ # contains useful examples of how to use the conversion DSLs.
242
+
243
+ def self.create_semver_to_standard
244
+
245
+ # We'll use a parsing conversion.
246
+ Conversion::Parsing.new do
247
+
248
+ # Handle the case where the semver version ends with a string
249
+ # field, e.g. "1.0b". We want to treat this like "1.0b0" rather
250
+ # than "1.0-2" since the semver semantic states that this is a
251
+ # prerelease version. So we add 0 to the end of the parsed string
252
+ # if it ends in a letter.
253
+ to_modify_string do |str_, convert_params_|
254
+ str_.gsub(/([[:alpha:]])\z/, '\10')
255
+ end
256
+
257
+ end
258
+
259
+ end
260
+
261
+
262
+ end
263
+
264
+
265
+ register(:standard, :semver, Conversion::Semver.create_standard_to_semver, true)
266
+ register(:semver, :standard, Conversion::Semver.create_semver_to_standard, true)
267
+
268
+
269
+ end
270
+
271
+
272
+ end
@@ -131,8 +131,8 @@ module Versionomy
131
131
 
132
132
 
133
133
  # Create the standard format.
134
- # This method is called internally when Versionomy initializes itself,
135
- # and you should not need to call it again. It is documented, however,
134
+ # This method is called internally when Versionomy loads the standard
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.
@@ -131,22 +131,67 @@ module Versionomy
131
131
  end
132
132
 
133
133
 
134
+ # Convenience method for creating a version number using the Semantic
135
+ # Versioning format (see http://semver.org/).
136
+ #
137
+ # You may pass a string to parse, or a hash with the following keys, all
138
+ # of which are optional:
139
+ # <tt>:major</tt>::
140
+ # Major version number
141
+ # <tt>:minor</tt>::
142
+ # Minor version number
143
+ # <tt>:patch</tt>::
144
+ # Patch version number
145
+ # <tt>:prerelease_suffix</tt>::
146
+ # A prerelease suffix (e.g. "b2")
147
+ #
148
+ # May raise Versionomy::Errors::ParseError if parsing failed.
149
+
150
+ def semver(input_)
151
+ if input_.kind_of?(::Hash)
152
+ create(input_, :semver)
153
+ else
154
+ parse(input_.to_s, :semver)
155
+ end
156
+ end
157
+
158
+
134
159
  # Get the version of the given module as a Versionomy::Value.
135
- # Attempts to find the version by querying the constants VERSION and
136
- # VERSION_STRING. If a string is found, an attempt is made to parse it.
137
- # Returns the version number, or nil if it wasn't found or wasn't
138
- # parseable.
160
+ # Tries a number of common approaches to embedding version numbers into
161
+ # modules, such as string or array constants, submodules containing
162
+ # constants, or module method calls.
163
+ # Returns the version number, or nil if it wasn't found or couldn't
164
+ # be interpreted.
139
165
 
140
166
  def version_of(mod_)
141
- if mod_.const_defined?(:VERSION)
142
- version_ = mod_.const_get(:VERSION)
143
- elsif mod_.const_defined?(:VERSION_STRING)
144
- version_ = mod_.const_get(:VERSION_STRING)
145
- else
146
- version_ = nil
167
+ version_ = nil
168
+ [:VERSION, :VERSION_STRING, :GemVersion].each do |sym_|
169
+ if mod_.const_defined?(sym_)
170
+ version_ = mod_.const_get(sym_)
171
+ break
172
+ end
173
+ end
174
+ if version_.kind_of?(::Module)
175
+ if version_.const_defined?(:STRING)
176
+ version_ = version_.const_get(:STRING)
177
+ elsif version_.const_defined?(:VERSION)
178
+ version_ = version_.const_get(:VERSION)
179
+ elsif version_.const_defined?(:MAJOR) && version_.const_defined?(:MINOR) && version_.const_defined?(:TINY)
180
+ version_ = Value.new([version_.const_get(:MAJOR), version_.const_get(:MINOR), version_.const_get(:TINY)], :standard)
181
+ end
182
+ end
183
+ unless version_.kind_of?(::String) || version_.kind_of?(::Array) || version_.kind_of?(Value)
184
+ [:version, :release].each do |sym_|
185
+ if mod_.respond_to?(sym_)
186
+ version_ = mod_.send(sym_)
187
+ break
188
+ end
189
+ end
147
190
  end
148
191
  if version_.kind_of?(::String)
149
192
  version_ = parse(version_, :standard) rescue nil
193
+ elsif version_.kind_of?(::Array)
194
+ version_ = create(version_, :standard) rescue nil
150
195
  elsif !version_.kind_of?(Value)
151
196
  version_ = nil
152
197
  end
@@ -374,8 +374,20 @@ module Versionomy
374
374
  if from_schema_ == to_schema_
375
375
  return Value.new(@_values, format_, convert_params_)
376
376
  end
377
- conversion_ = Conversion.get(from_schema_, to_schema_, true)
378
- conversion_.convert_value(self, format_, convert_params_)
377
+ conversion_ = Conversion.get(from_schema_, to_schema_)
378
+ if conversion_
379
+ conversion_.convert_value(self, format_, convert_params_)
380
+ else
381
+ standard_format_ = Format.get(:standard)
382
+ conversion1_ = Conversion.get(from_schema_, standard_format_)
383
+ conversion2_ = Conversion.get(standard_format_, to_schema_)
384
+ if conversion1_ && conversion2_
385
+ value_ = conversion1_.convert_value(self, standard_format_, convert_params_)
386
+ conversion2_.convert_value(value_, format_, convert_params_)
387
+ else
388
+ raise Errors::UnknownConversionError
389
+ end
390
+ end
379
391
  end
380
392
 
381
393
 
@@ -37,7 +37,7 @@
37
37
  module Versionomy
38
38
 
39
39
  # Current gem version, as a frozen string.
40
- VERSION_STRING = '0.3.0'.freeze
40
+ VERSION_STRING = '0.4.0'.freeze
41
41
 
42
42
  # Current gem version, as a Versionomy::Value.
43
43
  VERSION = ::Versionomy.parse(VERSION_STRING, :standard)
@@ -161,7 +161,7 @@ module Versionomy
161
161
 
162
162
  # Test inequality comparisons between rubygems and standard
163
163
 
164
- def test_rubygems_to_standard_equality_comparison
164
+ def test_rubygems_to_standard_inequality_comparison
165
165
  assert_operator(::Versionomy.parse('1.2.3', :rubygems), :<, ::Versionomy.parse('1.2.4'))
166
166
  assert_operator(::Versionomy.parse('1.2.b.3', :rubygems), :>, ::Versionomy.parse('1.2b2'))
167
167
  assert_operator(::Versionomy.parse('1.2', :rubygems), :>, ::Versionomy.parse('1.2b1'))
@@ -0,0 +1,214 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # Versionomy basic tests on rubygems schema
4
+ #
5
+ # This file contains tests for the basic use cases on the rubygems 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 TestSemverBasic < ::Test::Unit::TestCase # :nodoc:
47
+
48
+
49
+ # Test the default version value.
50
+
51
+ def test_default_value
52
+ value_ = ::Versionomy.create(nil, :semver)
53
+ assert_equal(1, value_.major)
54
+ assert_equal(0, value_.minor)
55
+ assert_equal(0, value_.patch)
56
+ assert_equal('', value_.prerelease_suffix)
57
+ end
58
+
59
+
60
+ # Test an arbitrary value.
61
+
62
+ def test_arbitrary_value
63
+ value_ = ::Versionomy.create([1, 9, 2, 'pre2'], :semver)
64
+ assert_equal(1, value_.major)
65
+ assert_equal(9, value_.minor)
66
+ assert_equal(2, value_.patch)
67
+ assert_equal('pre2', value_.prerelease_suffix)
68
+ end
69
+
70
+
71
+ # Test aliases
72
+
73
+ def test_alias_fields
74
+ value_ = ::Versionomy.create([1, 9, 2, 'pre2'], :semver)
75
+ assert_equal('pre2', value_.special_suffix)
76
+ end
77
+
78
+
79
+ # Test construction using aliases
80
+
81
+ def test_alias_field_construction
82
+ value_ = ::Versionomy.create({:major => 1, :minor => 9, :special_suffix => 'pre2'}, :semver)
83
+ assert_equal([1, 9, 0, 'pre2'], value_.values_array)
84
+ end
85
+
86
+
87
+ # Test comparison of numeric values.
88
+
89
+ def test_numeric_comparison
90
+ value1_ = ::Versionomy.create([1, 9, 2], :semver)
91
+ value2_ = ::Versionomy.create([1, 9], :semver)
92
+ assert(value2_ < value1_)
93
+ value1_ = ::Versionomy.create([1, 9, 0], :semver)
94
+ value2_ = ::Versionomy.create([1, 9], :semver)
95
+ assert(value2_ == value1_)
96
+ end
97
+
98
+
99
+ # Test comparison of string values.
100
+
101
+ def test_string_comparison
102
+ value1_ = ::Versionomy.create([1, 9, 2, 'a2'], :semver)
103
+ value2_ = ::Versionomy.create([1, 9, 2, 'b1'], :semver)
104
+ assert(value2_ > value1_)
105
+ end
106
+
107
+
108
+ # Test comparison of numeric and string values.
109
+
110
+ def test_numeric_and_string_comparison
111
+ value1_ = ::Versionomy.create([1, 9, 2, 'a2'], :semver)
112
+ value2_ = ::Versionomy.create([1, 9, 2], :semver)
113
+ assert(value2_ > value1_)
114
+ end
115
+
116
+
117
+ # Test parsing numeric.
118
+
119
+ def test_parsing_numeric
120
+ value_ = ::Versionomy.parse('2.0.1', :semver)
121
+ assert_equal([2, 0, 1, ''], value_.values_array)
122
+ assert_equal('2.0.1', value_.unparse)
123
+ end
124
+
125
+
126
+ # Test parsing with a string.
127
+
128
+ def test_parsing_with_string
129
+ value_ = ::Versionomy.parse('1.9.2pre2', :semver)
130
+ assert_equal([1, 9, 2, 'pre2'], value_.values_array)
131
+ assert_equal('1.9.2pre2', value_.unparse)
132
+ end
133
+
134
+
135
+ # Test making sure unparsing requires all three fields.
136
+
137
+ def test_parsing_require_all_fields
138
+ value_ = ::Versionomy.parse('2.0', :semver)
139
+ assert_equal([2, 0, 0, ''], value_.values_array)
140
+ assert_equal('2.0.0', value_.unparse)
141
+ assert_raise(::Versionomy::Errors::ParseError) do
142
+ value_ = ::Versionomy.parse('2.0b1', :semver)
143
+ end
144
+ end
145
+
146
+
147
+ # Test convenience parsing
148
+
149
+ def test_convenience_parse
150
+ value_ = ::Versionomy.semver('2.0.1')
151
+ assert_equal([2, 0, 1, ''], value_.values_array)
152
+ end
153
+
154
+
155
+ # Test convenience creation from hash
156
+
157
+ def test_convenience_create
158
+ value_ = ::Versionomy.semver(:major => 2, :patch => 1, :prerelease_suffix => 'b2')
159
+ assert_equal([2, 0, 1, 'b2'], value_.values_array)
160
+ end
161
+
162
+
163
+ # Test bumping a numeric field.
164
+
165
+ def test_bump_numeric
166
+ value_ = ::Versionomy.create([1, 9, 2, 'a2'], :semver)
167
+ value_ = value_.bump(:patch)
168
+ assert_equal([1, 9, 3, ''], value_.values_array)
169
+ end
170
+
171
+
172
+ # Test bumping a string field.
173
+
174
+ def test_bump_string
175
+ value_ = ::Versionomy.create([1, 9, 2, 'a2'], :semver)
176
+ value_ = value_.bump(:prerelease_suffix)
177
+ assert_equal([1, 9, 2, 'a3'], value_.values_array)
178
+ end
179
+
180
+
181
+ # Test "prerelase?" custom method
182
+
183
+ def test_method_prereleasep
184
+ value_ = ::Versionomy.create([1, 9, 2, 'a2'], :semver)
185
+ assert_equal(true, value_.prerelease?)
186
+ value_ = ::Versionomy.create([1, 9, 2], :semver)
187
+ assert_equal(false, value_.prerelease?)
188
+ end
189
+
190
+
191
+ # Test marshalling
192
+
193
+ def test_marshal
194
+ value_ = ::Versionomy.create([1, 9, 2, 'pre2'], :semver)
195
+ str_ = ::Marshal.dump(value_)
196
+ value2_ = ::Marshal.load(str_)
197
+ assert_equal(value_, value2_)
198
+ end
199
+
200
+
201
+ # Test YAML
202
+
203
+ def test_yaml
204
+ value_ = ::Versionomy.create([1, 9, 2, 'pre2'], :semver)
205
+ str_ = ::YAML.dump(value_)
206
+ value2_ = ::YAML.load(str_)
207
+ assert_equal(value_, value2_)
208
+ end
209
+
210
+
211
+ end
212
+
213
+ end
214
+ end
@@ -0,0 +1,197 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # Versionomy tests on rubygems schema conversions
4
+ #
5
+ # This file contains tests converting to and from the rubygems 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 TestSemverConversions < ::Test::Unit::TestCase # :nodoc:
47
+
48
+
49
+ def setup
50
+ @standard_format = Format.get(:standard)
51
+ @semver_format = Format.get(:semver)
52
+ end
53
+
54
+
55
+ # Test simple conversion from standard to semver.
56
+
57
+ def test_standard_to_semver_simple
58
+ value_ = ::Versionomy.parse('1.2')
59
+ value2_ = value_.convert(:semver)
60
+ assert_equal(@semver_format, value2_.format)
61
+ assert_equal([1, 2, 0, ''], value2_.values_array)
62
+ value_ = ::Versionomy.parse('1.2.4')
63
+ value2_ = value_.convert(:semver)
64
+ assert_equal(@semver_format, value2_.format)
65
+ assert_equal([1, 2, 4, ''], value2_.values_array)
66
+ end
67
+
68
+
69
+ # Test conversion from standard to semver with a beta version
70
+
71
+ def test_standard_to_semver_beta
72
+ value_ = ::Versionomy.parse('1.2b3')
73
+ value2_ = value_.convert(:semver)
74
+ assert_equal([1, 2, 0, 'b3'], value2_.values_array)
75
+ value_ = ::Versionomy.parse('1.2 beta 3')
76
+ value2_ = value_.convert(:semver)
77
+ assert_equal([1, 2, 0, 'beta3'], value2_.values_array)
78
+ end
79
+
80
+
81
+ # Test conversion from standard to semver with a "v" prefix
82
+
83
+ def test_standard_to_semver_with_v
84
+ value_ = ::Versionomy.parse('v1.2.3')
85
+ value2_ = value_.convert(:semver)
86
+ assert_equal([1, 2, 3, ''], value2_.values_array)
87
+ value_ = ::Versionomy.parse('V 1.2.3')
88
+ value2_ = value_.convert(:semver)
89
+ assert_equal([1, 2, 3, ''], value2_.values_array)
90
+ end
91
+
92
+
93
+ # Test conversion from standard to semver with an expectation of failure
94
+
95
+ def test_standard_to_semver_fail
96
+ value_ = ::Versionomy.parse('1.2.3.4', :standard)
97
+ assert_raise(::Versionomy::Errors::ConversionError) do
98
+ value2_ = value_.convert(:semver)
99
+ end
100
+ end
101
+
102
+
103
+ # Test simple conversion from semver to standard.
104
+
105
+ def test_semver_to_standard_simple
106
+ value_ = ::Versionomy.parse('1.2', :semver)
107
+ value2_ = value_.convert(:standard)
108
+ assert_equal(@standard_format, value2_.format)
109
+ assert_equal([1, 2, 0, 0, :final, 0, 0], value2_.values_array)
110
+ value_ = ::Versionomy.parse('1.2.4', :semver)
111
+ value2_ = value_.convert(:standard)
112
+ assert_equal(@standard_format, value2_.format)
113
+ assert_equal([1, 2, 4, 0, :final, 0, 0], value2_.values_array)
114
+ end
115
+
116
+
117
+ # Test conversion from semver to standard with a beta version
118
+
119
+ def test_semver_to_standard_beta
120
+ value_ = ::Versionomy.parse('1.2.0b3', :semver)
121
+ value2_ = value_.convert(:standard)
122
+ assert_equal([1, 2, 0, 0, :beta, 3, 0], value2_.values_array)
123
+ value_ = ::Versionomy.parse('1.2.4beta3', :semver)
124
+ value2_ = value_.convert(:standard)
125
+ assert_equal([1, 2, 4, 0, :beta, 3, 0], value2_.values_array)
126
+ end
127
+
128
+
129
+ # Test conversion from rubygems to standard with an expectation of failure
130
+
131
+ def test_semver_to_standard_fail
132
+ value_ = ::Versionomy.parse('1.2.3c4', :semver)
133
+ assert_raise(::Versionomy::Errors::ConversionError) do
134
+ value2_ = value_.convert(:standard)
135
+ end
136
+ end
137
+
138
+
139
+ # Test conversion when there aren't unparse_params
140
+
141
+ def test_standard_to_semver_without_unparse_params
142
+ value_ = ::Versionomy.create([1,2,3], :standard)
143
+ value2_ = value_.convert(:semver)
144
+ assert_equal([1, 2, 3, ''], value2_.values_array)
145
+ end
146
+
147
+
148
+ # Test conversion between semver and rubygems
149
+
150
+ def test_semver_and_rubygems
151
+ value_ = ::Versionomy.create([1,2,3], :semver)
152
+ value2_ = value_.convert(:rubygems)
153
+ assert_equal([1, 2, 3, 0, 0, 0, 0, 0], value2_.values_array)
154
+ value_ = ::Versionomy.create([1,2,3], :rubygems)
155
+ value2_ = value_.convert(:semver)
156
+ assert_equal([1, 2, 3, ''], value2_.values_array)
157
+ end
158
+
159
+
160
+ # Test equality comparisons between semver and standard
161
+
162
+ def test_semver_to_standard_equality_comparison
163
+ assert_operator(::Versionomy.parse('1.2.0', :semver), :==, ::Versionomy.parse('1.2'))
164
+ assert_operator(::Versionomy.parse('1.2.0b3', :semver), :==, ::Versionomy.parse('1.2b3'))
165
+ end
166
+
167
+
168
+ # Test inequality comparisons between semver and standard
169
+
170
+ def test_semver_to_standard_inequality_comparison
171
+ assert_operator(::Versionomy.parse('1.2.3', :semver), :<, ::Versionomy.parse('1.2.4'))
172
+ assert_operator(::Versionomy.parse('1.2.0b3', :semver), :>, ::Versionomy.parse('1.2b2'))
173
+ assert_operator(::Versionomy.parse('1.2.0', :semver), :>, ::Versionomy.parse('1.2b1'))
174
+ end
175
+
176
+
177
+ # Test equality comparisons between standard and rubygems
178
+
179
+ def test_standard_to_semver_equality_comparison
180
+ assert_operator(::Versionomy.parse('1.2.0'), :==, ::Versionomy.parse('1.2.0', :semver))
181
+ assert_operator(::Versionomy.parse('1.2b3'), :==, ::Versionomy.parse('1.2.0beta3', :semver))
182
+ end
183
+
184
+
185
+ # Test inequality comparisons between standard and rubygems
186
+
187
+ def test_standard_to_semver_inequality_comparison
188
+ assert_operator(::Versionomy.parse('1.2.4'), :>, ::Versionomy.parse('1.2.3', :semver))
189
+ assert_operator(::Versionomy.parse('1.2b2'), :<, ::Versionomy.parse('1.2.0beta3', :semver))
190
+ assert_operator(::Versionomy.parse('1.2b2'), :<, ::Versionomy.parse('1.2.0', :semver))
191
+ end
192
+
193
+
194
+ end
195
+
196
+ end
197
+ end
@@ -0,0 +1,82 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # Versionomy basic tests on standard schema
4
+ #
5
+ # This file contains tests for the basic use cases 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 TestVersionOf < ::Test::Unit::TestCase # :nodoc:
47
+
48
+
49
+ # Gems to test if we can
50
+ GEM_LIST = {
51
+ 'activerecord' => {:require => 'active_record', :module_name => 'ActiveRecord'},
52
+ 'blockenspiel' => {:module_name => 'Blockenspiel'},
53
+ 'bundler' => {:module_name => 'Bundler'},
54
+ 'erubis' => {:module_name => 'Erubis'},
55
+ }
56
+
57
+
58
+ # Engine that tests each gem if it's installed
59
+ zero_ = ::Versionomy.create(:major => 0)
60
+ GEM_LIST.each do |name_, data_|
61
+ unless data_.kind_of?(::Hash)
62
+ data_ = {:module_name => data_}
63
+ end
64
+ begin
65
+ gem name_
66
+ require data_[:require] || name_
67
+ rescue ::LoadError
68
+ next
69
+ end
70
+ define_method("test_gem_#{name_}") do
71
+ mod_ = eval(data_[:module_name])
72
+ value_ = ::Versionomy.version_of(mod_)
73
+ assert_not_nil(value_)
74
+ assert_not_equal(zero_, value_)
75
+ end
76
+ end
77
+
78
+
79
+ end
80
+
81
+ end
82
+ end
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: versionomy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ hash: 15
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 4
9
+ - 0
10
+ version: 0.4.0
5
11
  platform: ruby
6
12
  authors:
7
13
  - Daniel Azuma
@@ -9,19 +15,25 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2009-11-30 00:00:00 -08:00
18
+ date: 2010-05-24 00:00:00 -07:00
13
19
  default_executable:
14
20
  dependencies:
15
21
  - !ruby/object:Gem::Dependency
16
22
  name: blockenspiel
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
20
26
  requirements:
21
27
  - - ">="
22
28
  - !ruby/object:Gem::Version
29
+ hash: 17
30
+ segments:
31
+ - 0
32
+ - 3
33
+ - 1
23
34
  version: 0.3.1
24
- version:
35
+ type: :runtime
36
+ version_requirements: *id001
25
37
  description: Versionomy is a generalized version number library. It provides tools to represent, manipulate, parse, and compare version numbers in the wide variety of versioning schemes in use.
26
38
  email: dazuma@gmail.com
27
39
  executables: []
@@ -41,6 +53,7 @@ files:
41
53
  - lib/versionomy/format/delimiter.rb
42
54
  - lib/versionomy/format.rb
43
55
  - lib/versionomy/format_definitions/rubygems.rb
56
+ - lib/versionomy/format_definitions/semver.rb
44
57
  - lib/versionomy/format_definitions/standard.rb
45
58
  - lib/versionomy/interface.rb
46
59
  - lib/versionomy/schema/field.rb
@@ -53,6 +66,8 @@ files:
53
66
  - tests/tc_readme_examples.rb
54
67
  - tests/tc_rubygems_basic.rb
55
68
  - tests/tc_rubygems_conversions.rb
69
+ - tests/tc_semver_basic.rb
70
+ - tests/tc_semver_conversions.rb
56
71
  - tests/tc_standard_basic.rb
57
72
  - tests/tc_standard_bump.rb
58
73
  - tests/tc_standard_change.rb
@@ -60,6 +75,7 @@ files:
60
75
  - tests/tc_standard_misc.rb
61
76
  - tests/tc_standard_parse.rb
62
77
  - tests/tc_standard_reset.rb
78
+ - tests/tc_version_of.rb
63
79
  - History.rdoc
64
80
  - README.rdoc
65
81
  - Versionomy.rdoc
@@ -74,21 +90,29 @@ rdoc_options: []
74
90
  require_paths:
75
91
  - lib
76
92
  required_ruby_version: !ruby/object:Gem::Requirement
93
+ none: false
77
94
  requirements:
78
95
  - - ">="
79
96
  - !ruby/object:Gem::Version
97
+ hash: 59
98
+ segments:
99
+ - 1
100
+ - 8
101
+ - 6
80
102
  version: 1.8.6
81
- version:
82
103
  required_rubygems_version: !ruby/object:Gem::Requirement
104
+ none: false
83
105
  requirements:
84
106
  - - ">="
85
107
  - !ruby/object:Gem::Version
108
+ hash: 3
109
+ segments:
110
+ - 0
86
111
  version: "0"
87
- version:
88
112
  requirements: []
89
113
 
90
114
  rubyforge_project: virtuoso
91
- rubygems_version: 1.3.5
115
+ rubygems_version: 1.3.7
92
116
  signing_key:
93
117
  specification_version: 3
94
118
  summary: Versionomy is a generalized version number library.
@@ -97,6 +121,8 @@ test_files:
97
121
  - tests/tc_readme_examples.rb
98
122
  - tests/tc_rubygems_basic.rb
99
123
  - tests/tc_rubygems_conversions.rb
124
+ - tests/tc_semver_basic.rb
125
+ - tests/tc_semver_conversions.rb
100
126
  - tests/tc_standard_basic.rb
101
127
  - tests/tc_standard_bump.rb
102
128
  - tests/tc_standard_change.rb
@@ -104,3 +130,4 @@ test_files:
104
130
  - tests/tc_standard_misc.rb
105
131
  - tests/tc_standard_parse.rb
106
132
  - tests/tc_standard_reset.rb
133
+ - tests/tc_version_of.rb