Sha256: b5ad071d6daa601ae685ab69658ba8f7eedaa31ae9c2b7dbfc68df0a08afbbc3
Contents?: true
Size: 1.7 KB
Versions: 1
Compression:
Stored size: 1.7 KB
Contents
module MetadataJsonLint # Parses a string module version requirement with semantic_puppet and # provides methods to analyse it for lint warnings class VersionRequirement def initialize(requirement) @requirement = requirement if defined?(SemanticPuppet::VersionRange) @range = SemanticPuppet::VersionRange.parse(requirement) raise ArgumentError, "Range matches no versions: \"#{requirement}\"" if @range == SemanticPuppet::VersionRange::EMPTY_RANGE elsif requirement.match(/\A[a-z0-9*.\-^~><=|\t ]*\Z/i).nil? raise ArgumentError, "Unparsable version range: \"#{requirement}\"" end end # Whether the range uses a comparison operator (e.g. >=) with a wildcard # syntax, such as ">= 1.x" or "< 2.0.x" def mixed_syntax? !/ [><=^~]{1,2} # comparison operators \s* \d\. # MAJOR (?: (?:x|\*) # MINOR is wildcard | \d\.(?:x|\*) # MINOR is digit and PATCH is wildcard ) /x.match(requirement).nil? end def open_ended? if range range.end == SemanticPuppet::Version::MAX else # Empty requirement strings are open-ended. return true if requirement.strip.empty? # Strip superfluous whitespace. range_set = requirement.gsub(/([><=~^])(?:\s+|\s*v)/, '\1') # Split on logical OR ranges = range_set.split(/\s*\|\|\s*/) # Returns true if any range includes a '>' but not a corresponding '<' # which should be the only way to declare an open-ended range. ranges.select { |r| r.include?('>') }.any? { |r| !r.include?('<') } end end private attr_reader :range, :requirement end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
metadata-json-lint-2.1.0 | lib/metadata-json-lint/version_requirement.rb |