Class: StructuredParams::Errors
- Inherits:
-
ActiveModel::Errors
- Object
- ActiveModel::Errors
- StructuredParams::Errors
- Defined in:
- lib/structured_params/errors.rb
Overview
Custom errors collection that handles nested attribute names
Instance Method Summary collapse
-
#as_json(options = nil) ⇒ Object
Override as_json to support structured option This maintains compatibility with ActiveModel::Errors while adding structured functionality : (?{ full_messages?: bool, structured?: bool }?) -> Hash[Symbol, untyped].
-
#messages(structured: false) ⇒ Object
Override messages to support structured option This maintains compatibility with ActiveModel::Errors while adding structured functionality : (?structured: bool) -> Hash[Symbol, untyped].
-
#to_hash(full_messages = false, structured: false) ⇒ Object
Override to_hash to maintain compatibility with ActiveModel::Errors by default Add structured option to get nested structure for dot-notation attributes : (?bool, ?structured: false) -> Hash[Symbol, String] : (?bool, structured: bool) -> Hash[Symbol, untyped].
Instance Method Details
#as_json(options = nil) ⇒ Object
Override as_json to support structured option This maintains compatibility with ActiveModel::Errors while adding structured functionality : (?{ full_messages?: bool, structured?: bool }?) -> Hash[Symbol, untyped]
25 26 27 28 29 |
# File 'lib/structured_params/errors.rb', line 25 def as_json( = nil) ||= {} to_hash(.fetch(:full_messages, false), structured: .fetch(:structured, false)) end |
#messages(structured: false) ⇒ Object
Override messages to support structured option This maintains compatibility with ActiveModel::Errors while adding structured functionality : (?structured: bool) -> Hash[Symbol, untyped]
34 35 36 37 38 39 |
# File 'lib/structured_params/errors.rb', line 34 def (structured: false) hash = to_hash(false, structured: structured) hash.default = [].freeze hash.freeze hash end |
#to_hash(full_messages = false, structured: false) ⇒ Object
Override to_hash to maintain compatibility with ActiveModel::Errors by default Add structured option to get nested structure for dot-notation attributes : (?bool, ?structured: false) -> Hash[Symbol, String] : (?bool, structured: bool) -> Hash[Symbol, untyped]
12 13 14 15 16 17 18 19 20 |
# File 'lib/structured_params/errors.rb', line 12 def to_hash( = false, structured: false) if structured = () build_nested_hash({}, ) else # Use default ActiveModel::Errors behavior super() end end |