Module: Bundler::PubGrub::RubyGems

Extended by:
RubyGems
Included in:
RubyGems
Defined in:
lib/bundler/vendor/pub_grub/lib/pub_grub/rubygems.rb

Instance Method Summary collapse

Instance Method Details

#parse_constraint(package, dep) ⇒ Object



40
41
42
43
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/rubygems.rb', line 40

def parse_constraint(package, dep)
  range = parse_range(dep)
  Bundler::PubGrub::VersionConstraint.new(package, range: range)
end

#parse_range(dep) ⇒ Object



36
37
38
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/rubygems.rb', line 36

def parse_range(dep)
  requirement_to_range(Gem::Requirement.new(dep))
end

#requirement_to_constraint(package, requirement) ⇒ Object



32
33
34
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/rubygems.rb', line 32

def requirement_to_constraint(package, requirement)
  Bundler::PubGrub::VersionConstraint.new(package, range: requirement_to_range(requirement))
end

#requirement_to_range(requirement) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/rubygems.rb', line 5

def requirement_to_range(requirement)
  ranges = requirement.requirements.map do |(op, ver)|
    case op
    when "~>"
      name = "~> #{ver}"
      bump = ver.class.new(ver.bump.to_s + ".A")
      VersionRange.new(name: name, min: ver, max: bump, include_min: true)
    when ">"
      VersionRange.new(min: ver)
    when ">="
      VersionRange.new(min: ver, include_min: true)
    when "<"
      VersionRange.new(max: ver)
    when "<="
      VersionRange.new(max: ver, include_max: true)
    when "="
      VersionRange.new(min: ver, max: ver, include_min: true, include_max: true)
    when "!="
      VersionRange.new(min: ver, max: ver, include_min: true, include_max: true).invert
    else
      raise "bad version specifier: #{op}"
    end
  end

  ranges.inject(&:intersect)
end