Class: ValidationErrorReporter::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/validation_error_reporter/runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Runner

Returns a new instance of Runner.



5
6
7
# File 'lib/validation_error_reporter/runner.rb', line 5

def initialize(options = {})
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'lib/validation_error_reporter/runner.rb', line 3

def options
  @options
end

Instance Method Details

#runObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/validation_error_reporter/runner.rb', line 9

def run
  Rails.application.eager_load!

  models = Entity.models_for(options[:models])
  configuration = Configuration.new(options)
  reporter = Reporter.new(configuration)

  models.each do |model|
    model.find_each do |record|
      reporter.report(Error.new(record)) unless record.valid?
    end
  end
  reporter.finalize
end