Exception: NotNaughty::Violation
- Inherits:
-
RuntimeError
- Object
- RuntimeError
- NotNaughty::Violation
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/not_naughty/violation.rb
Overview
Container for failed validations.
…
Instance Method Summary collapse
-
#add(k, msg) ⇒ Object
Adds an error for the given attribute.
-
#full_messages ⇒ Object
Returns an array of fully-formatted error messages.
-
#initialize ⇒ Violation
constructor
:nodoc:.
-
#on(attribute) ⇒ Object
Returns an array of evaluated error messages for given attribute.
Constructor Details
#initialize ⇒ Violation
:nodoc:
13 14 15 |
# File 'lib/not_naughty/violation.rb', line 13 def initialize() #:nodoc: @errors = Hash.new {|h, k| h[k] = []} end |
Instance Method Details
#add(k, msg) ⇒ Object
Adds an error for the given attribute.
17 |
# File 'lib/not_naughty/violation.rb', line 17 def add(k, msg) @errors[k] << msg end |
#full_messages ⇒ Object
Returns an array of fully-formatted error messages.
20 21 22 23 24 25 |
# File 'lib/not_naughty/violation.rb', line 20 def @errors.inject([]) do |, k_errors| k, errors = *k_errors errors.each {|e| << eval(e.inspect.delete('\\') % k) } end end |
#on(attribute) ⇒ Object
Returns an array of evaluated error messages for given attribute.
28 29 30 31 32 |
# File 'lib/not_naughty/violation.rb', line 28 def on(attribute) @errors[attribute].map do || eval(.inspect.delete('\\') % attribute) end end |