Sha256: f9d1d3b81339ca24e5f5e20e7c1df829cdd869541b6511dd71aa339d8ca0bd8b

Contents?: true

Size: 1.24 KB

Versions: 2

Compression:

Stored size: 1.24 KB

Contents

module KeepUp
  # Single dependency with its current locked version.
  class Dependency
    def initialize(name:, requirement_list:, locked_version:)
      @name = name
      @requirement_list = requirement_list
      @locked_version = Gem::Version.new locked_version
    end

    attr_reader :name, :locked_version

    def requirement
      @requirement ||= Gem::Requirement.new @requirement_list
    end

    def matches_spec?(spec)
      dependency.matches_spec? spec
    end

    def generalize_specification(specification)
      return specification if requirement.exact?
      segments = specification.version.segments
      return specification if segments.count <= segment_count
      version = segments.take(segment_count).join('.')
      Gem::Specification.new(specification.name, version)
    end

    def ==(other)
      other.name == name &&
        other.locked_version == locked_version &&
        other.requirement == requirement
    end

    private

    def dependency
      @dependency ||= Gem::Dependency.new name, requirement
    end

    def segment_count
      @segment_count ||= begin
                           _, ver = requirement.requirements.first
                           ver.segments.count
                         end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
keep_up-0.6.3 lib/keep_up/dependency.rb
keep_up-0.6.2 lib/keep_up/dependency.rb