Class: Pod::Vendor::Gem::Requirement
- Inherits:
-
Object
- Object
- Pod::Vendor::Gem::Requirement
- Includes:
- Comparable
- Defined in:
- lib/cocoapods-core/vendor/requirement.rb
Overview
require “rubygems/version” require “rubygems/deprecate”
Direct Known Subclasses
Constant Summary collapse
- OPS =
:nodoc:
{ #:nodoc: "=" => lambda { |v, r| v == r }, "!=" => lambda { |v, r| v != r }, ">" => lambda { |v, r| v > r }, "<" => lambda { |v, r| v < r }, ">=" => lambda { |v, r| v >= r }, "<=" => lambda { |v, r| v <= r }, "~>" => lambda { |v, r| v >= r && v.release < r.bump } }
- PATTERN =
/\A\s*(#{quoted})?\s*(#{Gem::Version::VERSION_PATTERN})\s*\z/
Instance Attribute Summary collapse
-
#requirements ⇒ Object
readonly
An array of requirement pairs.
Class Method Summary collapse
-
.create(input) ⇒ Object
Factory method to create a Gem::Requirement object.
-
.default ⇒ Object
A default “version requirement” can surely only be ‘>= 0’.
-
.parse(obj) ⇒ Object
Parse
obj
, returning an[op, version]
pair.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
:nodoc:.
-
#as_list ⇒ Object
:nodoc:.
-
#hash ⇒ Object
:nodoc:.
-
#init_with(coder) ⇒ Object
:nodoc:.
-
#initialize(*requirements) ⇒ Requirement
constructor
Constructs a requirement from
requirements
. -
#marshal_dump ⇒ Object
:nodoc:.
-
#marshal_load(array) ⇒ Object
:nodoc:.
- #none? ⇒ Boolean
- #prerelease? ⇒ Boolean
-
#pretty_print(q) ⇒ Object
:nodoc:.
-
#satisfied_by?(version) ⇒ Boolean
(also: #===, #=~)
True if
version
satisfies this Requirement. -
#specific? ⇒ Boolean
True if the requirement will not always match the latest version.
-
#to_s ⇒ Object
:nodoc:.
-
#yaml_initialize(tag, vals) ⇒ Object
:nodoc:.
Constructor Details
#initialize(*requirements) ⇒ Requirement
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"
.
101 102 103 104 105 106 107 108 109 |
# File 'lib/cocoapods-core/vendor/requirement.rb', line 101 def initialize(*requirements) requirements = requirements.flatten requirements.compact! requirements.uniq! requirements << ">= 0" if requirements.empty? @none = (requirements == ">= 0") @requirements = requirements.map! { |r| self.class.parse r } end |
Instance Attribute Details
#requirements ⇒ Object (readonly)
An array of requirement pairs. The first element of the pair is the op, and the second is the Gem::Version.
93 94 95 |
# File 'lib/cocoapods-core/vendor/requirement.rb', line 93 def requirements @requirements end |
Class Method Details
.create(input) ⇒ Object
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.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/cocoapods-core/vendor/requirement.rb', line 41 def self.create(input) case input when Gem::Requirement then input when Gem::Version, Array then new input else if input.respond_to? :to_str then new [input.to_str] else default end end end |
.default ⇒ Object
A default “version requirement” can surely only be ‘>= 0’. – This comment once said:
“A default ”version requirement“ can surely only be ‘> 0’.”
63 64 65 |
# File 'lib/cocoapods-core/vendor/requirement.rb', line 63 def self.default new '>= 0' end |
.parse(obj) ⇒ Object
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"]
79 80 81 82 83 84 85 86 87 |
# File 'lib/cocoapods-core/vendor/requirement.rb', line 79 def self.parse(obj) return ["=", obj] if Gem::Version === obj unless PATTERN =~ obj.to_s raise ArgumentError, "Illformed requirement [#{obj.inspect}]" end [Regexp.last_match[1] || "=", Gem::Version.new(Regexp.last_match[2])] end |
Instance Method Details
#<=>(other) ⇒ Object
:nodoc:
181 182 183 |
# File 'lib/cocoapods-core/vendor/requirement.rb', line 181 def <=>(other) # :nodoc: to_s <=> other.to_s end |
#as_list ⇒ Object
:nodoc:
115 116 117 |
# File 'lib/cocoapods-core/vendor/requirement.rb', line 115 def as_list # :nodoc: requirements.map { |op, version| "#{op} #{version}" }.sort end |
#hash ⇒ Object
:nodoc:
119 120 121 |
# File 'lib/cocoapods-core/vendor/requirement.rb', line 119 def hash # :nodoc: requirements.hash end |
#init_with(coder) ⇒ Object
:nodoc:
143 144 145 |
# File 'lib/cocoapods-core/vendor/requirement.rb', line 143 def init_with(coder) # :nodoc: yaml_initialize coder.tag, coder.map end |
#marshal_dump ⇒ Object
:nodoc:
123 124 125 126 127 |
# File 'lib/cocoapods-core/vendor/requirement.rb', line 123 def marshal_dump # :nodoc: fix_syck_default_key_in_requirements [@requirements] end |
#marshal_load(array) ⇒ Object
:nodoc:
129 130 131 132 133 |
# File 'lib/cocoapods-core/vendor/requirement.rb', line 129 def marshal_load(array) # :nodoc: @requirements = array[0] fix_syck_default_key_in_requirements end |
#none? ⇒ Boolean
111 112 113 |
# File 'lib/cocoapods-core/vendor/requirement.rb', line 111 def none? @none ||= (to_s == ">= 0") end |
#prerelease? ⇒ Boolean
147 148 149 |
# File 'lib/cocoapods-core/vendor/requirement.rb', line 147 def prerelease? requirements.any? { |r| r.last.prerelease? } end |
#pretty_print(q) ⇒ Object
:nodoc:
151 152 153 154 155 |
# File 'lib/cocoapods-core/vendor/requirement.rb', line 151 def pretty_print(q) # :nodoc: q.group 1, 'Gem::Requirement.new(', ')' do q.pp as_list end end |
#satisfied_by?(version) ⇒ Boolean Also known as: ===, =~
True if version
satisfies this Requirement.
160 161 162 163 |
# File 'lib/cocoapods-core/vendor/requirement.rb', line 160 def satisfied_by?(version) # #28965: syck has a bug with unquoted '=' YAML.loading as YAML::DefaultKey requirements.all? { |op, rv| (OPS[op] || OPS["="]).call version, rv } end |
#specific? ⇒ Boolean
True if the requirement will not always match the latest version.
171 172 173 174 175 |
# File 'lib/cocoapods-core/vendor/requirement.rb', line 171 def specific? return true if @requirements.length > 1 # GIGO, > 1, > 2 is silly not %w(> >=).include? @requirements.first.first # grab the operator end |
#to_s ⇒ Object
:nodoc:
177 178 179 |
# File 'lib/cocoapods-core/vendor/requirement.rb', line 177 def to_s # :nodoc: as_list.join ", " end |
#yaml_initialize(tag, vals) ⇒ Object
:nodoc:
135 136 137 138 139 140 141 |
# File 'lib/cocoapods-core/vendor/requirement.rb', line 135 def yaml_initialize(tag, vals) # :nodoc: vals.each do |ivar, val| instance_variable_set "@#{ivar}", val end fix_syck_default_key_in_requirements end |