Class: Bundler::PubGrub::VersionConstraint
- Inherits:
-
Object
- Object
- Bundler::PubGrub::VersionConstraint
- Defined in:
- lib/bundler/vendor/pub_grub/lib/pub_grub/version_constraint.rb
Instance Attribute Summary collapse
-
#package ⇒ Object
readonly
Returns the value of attribute package.
-
#range ⇒ Object
readonly
Returns the value of attribute range.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #allows_all?(other) ⇒ Boolean
- #allows_any?(other) ⇒ Boolean
-
#any? ⇒ Boolean
Does this match every version of the package.
- #constraint_string ⇒ Object
- #difference(other) ⇒ Object
- #disjoint?(other) ⇒ Boolean
- #empty? ⇒ Boolean
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(package, range: nil) ⇒ VersionConstraint
constructor
A new instance of VersionConstraint.
- #inspect ⇒ Object
- #intersect(other) ⇒ Object
- #invert ⇒ Object
- #overlap?(other) ⇒ Boolean
- #relation(other) ⇒ Object
- #subset?(other) ⇒ Boolean
- #to_s(allow_every: false) ⇒ Object
- #union(other) ⇒ Object
Constructor Details
#initialize(package, range: nil) ⇒ VersionConstraint
Returns a new instance of VersionConstraint.
9 10 11 12 |
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_constraint.rb', line 9 def initialize(package, range: nil) @package = package @range = range end |
Instance Attribute Details
#package ⇒ Object (readonly)
Returns the value of attribute package.
5 6 7 |
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_constraint.rb', line 5 def package @package end |
#range ⇒ Object (readonly)
Returns the value of attribute range.
5 6 7 |
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_constraint.rb', line 5 def range @range end |
Class Method Details
.any(package) ⇒ Object
33 34 35 |
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_constraint.rb', line 33 def any(package) new(package, range: VersionRange.any) end |
.empty(package) ⇒ Object
37 38 39 |
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_constraint.rb', line 37 def empty(package) new(package, range: VersionRange.empty) end |
.exact(package, version) ⇒ Object
28 29 30 31 |
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_constraint.rb', line 28 def exact(package, version) range = VersionRange.new(min: version, max: version, include_min: true, include_max: true) new(package, range: range) end |
Instance Method Details
#==(other) ⇒ Object
23 24 25 |
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_constraint.rb', line 23 def ==(other) package == other.package && range == other.range end |
#allows_all?(other) ⇒ Boolean
67 68 69 |
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_constraint.rb', line 67 def allows_all?(other) range.allows_all?(other.range) end |
#allows_any?(other) ⇒ Boolean
71 72 73 |
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_constraint.rb', line 71 def allows_any?(other) range.intersects?(other.range) end |
#any? ⇒ Boolean
Does this match every version of the package
120 121 122 |
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_constraint.rb', line 120 def any? range.any? end |
#constraint_string ⇒ Object
107 108 109 110 111 112 113 |
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_constraint.rb', line 107 def constraint_string if any? ">= 0" else range.to_s end end |
#difference(other) ⇒ Object
63 64 65 |
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_constraint.rb', line 63 def difference(other) intersect(other.invert) end |
#disjoint?(other) ⇒ Boolean
83 84 85 |
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_constraint.rb', line 83 def disjoint?(other) !overlap?(other) end |
#empty? ⇒ Boolean
115 116 117 |
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_constraint.rb', line 115 def empty? range.empty? end |
#eql?(other) ⇒ Boolean
18 19 20 21 |
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_constraint.rb', line 18 def eql?(other) package.eql?(other.package) && range.eql?(other.range) end |
#hash ⇒ Object
14 15 16 |
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_constraint.rb', line 14 def hash package.hash ^ range.hash end |
#inspect ⇒ Object
124 125 126 |
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_constraint.rb', line 124 def inspect "#<#{self.class} #{self}>" end |
#intersect(other) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_constraint.rb', line 42 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 ⇒ Object
58 59 60 61 |
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_constraint.rb', line 58 def invert new_range = range.invert self.class.new(package, range: new_range) end |
#overlap?(other) ⇒ Boolean
79 80 81 |
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_constraint.rb', line 79 def overlap?(other) other.allows_any?(self) end |
#relation(other) ⇒ Object
87 88 89 90 91 92 93 94 95 |
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_constraint.rb', line 87 def relation(other) if subset?(other) :subset elsif overlap?(other) :overlap else :disjoint end end |
#subset?(other) ⇒ Boolean
75 76 77 |
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_constraint.rb', line 75 def subset?(other) other.allows_all?(self) end |
#to_s(allow_every: false) ⇒ Object
97 98 99 100 101 102 103 104 105 |
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_constraint.rb', line 97 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) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_constraint.rb', line 50 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 |