module Versionomy::Conversion::Rubygems

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

Public Class Methods

create_rubygems_to_standard() click to toggle source

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.

# 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_rubygems() click to toggle source

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.

# 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