Class: SimpleParams::NestedErrors
- Inherits:
-
ActiveModel::Errors
- Object
- ActiveModel::Errors
- SimpleParams::NestedErrors
- Defined in:
- lib/simple_params/nested_errors.rb
Instance Attribute Summary collapse
-
#base ⇒ Object
readonly
Returns the value of attribute base.
Instance Method Summary collapse
- #[](attribute) ⇒ Object
- #[]=(attribute, error) ⇒ Object
- #add(attribute, message = :invalid, options = {}) ⇒ Object
- #array? ⇒ Boolean
- #clear ⇒ Object
- #empty? ⇒ Boolean (also: #blank?)
- #full_messages ⇒ Object
- #hash? ⇒ Boolean
- #include?(attribute) ⇒ Boolean (also: #has_key?, #key?)
-
#initialize(base) ⇒ NestedErrors
constructor
A new instance of NestedErrors.
- #to_a ⇒ Object
- #to_hash(full_messages = false) ⇒ Object
- #to_s(full_messages = false) ⇒ Object
- #values ⇒ Object
Constructor Details
#initialize(base) ⇒ NestedErrors
Returns a new instance of NestedErrors.
7 8 9 10 |
# File 'lib/simple_params/nested_errors.rb', line 7 def initialize(base) super(base) @base = base end |
Instance Attribute Details
#base ⇒ Object (readonly)
Returns the value of attribute base.
5 6 7 |
# File 'lib/simple_params/nested_errors.rb', line 5 def base @base end |
Instance Method Details
#[](attribute) ⇒ Object
20 21 22 |
# File 'lib/simple_params/nested_errors.rb', line 20 def [](attribute) super(attribute) end |
#[]=(attribute, error) ⇒ Object
24 25 26 |
# File 'lib/simple_params/nested_errors.rb', line 24 def []=(attribute, error) add_error_to_attribute(attribute, error) end |
#add(attribute, message = :invalid, options = {}) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/simple_params/nested_errors.rb', line 28 def add(attribute, = :invalid, = {}) = (attribute, , ) if exception = [:strict] exception = ActiveModel::StrictValidationFailed if exception == true raise exception, (attribute, ) end add_error_to_attribute(attribute, ) end |
#array? ⇒ Boolean
12 13 14 |
# File 'lib/simple_params/nested_errors.rb', line 12 def array? @base.array? end |
#clear ⇒ Object
38 39 40 |
# File 'lib/simple_params/nested_errors.rb', line 38 def clear super end |
#empty? ⇒ Boolean Also known as: blank?
42 43 44 |
# File 'lib/simple_params/nested_errors.rb', line 42 def empty? super end |
#full_messages ⇒ Object
57 58 59 |
# File 'lib/simple_params/nested_errors.rb', line 57 def map { |attribute, | (attribute, ) } end |
#hash? ⇒ Boolean
16 17 18 |
# File 'lib/simple_params/nested_errors.rb', line 16 def hash? @base.hash? end |
#include?(attribute) ⇒ Boolean Also known as: has_key?, key?
47 48 49 |
# File 'lib/simple_params/nested_errors.rb', line 47 def include?(attribute) [attribute].present? end |
#to_a ⇒ Object
61 62 63 |
# File 'lib/simple_params/nested_errors.rb', line 61 def to_a end |
#to_hash(full_messages = false) ⇒ Object
65 66 67 |
# File 'lib/simple_params/nested_errors.rb', line 65 def to_hash( = false) (self, ) end |
#to_s(full_messages = false) ⇒ Object
69 70 71 72 |
# File 'lib/simple_params/nested_errors.rb', line 69 def to_s( = false) array = to_a.compact array.join(', ') end |
#values ⇒ Object
53 54 55 |
# File 'lib/simple_params/nested_errors.rb', line 53 def values .values end |