Sha256: eae8f9d4051a5e70eabc948043c07676d36d101d14769b1b91569fa383bd4946

Contents?: true

Size: 1.4 KB

Versions: 5

Compression:

Stored size: 1.4 KB

Contents

require 'rubygems/requirement'

module PubGrub
  module RubyGems
    extend self

    def requirement_to_range(requirement)
      ranges = requirement.requirements.map do |(op, ver)|
        case op
        when "~>"
          # TODO: not sure this is correct for prereleases
          VersionRange.new(min: ver, max: ver.bump, include_min: true)
        when ">"
          VersionRange.new(min: ver)
        when ">="
          if ver == Gem::Version.new("0")
            VersionRange.any
          else
            VersionRange.new(min: ver, include_min: true)
          end
        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

5 entries across 5 versions & 1 rubygems

Version Path
pub_grub-0.4.1 lib/pub_grub/rubygems.rb
pub_grub-0.4.0 lib/pub_grub/rubygems.rb
pub_grub-0.3.2 lib/pub_grub/rubygems.rb
pub_grub-0.3.1 lib/pub_grub/rubygems.rb
pub_grub-0.3.0 lib/pub_grub/rubygems.rb