Object
A Requirement is a set of one or more version restrictions. It supports a few (=, !=, >, <, >=, <=, ~>) different restriction operators.
Factory method to create a Gem::Requirement object. Input may be a Version, a String, or nil. Intended to simplify client code.
If the input is “weird”, the default version requirement is returned.
# File lib/rubygems/requirement.rb, line 30 30: def self.create input 31: case input 32: when Gem::Requirement then 33: input 34: when Gem::Version, Array then 35: new input 36: else 37: if input.respond_to? :to_str then 38: new [input.to_str] 39: else 40: default 41: end 42: end 43: end
A default “version requirement” can surely only be ’>= 0’.
# File lib/rubygems/requirement.rb, line 52 52: def self.default 53: new '>= 0' 54: end
Constructs a requirement from requirements. Requirements can be Strings, Gem::Versions, or Arrays of those. nil and duplicate requirements are ignored. An empty set of requirements is the same as ">= 0".
# File lib/rubygems/requirement.rb, line 90 90: def initialize *requirements 91: requirements = requirements.flatten 92: requirements.compact! 93: requirements.uniq! 94: 95: requirements << ">= 0" if requirements.empty? 96: @none = (requirements == ">= 0") 97: @requirements = requirements.map! { |r| self.class.parse r } 98: end
Parse obj, returning an [op, version] pair. obj can be a String or a Gem::Version.
If obj is a String, it can be either a full requirement specification, like ">= 1.2", or a simple version number, like "1.2".
parse("> 1.0") # => [">", "1.0"] parse("1.0") # => ["=", "1.0"] parse(Gem::Version.new("1.0")) # => ["=, "1.0"]
# File lib/rubygems/requirement.rb, line 68 68: def self.parse obj 69: return ["=", obj] if Gem::Version === obj 70: 71: unless PATTERN =~ obj.to_s 72: raise ArgumentError, "Illformed requirement [#{obj.inspect}]" 73: end 74: 75: [$1 || "=", Gem::Version.new($2)] 76: end
# File lib/rubygems/requirement.rb, line 100 100: def none? 101: @none ||= (to_s == ">= 0") 102: end
# File lib/rubygems/requirement.rb, line 136 136: def prerelease? 137: requirements.any? { |r| r.last.prerelease? } 138: end
True if version satisfies this Requirement.
# File lib/rubygems/requirement.rb, line 149 149: def satisfied_by? version 150: # #28965: syck has a bug with unquoted '=' YAML.loading as YAML::DefaultKey 151: requirements.all? { |op, rv| (OPS[op] || OPS["="]).call version, rv } 152: end
True if the requirement will not always match the latest version.
# File lib/rubygems/requirement.rb, line 160 160: def specific? 161: return true if @requirements.length > 1 # GIGO, > 1, > 2 is silly 162: 163: not ]> >=].include? @requirements.first.first # grab the operator 164: end
# File lib/rubygems/requirement.rb, line 176 176: def fix_syck_default_key_in_requirements 177: # Fixup the Syck DefaultKey bug 178: @requirements.each do |r| 179: if r[0].kind_of? Gem::SyckDefaultKey 180: r[0] = "=" 181: end 182: end 183: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.