Sha256: b1a01d945d11271c4f6f556b9075d4d62726cd90d57d7e9ceacf5b0e63acf677

Contents?: true

Size: 937 Bytes

Versions: 1

Compression:

Stored size: 937 Bytes

Contents

# frozen_string_literal: true

module ActiveRecord
  module DataIntegrity
    # collects result info for rendering
    class Collector
      class << self
        def log(cop, message)
          data.push(cop: cop, message: message)
        end

        def progress(_cop, char)
          print char
        end

        def render
          group_data_by_cop_name.each do |cop_name, items|
            items.each do |item|
              puts "#{Rainbow(cop_name).red}:"\
                     " #{Rainbow(item[:cop].model.name).yellow}"\
                     " #{item[:message]}"
            end
          end
        end

        private

        def data
          @data ||= []
        end

        def group_data_by_cop_name
          data.each_with_object({}) do |item, hash|
            hash[item[:cop].class.cop_name] ||= []
            hash[item[:cop].class.cop_name] << item
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
activerecord-data_integrity-0.2.1 lib/active_record/data_integrity/collector.rb