Sha256: 9d6e631dea856dd1cf9b6e1cc6ab9caa3ec63991baa781102e4183cde94ca280

Contents?: true

Size: 1.38 KB

Versions: 4

Compression:

Stored size: 1.38 KB

Contents

# frozen_string_literal: true

require "active_support/core_ext/class/attribute"

module DeprecationToolkit
  class Collector
    include Comparable
    extend ReadWriteHelper

    class_attribute :deprecations
    self.deprecations = []
    delegate :size, to: :deprecations

    class << self
      def collect(message)
        deprecations << message
      end

      def load(test)
        new(read(test))
      end

      def reset!
        deprecations.clear
      end
    end

    def initialize(deprecations)
      self.deprecations = deprecations
    end

    def <=>(other)
      deprecations_without_stacktrace <=> other.deprecations_without_stacktrace
    end

    def deprecations_without_stacktrace
      deprecations.map do |deprecation|
        if ActiveSupport.gem_version.to_s < "5.0"
          deprecation.sub(/\W\s\(called from .*\)$/, "")
        else
          deprecation.sub(/ \(called from .*\)$/, "")
        end
      end
    end

    def -(other)
      difference = deprecations.dup
      current = deprecations_without_stacktrace
      other = other.deprecations_without_stacktrace

      other.each do |deprecation|
        index = current.index(deprecation)

        if index
          current.delete_at(index)
          difference.delete_at(index)
        end
      end

      difference
    end

    def flaky?
      size == 1 && deprecations.first['flaky'] == true
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
deprecation_toolkit-1.5.1 lib/deprecation_toolkit/collector.rb
deprecation_toolkit-1.5.0 lib/deprecation_toolkit/collector.rb
deprecation_toolkit-1.4.0 lib/deprecation_toolkit/collector.rb
deprecation_toolkit-1.3.0 lib/deprecation_toolkit/collector.rb