Module: Versionomy::Conversion::Rubygems

Defined in:
lib/versionomy/format_definitions/rubygems.rb

Overview

This is a namespace for the implementation of the conversion between the rubygems and standard formats.

Class Method Summary collapse

Class Method Details

.create_rubygems_to_standardObject

Create the conversion from rubygems to standard format. This method is called internally when Versionomy loads the rubygems format, and you should not need to call it again. It is documented so that you can inspect its source code from RDoc, since the source contains useful examples of how to use the conversion DSLs.



314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
# File 'lib/versionomy/format_definitions/rubygems.rb', line 314

def self.create_rubygems_to_standard
  
  # We'll use a parsing conversion.
  Conversion::Parsing.new do
    
    # Handle the case where the rubygems version ends with a string
    # field, e.g. "1.0.b". We want to treat this like "1.0b0" rather
    # than "1.0-2" since the rubygems semantic states that this is a
    # prerelease version. So we add 0 to the end of the parsed string
    # if it ends in a letter.
    to_modify_string do |str_, convert_params_|
      str_.gsub(/([[:alpha:]])\z/, '\10')
    end
    
  end
  
end

.create_standard_to_rubygemsObject

Create the conversion from standard to rubygems format. This method is called internally when Versionomy loads the rubygems format, and you should not need to call it again. It is documented so that you can inspect its source code from RDoc, since the source contains useful examples of how to use the conversion DSLs.



254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
# File 'lib/versionomy/format_definitions/rubygems.rb', line 254

def self.create_standard_to_rubygems
  
  # We'll use a parsing conversion.
  Conversion::Parsing.new do
    
    # We're going to modify how the standard format version is
    # unparsed, so the rubygems format will have a better chance
    # of parsing it.
    to_modify_unparse_params do |params_, convert_params_|
      
      params_ ||= {}
      
      # If the standard format version has a prerelease notation,
      # make sure it is set off using a delimiter that the rubygems
      # format can recognize. So instead of "1.0b2", we force the
      # unparsing to generate "1.0.b.2".
      params_[:release_type_delim] = '.'
      params_[:development_version_delim] = '.'
      params_[:alpha_version_delim] = '.'
      params_[:beta_version_delim] = '.'
      params_[:release_candidate_version_delim] = '.'
      params_[:preview_version_delim] = '.'
      
      # If the standard format version has a patchlevel notation,
      # force it to use the default number rather than letter style.
      # So instead of "1.2c", we force the unparsing to generate
      # "1.2-3".
      params_[:patchlevel_style] = nil
      
      # If the standard format version has a patchlevel notation,
      # force it to use the default delimiter of "-" so the rubygems
      # format will recognize it. So instead of "1.9.1p243", we force
      # the unparsing to generate "1.9.1-243".
      params_[:patchlevel_delim] = nil
      
      # If the standard format version includes a "v" prefix, strip
      # it because rubygems doesn't like it.
      params_[:major_delim] = nil
      
      params_
    end
    
    # Standard formats sometimes allow hyphens and spaces in field
    # delimiters, but the rubygems format requires periods. So modify
    # the unparsed string to conform to rubygems's expectations.
    to_modify_string do |str_, convert_params_|
      str_.gsub(/[\.\s-]+/, '.')
    end
    
  end
  
end