Sha256: 534119574e9b1797353b8ad93d0e5cf1454312dda277b37b073f08e9236f355f

Contents?: true

Size: 1.2 KB

Versions: 6

Compression:

Stored size: 1.2 KB

Contents

# frozen_string_literal: true

require 'forwardable'

module Unwrappr
  # Represents a gem change in a Gemfile.lock diff.
  class GemChange
    extend Forwardable

    def initialize(
      name:, head_version:, base_version:, line_number:, lock_file_diff:
    )
      @name = name
      @head_version = head_version
      @base_version = base_version
      @line_number = line_number
      @lock_file_diff = lock_file_diff
    end

    attr_reader :name, :head_version, :base_version, :line_number
    def_delegators :@lock_file_diff, :filename, :sha

    def added?
      (head_version && base_version.nil?)
    end

    def removed?
      (base_version && head_version.nil?)
    end

    def major?
      head_version && base_version &&
        head_version.major_difference?(base_version)
    end

    def minor?
      head_version && base_version &&
        head_version.minor_difference?(base_version)
    end

    def patch?
      head_version && base_version &&
        head_version.patch_difference?(base_version)
    end

    def upgrade?
      head_version && base_version && (head_version > base_version)
    end

    def downgrade?
      head_version && base_version && (head_version < base_version)
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
unwrappr-0.3.5 lib/unwrappr/gem_change.rb
unwrappr-0.3.4 lib/unwrappr/gem_change.rb
unwrappr-0.3.3 lib/unwrappr/gem_change.rb
unwrappr-0.3.2 lib/unwrappr/gem_change.rb
unwrappr-0.3.1 lib/unwrappr/gem_change.rb
unwrappr-0.3.0 lib/unwrappr/gem_change.rb