class Tidylib::ValidationErrors
Constants
- VERSION
Public Class Methods
new()
click to toggle source
# File lib/tidylib/validation_errors.rb, line 9 def initialize @errors = [] end
Public Instance Methods
<<(error)
click to toggle source
# File lib/tidylib/validation_errors.rb, line 59 def <<(error) raise ArgumentError unless error.respond_to?(:topic) && error.respond_to?(:message) && error.respond_to?(:context) @errors << error end
[](topic)
click to toggle source
# File lib/tidylib/validation_errors.rb, line 27 def [](topic) @errors.select do |error| error.topic == topic end.map do |error| [ error.message, error.context ] end end
Also aliased as: on
add(topic, message, context={})
click to toggle source
# File lib/tidylib/validation_errors.rb, line 17 def add(topic, message, context={}) error = OpenStruct.new( topic: topic, message: message, context: context ) @errors << error end
clear()
click to toggle source
# File lib/tidylib/validation_errors.rb, line 51 def clear @errors = [] end
count()
click to toggle source
# File lib/tidylib/validation_errors.rb, line 55 def count @errors.length end
each() { |topic, message, context| ... }
click to toggle source
# File lib/tidylib/validation_errors.rb, line 36 def each(&blk) @errors.each do |error| yield error.topic, error.message, error.context end end
empty?()
click to toggle source
# File lib/tidylib/validation_errors.rb, line 13 def empty? @errors.empty? end
grouped_by_topic()
click to toggle source
# File lib/tidylib/validation_errors.rb, line 42 def grouped_by_topic @errors.inject({}) do |grouped, error| grouped[error.topic] ||= [] grouped[error.topic] << [error.message, error.context] grouped end end