lib/semantic_range.rb in semantic_range-3.0.0 vs lib/semantic_range.rb in semantic_range-3.1.0

- old
+ new

@@ -147,10 +147,13 @@ end true end def self.satisfies?(version, range, loose: false, platform: nil) + if valid?(range, loose: loose) + return version == range + end return false if !valid_range(range, loose: loose, platform: platform) Range.new(range, loose: loose, platform: platform).test(version) end def self.filter(versions, range, loose: false, platform: nil) @@ -219,10 +222,20 @@ def self.lte?(a, b, loose: false) compare(a, b, loose: loose) <= 0 end + def self.valid?(version, loose: false) + return false unless version.is_a?(String) + + stripped_version = version.strip + return false if stripped_version.length > MAX_LENGTH + + rxp = loose ? LOOSE : FULL + return rxp.match?(stripped_version) + end + def self.valid(version, loose: false) v = parse(version, loose: loose) return v ? v.version : nil end @@ -231,20 +244,12 @@ return s ? s.version : nil end def self.parse(version, loose: false) return version if version.is_a?(Version) + return nil unless valid?(version, loose: loose) - return nil unless version.is_a?(String) - - stripped_version = version.strip - - return nil if stripped_version.length > MAX_LENGTH - - rxp = loose ? LOOSE : FULL - return nil if !rxp.match(stripped_version) - - Version.new(stripped_version, loose: loose) + Version.new(version.strip, loose: loose) end def self.increment!(version, release, identifier, loose: false) Version.new(version, loose: loose).increment!(release, identifier).version rescue InvalidIncrement, InvalidVersion