Class: MVCLI::Middleware::ExceptionLogger::ValidationSummary
- Inherits:
-
Enumerator
- Object
- Enumerator
- MVCLI::Middleware::ExceptionLogger::ValidationSummary
- Defined in:
- lib/mvcli/middleware/exception_logger/validation_summary.rb
Instance Method Summary collapse
-
#initialize(validation) ⇒ ValidationSummary
constructor
A new instance of ValidationSummary.
- #write(stream) ⇒ Object
- #yield(output) ⇒ Object
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, | .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, | output << [key, ] end @validation.errors.each do |key, exceptions| output << [key, exceptions.map {|ex| "#{ex.class}: #{ex.}"}] end @validation.each do |name, child| if child.length > 1 child.each_with_index do |c, i| ValidationSummary.new(c).each do |key, | output << ["#{name}[#{i}].#{key}", ] end end elsif first = child.first ValidationSummary.new(first).each do |key, | output << ["#{name}.#{key}", ] end end end end |