Sha256: a9c94e2c31650d27e74ae98d6414cf2138961d214e5000f5ca3c80f6aba8434e

Contents?: true

Size: 935 Bytes

Versions: 5

Compression:

Stored size: 935 Bytes

Contents

# Simple helpers to find invalid records and print why they are invalid. May
# take a while to run depending on size of data
namespace :invalids do
  Dir.foreach("#{Rails.root}/app/models") do |item|
    next if item == '.' or item == '..' or not item
    name = item.split(".")[0].pluralize

    desc "Finds invalid records for #{name} scaffold"
    task "find:#{name}" => :environment do
      Rails.application.eager_load!
      klass = Kernel.const_get(name.classify)

      invalids = []
      index = 0
      klass.find_each do |obj|
        index += 1

        if index % 1000 == 0
          ap "invalids at index #{index}"
          ap invalids
        end

        next if obj.valid?
        invalids << { id: obj.id, errors: obj.errors }
      end

      ap "Invalids at end:"
      ap invalids

      # This is used for log based alerts
      ap "LOG NOTIFIER: INVALID RECORDS EXIST" if invalids.count > 0
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
handshake_service-0.1.5 lib/tasks/invalids.rake
handshake_service-0.1.4 lib/tasks/invalids.rake
handshake_service-0.1.3 lib/tasks/invalids.rake
handshake_service-0.1.2 lib/tasks/invalids.rake
handshake_service-0.1.1 lib/tasks/invalids.rake