Method: Subvalid::ValidationResult#flatten
- Defined in:
- lib/subvalid/validation_result.rb
#flatten(parent_attributes = []) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/subvalid/validation_result.rb', line 40 def flatten(parent_attributes=[]) # TODO make this more flexible than just hardcoded format flat_errors = errors.map{|error| if parent_attributes.empty? error else human_keys = parent_attributes.map{|a| a.to_s.gsub('_', ' ')} [human_keys.join(", "), error].join(": ") end } children.each do |attribute, child| flat_errors += child.flatten(parent_attributes + [attribute]) end flat_errors end |