class PubGrub::Term
Attributes
constraint[R]
package[R]
positive[R]
Public Class Methods
new(constraint, positive)
click to toggle source
# File lib/pub_grub/term.rb, line 7 def initialize(constraint, positive) @constraint = constraint @package = @constraint.package @positive = positive end
Public Instance Methods
difference(other)
click to toggle source
# File lib/pub_grub/term.rb, line 49 def difference(other) intersect(other.invert) end
empty?()
click to toggle source
# File lib/pub_grub/term.rb, line 99 def empty? @empty ||= normalized_constraint.empty? end
eql?(other)
click to toggle source
# File lib/pub_grub/term.rb, line 25 def eql?(other) positive == other.positive && constraint.eql?(other.constraint) end
hash()
click to toggle source
# File lib/pub_grub/term.rb, line 21 def hash constraint.hash ^ positive.hash end
inspect()
click to toggle source
# File lib/pub_grub/term.rb, line 103 def inspect "#<#{self.class} #{self}>" end
intersect(other)
click to toggle source
# File lib/pub_grub/term.rb, line 35 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()
click to toggle source
# File lib/pub_grub/term.rb, line 30 def invert self.class.new(@constraint, !@positive) end
Also aliased as: inverse
negative?()
click to toggle source
# File lib/pub_grub/term.rb, line 95 def negative? !positive? end
normalized_constraint()
click to toggle source
# File lib/pub_grub/term.rb, line 81 def normalized_constraint @normalized_constraint ||= positive ? constraint : constraint.invert end
positive?()
click to toggle source
# File lib/pub_grub/term.rb, line 91 def positive? @positive end
relation(other)
click to toggle source
# File lib/pub_grub/term.rb, line 53 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)
click to toggle source
# File lib/pub_grub/term.rb, line 85 def satisfies?(other) raise ArgumentError, "packages must match" unless package == other.package relation(other) == :subset end
to_s(allow_every: false)
click to toggle source
# File lib/pub_grub/term.rb, line 13 def to_s(allow_every: false) if positive @constraint.to_s(allow_every: allow_every) else "not #{@constraint}" end end