Sha256: 40254714223309851ab16936b633a75ad9abd0c08e781f6df0b31920dd036c72

Contents?: true

Size: 1.11 KB

Versions: 3

Compression:

Stored size: 1.11 KB

Contents

# frozen_string_literal: true

module LicenseFinder
  class PackageDelta
    STATUSES = %i[added removed unchanged].freeze

    def initialize(status, current_package, previous_package)
      @status = status
      @current_package = current_package
      @previous_package = previous_package
    end

    def name
      pick_package.name
    end

    def version
      pick_package.version
    end

    def aggregate_paths
      pick_package.aggregate_paths
    end

    attr_reader :status

    def licenses
      pick_package.licenses
    end

    def merged_package?
      pick_package.instance_of?(MergedPackage)
    end

    def method_missing(_method_name)
      nil
    end

    def self.added(package)
      new(:added, package, nil)
    end

    def self.removed(package)
      new(:removed, nil, package)
    end

    def self.unchanged(current_package, previous_package)
      new(:unchanged, current_package, previous_package)
    end

    def <=>(other)
      STATUSES.index(status) <=> STATUSES.index(other.status)
    end

    private

    def pick_package
      @current_package || @previous_package
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
license_finder-7.1.0 lib/license_finder/package_delta.rb
license_finder-7.0.1 lib/license_finder/package_delta.rb
license_finder-7.0.0 lib/license_finder/package_delta.rb