Sha256: d0b7814da5338985c527a776fd263bf0d1b57802a3db4132ddd813ff3f109ece

Contents?: true

Size: 1.3 KB

Versions: 3

Compression:

Stored size: 1.3 KB

Contents

module PubGrub
  module RubyGems
    extend self

    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

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

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

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pub_grub-0.5.0 lib/pub_grub/rubygems.rb
pub_grub-0.5.0.alpha3 lib/pub_grub/rubygems.rb
pub_grub-0.5.0.alpha2 lib/pub_grub/rubygems.rb