Module: Bundler::VersionRanges

Defined in:
lib/bundler/version_ranges.rb

Defined Under Namespace

Classes: NEq, ReqR

Class Method Summary collapse

Class Method Details

.empty?(ranges, neqs) ⇒ Boolean

Returns:

  • (Boolean)


103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/bundler/version_ranges.rb', line 103

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
    # higher
    when 1 then next ReqR.new(curr_range.left, last_range.right)
    # equal
    when 0
      if last_range.right.inclusive && curr_range.left.inclusive && !neqs.include?(curr_range.left.version)
        ReqR.new(curr_range.left, [curr_range.right, last_range.right].max)
      end
    # lower
    when -1 then next false
    end
  end
end

.for(requirement) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/bundler/version_ranges.rb', line 85

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, neqs.map(&:version)]
end

.for_many(requirements) ⇒ Object



78
79
80
81
82
83
# File 'lib/bundler/version_ranges.rb', line 78

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