Class: ValidData::Collector
- Inherits:
-
Object
- Object
- ValidData::Collector
- Defined in:
- lib/valid_data/collector.rb
Instance Method Summary collapse
- #compute_result(model) ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(models) ⇒ Collector
constructor
A new instance of Collector.
Constructor Details
#initialize(models) ⇒ Collector
Returns a new instance of Collector.
3 4 5 |
# File 'lib/valid_data/collector.rb', line 3 def initialize(models) @models = models end |
Instance Method Details
#compute_result(model) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/valid_data/collector.rb', line 15 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 |
#each(&block) ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/valid_data/collector.rb', line 7 def each(&block) return enum_for(:each) unless block_given? models.each { |model| yield compute_result(model) } end |