lib/mixlib/versioning/format/semver.rb in mixlib-versioning-1.0.0 vs lib/mixlib/versioning/format/semver.rb in mixlib-versioning-1.1.0

- old
+ new

@@ -1,8 +1,8 @@ # -# Author:: Seth Chisamore (<schisamo@opscode.com>) -# Author:: Christopher Maier (<cm@opscode.com>) +# Author:: Seth Chisamore (<schisamo@chef.io>) +# Author:: Christopher Maier (<cm@chef.io>) # Copyright:: Copyright (c) 2013 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -26,41 +26,39 @@ # ----------------- # ```text # MAJOR.MINOR.PATCH # MAJOR.MINOR.PATCH-PRERELEASE # MAJOR.MINOR.PATCH-PRERELEASE+BUILD - #``` + # ``` # # EXAMPLES # -------- # ```text # 11.0.0 # 11.0.0-alpha.1 # 11.0.0-alpha1+20121218164140 # 11.0.0-alpha1+20121218164140.git.207.694b062 # ``` # - # @author Seth Chisamore (<schisamo@opscode.com>) - # @author Christopher Maier (<cm@opscode.com>) + # @author Seth Chisamore (<schisamo@chef.io>) + # @author Christopher Maier (<cm@chef.io>) class SemVer < Format + SEMVER_REGEX = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][a-zA-Z0-9-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][a-zA-Z0-9-]*))*))?(?:\+([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?$/ - SEMVER_REGEX = /^(\d+)\.(\d+)\.(\d+)(?:\-([\dA-Za-z\-\.]+))?(?:\+([\dA-Za-z\-\.]+))?$/ - # @see Format#parse def parse(version_string) match = version_string.match(SEMVER_REGEX) rescue nil unless match - raise Mixlib::Versioning::ParseError, "'#{version_string}' is not a valid #{self.class} version string!" + fail Mixlib::Versioning::ParseError, "'#{version_string}' is not a valid #{self.class} version string!" end @major, @minor, @patch, @prerelease, @build = match[1..5] @major, @minor, @patch = [@major, @minor, @patch].map(&:to_i) - @prerelease = nil if (@prerelease.nil? || @prerelease.empty?) - @build = nil if (@build.nil? || @build.empty?) + @prerelease = nil if @prerelease.nil? || @prerelease.empty? + @build = nil if @build.nil? || @build.empty? end - end # class SemVer end # class Format end # module Versioning end # module Mixlib