Class: Valcro::ErrorList
- Inherits:
-
Object
- Object
- Valcro::ErrorList
- Defined in:
- lib/valcro/error_list.rb
Instance Attribute Summary collapse
-
#errors ⇒ Object
Returns the value of attribute errors.
Instance Method Summary collapse
- #<<(error) ⇒ Object
- #[](prop) ⇒ Object
- #add(prop, message) ⇒ Object
- #any? ⇒ Boolean
- #clear! ⇒ Object
- #full_messages ⇒ Object
-
#initialize ⇒ ErrorList
constructor
A new instance of ErrorList.
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ ErrorList
Returns a new instance of ErrorList.
4 5 6 |
# File 'lib/valcro/error_list.rb', line 4 def initialize @errors = [] end |
Instance Attribute Details
#errors ⇒ Object
Returns the value of attribute errors.
3 4 5 |
# File 'lib/valcro/error_list.rb', line 3 def errors @errors end |
Instance Method Details
#<<(error) ⇒ Object
8 9 10 |
# File 'lib/valcro/error_list.rb', line 8 def <<(error) @errors << error end |
#[](prop) ⇒ Object
16 17 18 |
# File 'lib/valcro/error_list.rb', line 16 def [](prop) @errors.select { |error| error.property == prop }.map(&:message) || [] end |
#add(prop, message) ⇒ Object
12 13 14 |
# File 'lib/valcro/error_list.rb', line 12 def add(prop, ) @errors << Valcro::Error.new(prop, ) end |
#any? ⇒ Boolean
32 33 34 |
# File 'lib/valcro/error_list.rb', line 32 def any? @errors.any? end |
#clear! ⇒ Object
20 21 22 |
# File 'lib/valcro/error_list.rb', line 20 def clear! @errors = [] end |
#full_messages ⇒ Object
24 25 26 |
# File 'lib/valcro/error_list.rb', line 24 def @errors.map(&:to_s) end |
#to_s ⇒ Object
28 29 30 |
# File 'lib/valcro/error_list.rb', line 28 def to_s .join(' ') end |