Class: PoroValidator::Errors
- Inherits:
-
Object
- Object
- PoroValidator::Errors
- Defined in:
- lib/poro_validator/errors.rb
Overview
Instance Attribute Summary collapse
- #store ⇒ Object readonly
Instance Method Summary collapse
- #add(attr, validator, *msg_opts) ⇒ Object
- #clear_errors ⇒ Object
- #count ⇒ Object
- #empty? ⇒ Boolean
- #full_messages ⇒ Object
-
#initialize ⇒ Errors
constructor
A new instance of Errors.
- #on(attr) ⇒ Object (also: #[])
Constructor Details
#initialize ⇒ Errors
Returns a new instance of Errors.
6 7 8 |
# File 'lib/poro_validator/errors.rb', line 6 def initialize @store = ErrorStore.new end |
Instance Attribute Details
#store ⇒ Object (readonly)
4 5 6 |
# File 'lib/poro_validator/errors.rb', line 4 def store @store end |
Instance Method Details
#add(attr, validator, *msg_opts) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/poro_validator/errors.rb', line 10 def add(attr, validator, *msg_opts) if store.set?(attr) store.get(attr) << (validator, *msg_opts) else store.set(attr, [(validator, *msg_opts)]) end end |
#clear_errors ⇒ Object
42 43 44 |
# File 'lib/poro_validator/errors.rb', line 42 def clear_errors self.store.reset end |
#count ⇒ Object
18 19 20 21 22 23 |
# File 'lib/poro_validator/errors.rb', line 18 def count store.data.inject(0) do |m, kv| _, errors = *kv m + errors.length end end |
#empty? ⇒ Boolean
25 26 27 |
# File 'lib/poro_validator/errors.rb', line 25 def empty? count == 0 end |
#full_messages ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/poro_validator/errors.rb', line 29 def store.data.inject([]) do |m, kv| attr, errors = *kv errors.each { |e| m << "#{attr} #{e}" } m end end |
#on(attr) ⇒ Object Also known as: []
37 38 39 40 |
# File 'lib/poro_validator/errors.rb', line 37 def on(attr) return unless store.set?(attr) store.get(attr) end |