Sha256: 1f351411598ee03fdfe11b81dd3f527e2a494db4e9b16e5f0d055bd778c3e6c1

Contents?: true

Size: 657 Bytes

Versions: 1

Compression:

Stored size: 657 Bytes

Contents

module ValidData
  class Collector
    def initialize(models)
      @models = models
    end

    def each(&block)
      return enum_for(:each) unless block_given?

      models.each { |model|
        yield compute_result(model)
      }
    end

    def compute_result(model)
      invalid_count, total = 0, 0

      model.find_each do |m|
        invalid_count += 1 if m.invalid?
        total += 1
      end

      Result.new(model.name, invalid_count, total)
      #NOTE: The following line doesn't work for Rails < 4.0!
      #Result.new(model.name, model.find_each.select(&:valid?), model.count)
    end

    private

    attr_reader :models
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
valid_data-0.0.1 lib/valid_data/collector.rb