Class: ValidationErrorReporter::Reporter

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ Reporter

Returns a new instance of Reporter.



5
6
7
8
9
# File 'lib/validation_error_reporter/reporter.rb', line 5

def initialize(configuration)
  @notifiers = configuration.notifiers
  @profiler = configuration.profiler if configuration.profiler
  @errors = []
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



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

def errors
  @errors
end

#notifiersObject (readonly)

Returns the value of attribute notifiers.



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

def notifiers
  @notifiers
end

#profilerObject (readonly)

Returns the value of attribute profiler.



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

def profiler
  @profiler
end

Instance Method Details

#finalizeObject



16
17
18
19
20
21
22
23
24
# File 'lib/validation_error_reporter/reporter.rb', line 16

def finalize
  if profiler
    profile = profiler.profile(errors)
    formatter = ProfileFormatter.new
    notifiers.each { |notifier| notifier.notify(formatter.format(profile)) }
  end

  notifiers.each(&:finalize)
end

#report(error) ⇒ Object



11
12
13
14
# File 'lib/validation_error_reporter/reporter.rb', line 11

def report(error)
  @errors << error
  notifiers.each { |notifier| notifier.notify(error.to_s) }
end