Class: ActiveModel::Errors
- Inherits:
-
Object
- Object
- ActiveModel::Errors
- Defined in:
- lib/activemodel_detailed_errors/load_error_details_support.rb
Constant Summary collapse
- MESSAGE_OPTIONS =
[:message]
Instance Attribute Summary collapse
-
#details ⇒ Object
Returns the value of attribute details.
Instance Method Summary collapse
- #add(attribute, message = :invalid, options = {}) ⇒ Object
- #added?(attribute, message = :invalid, options = {}) ⇒ Boolean
- #clear ⇒ Object
- #delete ⇒ Object
-
#initialize(base) ⇒ Errors
constructor
A new instance of Errors.
-
#initialize_dup(other) ⇒ Object
:nodoc:.
Constructor Details
#initialize(base) ⇒ Errors
Returns a new instance of Errors.
7 8 9 10 11 |
# File 'lib/activemodel_detailed_errors/load_error_details_support.rb', line 7 def initialize(base) @base = base @messages = Hash.new { |, attribute| [attribute] = [] } @details = Hash.new { |details, attribute| details[attribute] = [] } end |
Instance Attribute Details
#details ⇒ Object
Returns the value of attribute details.
5 6 7 |
# File 'lib/activemodel_detailed_errors/load_error_details_support.rb', line 5 def details @details end |
Instance Method Details
#add(attribute, message = :invalid, options = {}) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/activemodel_detailed_errors/load_error_details_support.rb', line 29 def add(attribute, = :invalid, = {}) = .call if .respond_to?(:call) detail = normalize_detail(attribute, , ) = (attribute, , ) if exception = [:strict] exception = ActiveModel::StrictValidationFailed if exception == true raise exception, (attribute, ) end details[attribute.to_sym] << detail self[attribute] << end |
#added?(attribute, message = :invalid, options = {}) ⇒ Boolean
42 43 44 45 46 |
# File 'lib/activemodel_detailed_errors/load_error_details_support.rb', line 42 def added?(attribute, = :invalid, = {}) = .call if .respond_to?(:call) = (attribute, , ) self[attribute].include? end |
#clear ⇒ Object
19 20 21 22 |
# File 'lib/activemodel_detailed_errors/load_error_details_support.rb', line 19 def clear .clear details.clear end |
#delete ⇒ Object
24 25 26 27 |
# File 'lib/activemodel_detailed_errors/load_error_details_support.rb', line 24 def delete .delete(key) details.delete(key) end |
#initialize_dup(other) ⇒ Object
:nodoc:
13 14 15 16 17 |
# File 'lib/activemodel_detailed_errors/load_error_details_support.rb', line 13 def initialize_dup(other) # :nodoc: @messages = other..dup @details = other.details.deep_dup super end |