Class: MVCLI::Middleware::ExceptionLogger::ValidationSummary

Inherits:
Enumerator
  • Object
show all
Defined in:
lib/mvcli/middleware/exception_logger/validation_summary.rb

Instance Method Summary collapse

Constructor Details

#initialize(validation) ⇒ ValidationSummary

Returns a new instance of ValidationSummary.



5
6
7
8
# File 'lib/mvcli/middleware/exception_logger/validation_summary.rb', line 5

def initialize(validation)
  super &method(:yield)
  @validation = validation
end

Instance Method Details

#write(stream) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/mvcli/middleware/exception_logger/validation_summary.rb', line 32

def write(stream)
  each do |key, messages|
    messages.each do |msg|
      stream.puts "#{key}: #{msg}"
    end
  end
end

#yield(output) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/mvcli/middleware/exception_logger/validation_summary.rb', line 10

def yield(output)
  @validation.violations.each do |key, messages|
    output << [key, messages]
  end
  @validation.errors.each do |key, exceptions|
    output << [key, exceptions.map {|ex| "#{ex.class}: #{ex.message}"}]
  end
  @validation.each do |name, child|
    if child.length > 1
      child.each_with_index do |c, i|
        ValidationSummary.new(c).each do |key, messages|
          output << ["#{name}[#{i}].#{key}", messages]
        end
      end
    elsif first = child.first
      ValidationSummary.new(first).each do |key, messages|
        output << ["#{name}.#{key}", messages]
      end
    end
  end
end