Module: Versionomy::Conversion::Semver
- Defined in:
- lib/versionomy/format_definitions/semver.rb
Overview
This is a namespace for the implementation of the conversion between the semver and standard formats.
Class Method Summary collapse
-
.create_semver_to_standard ⇒ Object
Create the conversion from semver to standard format.
-
.create_standard_to_semver ⇒ Object
Create the conversion from standard to semver format.
Class Method Details
.create_semver_to_standard ⇒ Object
Create the conversion from semver to standard format. This method is called internally when Versionomy loads the semver 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.
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 |
# File 'lib/versionomy/format_definitions/semver.rb', line 243 def self.create_semver_to_standard # We'll use a parsing conversion. Conversion::Parsing.new do # Handle the case where the semver version ends with a string # field, e.g. "1.0b". We want to treat this like "1.0b0" rather # than "1.0-2" since the semver 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_semver ⇒ Object
Create the conversion from standard to semver format. This method is called internally when Versionomy loads the semver 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.
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/versionomy/format_definitions/semver.rb', line 186 def self.create_standard_to_semver # We'll use a parsing conversion. Conversion::Parsing.new do # Sanity check the original value and make sure it doesn't # include fields that we don't support. to_modify_original_value do |value_, convert_params_| if value_.has_field?(:patchlevel) && value_.patchlevel != 0 raise Errors::ConversionError, 'Cannot convert a version with a patchlevel to semver' end if value_.tiny2 != 0 raise Errors::ConversionError, 'Cannot convert a version more than three fields to semver' end value_ end # We're going to modify how the standard format version is # unparsed, so the semver format will have a better chance # of parsing it. to_modify_unparse_params do |params_, convert_params_| # All three fields are required params_[:minor_required] = true params_[:tiny_required] = true # If the standard format version has a prerelease notation, # make sure it isn't set off using a delimiter. params_[:release_type_delim] = '' params_[:development_version_delim] = '' params_[:development_minor_delim] = '-' params_[:alpha_version_delim] = '' params_[:alpha_minor_delim] = '-' params_[:beta_version_delim] = '' params_[:beta_minor_delim] = '-' params_[:release_candidate_version_delim] = '' params_[:release_candidate_minor_delim] = '-' params_[:preview_version_delim] = '' params_[:preview_minor_delim] = '-' # If the standard format version includes a "v" prefix, strip it params_[:major_delim] = nil params_ end end end |