Class: MemModel::Errors
- Inherits:
-
Object
- Object
- MemModel::Errors
- Includes:
- Enumerable
- Defined in:
- lib/mem_model/errors.rb
Instance Attribute Summary collapse
-
#messages ⇒ Object
readonly
Returns the value of attribute messages.
Instance Method Summary collapse
- #[](attribute) ⇒ Object
- #[]=(attribute, error) ⇒ Object
- #each ⇒ Object
- #full_message(attribute, message) ⇒ Object
- #full_messages ⇒ Object
- #get(key) ⇒ Object
-
#initialize(base) ⇒ Errors
constructor
A new instance of Errors.
- #set(key, value) ⇒ Object
Constructor Details
#initialize(base) ⇒ Errors
Returns a new instance of Errors.
10 11 12 13 |
# File 'lib/mem_model/errors.rb', line 10 def initialize(base) @base = base @messages = {} end |
Instance Attribute Details
#messages ⇒ Object (readonly)
Returns the value of attribute messages.
8 9 10 |
# File 'lib/mem_model/errors.rb', line 8 def @messages end |
Instance Method Details
#[](attribute) ⇒ Object
29 30 31 |
# File 'lib/mem_model/errors.rb', line 29 def [](attribute) get(attribute.to_sym) || set(attribute.to_sym, []) end |
#[]=(attribute, error) ⇒ Object
33 34 35 |
# File 'lib/mem_model/errors.rb', line 33 def []=(attribute, error) self[attribute] << error end |
#each ⇒ Object
15 16 17 18 19 |
# File 'lib/mem_model/errors.rb', line 15 def each .each_key do |attribute| self[attribute].each { |error| yield attribute, error } end end |
#full_message(attribute, message) ⇒ Object
25 26 27 |
# File 'lib/mem_model/errors.rb', line 25 def (attribute, ) [attribute, ].join(' ') end |
#full_messages ⇒ Object
21 22 23 |
# File 'lib/mem_model/errors.rb', line 21 def map { |attribute, | (attribute, ) } end |
#get(key) ⇒ Object
37 38 39 |
# File 'lib/mem_model/errors.rb', line 37 def get(key) [key] end |
#set(key, value) ⇒ Object
41 42 43 |
# File 'lib/mem_model/errors.rb', line 41 def set(key, value) [key] = value end |