Class: Bundler::PubGrub::VersionUnion
Relationships & Source Files | |
Inherits: | Object |
Defined in: | lib/bundler/vendor/pub_grub/lib/pub_grub/version_union.rb |
Class Method Summary
Instance Attribute Summary
- #any? ⇒ Boolean readonly
- #empty? ⇒ Boolean readonly
- #ranges readonly
Instance Method Summary
Constructor Details
.new(ranges) ⇒ VersionUnion
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_union.rb', line 42
def initialize(ranges) raise ArgumentError unless ranges.all? { |r| r.instance_of?(VersionRange) } @ranges = ranges end
Class Method Details
.normalize_ranges(ranges)
[ GitHub ]# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_union.rb', line 7
def self.normalize_ranges(ranges) ranges = ranges.flat_map do |range| range.ranges end ranges.reject!(&:empty?) return [] if ranges.empty? mins, ranges = ranges.partition { |r| !r.min } original_ranges = mins + ranges.sort_by { |r| [r.min, r.include_min ? 0 : 1] } ranges = [original_ranges.shift] original_ranges.each do |range| if ranges.last.contiguous_to?(range) ranges << ranges.pop.span(range) else ranges << range end end ranges end
.union(ranges, normalize: true)
[ GitHub ]Instance Attribute Details
#any? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_union.rb', line 108
def any? false end
#empty? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_union.rb', line 104
def empty? false end
#ranges (readonly)
[ GitHub ]# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_union.rb', line 5
attr_reader :ranges
Instance Method Details
#==(other)
[ GitHub ]
#allows_all?(other) ⇒ Boolean
#allows_any?(other)
Alias for #intersects?.
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_union.rb', line 87
alias_method :allows_any?, :intersects?
#eql?(other) ⇒ Boolean
#hash
[ GitHub ]# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_union.rb', line 47
def hash ranges.hash end
#include?(version) ⇒ Boolean
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_union.rb', line 55
def include?(version) !!ranges.bsearch {|r| r.compare_version(version) } end
#inspect
[ GitHub ]# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_union.rb', line 169
def inspect "#<#{self.class} #{to_s}>" end
#intersect(other)
[ GitHub ]# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_union.rb', line 112
def intersect(other) my_ranges = ranges.dup other_ranges = other.ranges.dup new_ranges = [] my_range = my_ranges.shift other_range = other_ranges.shift while my_range && other_range new_ranges << my_range.intersect(other_range) if !my_range.max || other_range.empty? || (other_range.max && other_range.max < my_range.max) other_range = other_ranges.shift else my_range = my_ranges.shift end end new_ranges.reject!(&:empty?) VersionUnion.union(new_ranges, normalize: false) end
#intersects?(other) ⇒ Boolean
Also known as: #allows_any?
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_union.rb', line 69
def intersects?(other) my_ranges = ranges.dup other_ranges = other.ranges.dup my_range = my_ranges.shift other_range = other_ranges.shift while my_range && other_range if my_range.intersects?(other_range) return true end if !my_range.max || other_range.empty? || (other_range.max && other_range.max < my_range.max) other_range = other_ranges.shift else my_range = my_ranges.shift end end end
#invert
[ GitHub ]#select_versions(all_versions)
[ GitHub ]# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_union.rb', line 59
def select_versions(all_versions) versions = [] ranges.inject(all_versions) do |acc, range| _, matching, higher = range.partition_versions(acc) versions.concat matching higher end versions end
#to_s
[ GitHub ]# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_union.rb', line 144
def to_s output = [] ranges = self.ranges.dup while !ranges.empty? ne = [] range = ranges.shift while !ranges.empty? && ranges[0].min.to_s == range.max.to_s ne << range.max range = range.span(ranges.shift) end ne.map! {|x| "!= #{x}" } if ne.empty? output << range.to_s elsif range.any? output << ne.join(', ') else output << "#{range}, #{ne.join(', ')}" end end output.join(" OR ") end
#union(other)
[ GitHub ]# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_union.rb', line 140
def union(other) VersionUnion.union([self, other]) end
#upper_invert
[ GitHub ]# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_union.rb', line 132
def upper_invert ranges.last.upper_invert end