123456789_123456789_123456789_123456789_123456789_

Class: Bundler::PubGrub::VersionConstraint

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

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(package, range: nil) ⇒ VersionConstraint

[ GitHub ]

  
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_constraint.rb', line 9

def initialize(package, range: nil)
  @package = package
  @range = range
end

Class Method Details

.any(package)

[ GitHub ]

  
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_constraint.rb', line 34

def any(package)
  new(package, range: VersionRange.any)
end

.empty(package)

[ GitHub ]

  
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_constraint.rb', line 38

def empty(package)
  new(package, range: VersionRange.empty)
end

.exact(package, version)

[ GitHub ]

  
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_constraint.rb', line 29

def exact(package, version)
  range = VersionRange.new(min: version, max: version, include_min: true, include_max: true)
  new(package, range: range)
end

Instance Attribute Details

#any?Boolean (readonly)

Does this match every version of the package

[ GitHub ]

  
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_constraint.rb', line 121

def any?
  range.any?
end

#empty?Boolean (readonly)

[ GitHub ]

  
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_constraint.rb', line 116

def empty?
  range.empty?
end

#package (readonly)

[ GitHub ]

  
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_constraint.rb', line 5

attr_reader :package, :range

#range (readonly)

[ GitHub ]

  
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_constraint.rb', line 5

attr_reader :package, :range

Instance Method Details

#==(other)

[ GitHub ]

  
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_constraint.rb', line 18

def ==(other)
  package == other.package &&
    range == other.range
end

#allows_all?(other) ⇒ Boolean

[ GitHub ]

  
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_constraint.rb', line 68

def allows_all?(other)
  range.allows_all?(other.range)
end

#allows_any?(other) ⇒ Boolean

[ GitHub ]

  
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_constraint.rb', line 72

def allows_any?(other)
  range.intersects?(other.range)
end

#constraint_string

[ GitHub ]

  
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_constraint.rb', line 108

def constraint_string
  if any?
    ">= 0"
  else
    range.to_s
  end
end

#difference(other)

[ GitHub ]

  
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_constraint.rb', line 64

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

#disjoint?(other) ⇒ Boolean

[ GitHub ]

  
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_constraint.rb', line 84

def disjoint?(other)
  !overlap?(other)
end

#eql?(other) ⇒ Boolean

[ GitHub ]

  
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_constraint.rb', line 23

def eql?(other)
  package.eql?(other.package) &&
    range.eql?(other.range)
end

#hash

[ GitHub ]

  
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_constraint.rb', line 14

def hash
  package.hash ^ range.hash
end

#inspect

[ GitHub ]

  
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_constraint.rb', line 125

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

#intersect(other)

[ GitHub ]

  
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_constraint.rb', line 43

def intersect(other)
  unless package == other.package
    raise ArgumentError, "Can only intersect between VersionConstraint of the same package"
  end

  self.class.new(package, range: range.intersect(other.range))
end

#invert

[ GitHub ]

  
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_constraint.rb', line 59

def invert
  new_range = range.invert
  self.class.new(package, range: new_range)
end

#overlap?(other) ⇒ Boolean

[ GitHub ]

  
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_constraint.rb', line 80

def overlap?(other)
  other.allows_any?(self)
end

#relation(other)

[ GitHub ]

  
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_constraint.rb', line 88

def relation(other)
  if subset?(other)
    :subset
  elsif overlap?(other)
    :overlap
  else
    :disjoint
  end
end

#subset?(other) ⇒ Boolean

[ GitHub ]

  
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_constraint.rb', line 76

def subset?(other)
  other.allows_all?(self)
end

#to_s(allow_every: false)

[ GitHub ]

  
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_constraint.rb', line 98

def to_s(allow_every: false)
  if Package.root?(package)
    package.to_s
  elsif allow_every && any?
    "every version of #{package}"
  else
    "#{package} #{constraint_string}"
  end
end

#union(other)

[ GitHub ]

  
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_constraint.rb', line 51

def union(other)
  unless package == other.package
    raise ArgumentError, "Can only intersect between VersionConstraint of the same package"
  end

  self.class.new(package, range: range.union(other.range))
end