Class: ActiveModel::AttributeErrors
- Inherits:
-
Object
- Object
- ActiveModel::AttributeErrors
- Includes:
- Enumerable
- Defined in:
- lib/active_model/attribute_errors.rb
Instance Attribute Summary collapse
-
#attribute ⇒ Object
Returns the value of attribute attribute.
-
#errors ⇒ Object
Returns the value of attribute errors.
Instance Method Summary collapse
- #add(message = nil, options = {}) ⇒ Object (also: #<<)
- #each ⇒ Object
- #generate_message(type = :invalid, options = {}) ⇒ Object
- #include?(message) ⇒ Boolean
-
#initialize(base, attribute) ⇒ AttributeErrors
constructor
A new instance of AttributeErrors.
- #to_a ⇒ Object
Constructor Details
#initialize(base, attribute) ⇒ AttributeErrors
Returns a new instance of AttributeErrors.
8 9 10 11 12 |
# File 'lib/active_model/attribute_errors.rb', line 8 def initialize(base, attribute) @base = base @attribute = attribute @errors = [] end |
Instance Attribute Details
#attribute ⇒ Object
Returns the value of attribute attribute.
5 6 7 |
# File 'lib/active_model/attribute_errors.rb', line 5 def attribute @attribute end |
#errors ⇒ Object
Returns the value of attribute errors.
5 6 7 |
# File 'lib/active_model/attribute_errors.rb', line 5 def errors @errors end |
Instance Method Details
#add(message = nil, options = {}) ⇒ Object Also known as: <<
14 15 16 17 |
# File 'lib/active_model/attribute_errors.rb', line 14 def add( = nil, = {}) = (, ) if .is_a?(Symbol) @errors << end |
#each ⇒ Object
21 22 23 |
# File 'lib/active_model/attribute_errors.rb', line 21 def each @errors.each { |error| yield error } end |
#generate_message(type = :invalid, options = {}) ⇒ Object
36 37 38 |
# File 'lib/active_model/attribute_errors.rb', line 36 def (type = :invalid, = {}) @base.(attribute, type, ) end |
#include?(message) ⇒ Boolean
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/active_model/attribute_errors.rb', line 25 def include?() case when Symbol @errors.any? { |error| error.subject == } when String @errors.any? { |error| error.to_s == } else @errors.include?() end end |
#to_a ⇒ Object
40 41 42 |
# File 'lib/active_model/attribute_errors.rb', line 40 def to_a @errors end |