123456789_123456789_123456789_123456789_123456789_

Class: Bundler::PubGrub::Term

Relationships & Source Files
Inherits: Object
Defined in: lib/bundler/vendor/pub_grub/lib/pub_grub/term.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(constraint, positive) ⇒ Term

[ GitHub ]

  
# 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 (readonly)

[ GitHub ]

  
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/term.rb', line 3

attr_reader :package, :constraint, :positive

#empty?Boolean (readonly)

[ GitHub ]

  
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/term.rb', line 97

def empty?
  @empty ||= normalized_constraint.empty?
end

#negative?Boolean (readonly)

[ GitHub ]

  
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/term.rb', line 93

def negative?
  !positive?
end

#package (readonly)

[ GitHub ]

  
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/term.rb', line 3

attr_reader :package, :constraint, :positive

#positive (readonly)

[ GitHub ]

  
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/term.rb', line 3

attr_reader :package, :constraint, :positive

#positive?Boolean (readonly)

[ GitHub ]

  
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/term.rb', line 89

def positive?
  @positive
end

Instance Method Details

#difference(other)

[ GitHub ]

  
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/term.rb', line 47

def difference(other)
  intersect(other.invert)
end

#eql?(other) ⇒ Boolean

[ GitHub ]

  
# 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

[ GitHub ]

  
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/term.rb', line 19

def hash
  constraint.hash ^ positive.hash
end

#inspect

[ GitHub ]

  
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/term.rb', line 101

def inspect
  "#<#{self.class} #{self}>"
end

#intersect(other)

Raises:

  • (ArgumentError)
[ GitHub ]

  
# 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

#inverse

Alias for #invert.

[ GitHub ]

  
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/term.rb', line 31

alias_method :inverse, :invert

#invert Also known as: #inverse

[ GitHub ]

  
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/term.rb', line 28

def invert
  self.class.new(@constraint, !@positive)
end

#normalized_constraint

[ GitHub ]

  
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/term.rb', line 79

def normalized_constraint
  @normalized_constraint ||= positive ? constraint : constraint.invert
end

#relation(other)

[ GitHub ]

  
# 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

Raises:

  • (ArgumentError)
[ GitHub ]

  
# 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)

[ GitHub ]

  
# 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