module Bundler::VersionRanges - bundler-1.15.4 Documentation

# module Bundler::VersionRanges

### Constants

NEq
ReqR

### Public Class Methods

empty?(ranges, neqs) click to toggle source

    # File lib/bundler/version_ranges.rb, line 61
    def self.empty?(ranges, neqs)
      !ranges.reduce(ReqR::UNIVERSAL) do |last_range, curr_range|
        next false unless last_range
        next false if curr_range.single? && neqs.include?(curr_range.left.version)
        next curr_range if last_range.right.version == ReqR::INFINITY
        case last_range.right.version <=> curr_range.left.version
        when 1 then next curr_range
        when 0 then next(last_range.right.inclusive && curr_range.left.inclusive && !neqs.include?(curr_range.left.version) && curr_range)
        when -1 then next false
        end
      end
    end

for(requirement) click to toggle source

    # File lib/bundler/version_ranges.rb, line 43
    def self.for(requirement)
      ranges = requirement.requirements.map do |op, v|
        case op
        when "=" then ReqR.new(ReqR::Endpoint.new(v, true), ReqR::Endpoint.new(v, true))
        when "!=" then NEq.new(v)
        when ">=" then ReqR.new(ReqR::Endpoint.new(v, true), ReqR::Endpoint.new(ReqR::INFINITY, false))
        when ">" then ReqR.new(ReqR::Endpoint.new(v, false), ReqR::Endpoint.new(ReqR::INFINITY, false))
        when "<" then ReqR.new(ReqR::Endpoint.new(ReqR::ZERO, true), ReqR::Endpoint.new(v, false))
        when "<=" then ReqR.new(ReqR::Endpoint.new(ReqR::ZERO, true), ReqR::Endpoint.new(v, true))
        when "~>" then ReqR.new(ReqR::Endpoint.new(v, true), ReqR::Endpoint.new(v.bump, false))
        else raise "unknown version op #{op} in requirement #{requirement}"
        end
      end.uniq
      ranges, neqs = ranges.partition {|r| !r.is_a?(NEq) }

      [ranges.sort_by {|range| [range.left.version, range.left.inclusive ? 0 : 1] }, neqs.map(&:version)]
    end

for_many(requirements) click to toggle source

    # File lib/bundler/version_ranges.rb, line 36
    def self.for_many(requirements)
      requirements = requirements.map(&:requirements).flatten(1).map {|r| r.join(" ") }
      requirements << ">= 0.a" if requirements.empty?
      requirement = Gem::Requirement.new(requirements)
      self.for(requirement)
    end