Class: Bundler::PubGrub::Term
- Inherits:
-
Object
- Object
- Bundler::PubGrub::Term
- Defined in:
- lib/bundler/vendor/pub_grub/lib/pub_grub/term.rb
Instance Attribute Summary collapse
-
#constraint ⇒ Object
readonly
Returns the value of attribute constraint.
-
#package ⇒ Object
readonly
Returns the value of attribute package.
-
#positive ⇒ Object
readonly
Returns the value of attribute positive.
Instance Method Summary collapse
- #difference(other) ⇒ Object
- #empty? ⇒ Boolean
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(constraint, positive) ⇒ Term
constructor
A new instance of Term.
- #inspect ⇒ Object
- #intersect(other) ⇒ Object
- #invert ⇒ Object (also: #inverse)
- #negative? ⇒ Boolean
- #normalized_constraint ⇒ Object
- #positive? ⇒ Boolean
- #relation(other) ⇒ Object
- #satisfies?(other) ⇒ Boolean
- #to_s(allow_every: false) ⇒ Object
Constructor Details
#initialize(constraint, positive) ⇒ Term
Returns a new instance of Term.
5 6 7 8 9 |
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/term.rb', line 5 def initialize(constraint, positive) @constraint = constraint @package = @constraint.package @positive = positive end |
Instance Attribute Details
#constraint ⇒ Object (readonly)
Returns the value of attribute constraint.
3 4 5 |
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/term.rb', line 3 def constraint @constraint end |
#package ⇒ Object (readonly)
Returns the value of attribute package.
3 4 5 |
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/term.rb', line 3 def package @package end |
#positive ⇒ Object (readonly)
Returns the value of attribute positive.
3 4 5 |
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/term.rb', line 3 def positive @positive end |
Instance Method Details
#difference(other) ⇒ Object
47 48 49 |
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/term.rb', line 47 def difference(other) intersect(other.invert) end |
#empty? ⇒ Boolean
97 98 99 |
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/term.rb', line 97 def empty? @empty ||= normalized_constraint.empty? end |
#eql?(other) ⇒ Boolean
23 24 25 26 |
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/term.rb', line 23 def eql?(other) positive == other.positive && constraint.eql?(other.constraint) end |
#hash ⇒ Object
19 20 21 |
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/term.rb', line 19 def hash constraint.hash ^ positive.hash end |
#inspect ⇒ Object
101 102 103 |
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/term.rb', line 101 def inspect "#<#{self.class} #{self}>" end |
#intersect(other) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/term.rb', line 33 def intersect(other) raise ArgumentError, "packages must match" if package != other.package if positive? && other.positive? self.class.new(constraint.intersect(other.constraint), true) elsif negative? && other.negative? self.class.new(constraint.union(other.constraint), false) else positive = positive? ? self : other negative = negative? ? self : other self.class.new(positive.constraint.intersect(negative.constraint.invert), true) end end |
#invert ⇒ Object Also known as: inverse
28 29 30 |
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/term.rb', line 28 def invert self.class.new(@constraint, !@positive) end |
#negative? ⇒ Boolean
93 94 95 |
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/term.rb', line 93 def negative? !positive? end |
#normalized_constraint ⇒ Object
79 80 81 |
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/term.rb', line 79 def normalized_constraint @normalized_constraint ||= positive ? constraint : constraint.invert end |
#positive? ⇒ Boolean
89 90 91 |
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/term.rb', line 89 def positive? @positive end |
#relation(other) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/term.rb', line 51 def relation(other) if positive? && other.positive? constraint.relation(other.constraint) elsif negative? && other.positive? if constraint.allows_all?(other.constraint) :disjoint else :overlap end elsif positive? && other.negative? if !other.constraint.allows_any?(constraint) :subset elsif other.constraint.allows_all?(constraint) :disjoint else :overlap end elsif negative? && other.negative? if constraint.allows_all?(other.constraint) :subset else :overlap end else raise end end |
#satisfies?(other) ⇒ Boolean
83 84 85 86 87 |
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/term.rb', line 83 def satisfies?(other) raise ArgumentError, "packages must match" unless package == other.package relation(other) == :subset end |
#to_s(allow_every: false) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/term.rb', line 11 def to_s(allow_every: false) if positive @constraint.to_s(allow_every: allow_every) else "not #{@constraint}" end end |