Class: ActiveModel::Error
- Defined in:
- lib/reactive_record/active_record/error.rb
Instance Attribute Summary collapse
-
#messages ⇒ Object
readonly
Returns the value of attribute messages.
Instance Method Summary collapse
- #[](attribute) ⇒ Object
- #add(attribute, message = :invalid, _options = {}) ⇒ Object
- #clear ⇒ Object
- #delete(attribute) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(initial_msgs = {}) ⇒ Error
constructor
A new instance of Error.
Constructor Details
#initialize(initial_msgs = {}) ⇒ Error
Returns a new instance of Error.
6 7 8 9 |
# File 'lib/reactive_record/active_record/error.rb', line 6 def initialize(initial_msgs = {}) @messages = Hash.new { |h, k| h[k] = [] } initial_msgs.each { |attr, msgs| @messages[attr] = msgs.uniq } end |
Instance Attribute Details
#messages ⇒ Object (readonly)
Returns the value of attribute messages.
4 5 6 |
# File 'lib/reactive_record/active_record/error.rb', line 4 def @messages end |
Instance Method Details
#[](attribute) ⇒ Object
11 12 13 |
# File 'lib/reactive_record/active_record/error.rb', line 11 def [](attribute) [attribute] end |
#add(attribute, message = :invalid, _options = {}) ⇒ Object
27 28 29 |
# File 'lib/reactive_record/active_record/error.rb', line 27 def add(attribute, = :invalid, = {}) @messages[attribute] << unless @messages[attribute].include? end |
#clear ⇒ Object
23 24 25 |
# File 'lib/reactive_record/active_record/error.rb', line 23 def clear @messages.clear end |
#delete(attribute) ⇒ Object
15 16 17 |
# File 'lib/reactive_record/active_record/error.rb', line 15 def delete(attribute) .delete(attribute) end |
#empty? ⇒ Boolean
19 20 21 |
# File 'lib/reactive_record/active_record/error.rb', line 19 def empty? .empty? end |