Class: Compel::Errors
- Inherits:
-
Object
- Object
- Compel::Errors
- Defined in:
- lib/compel/errors.rb
Instance Method Summary collapse
- #add(key, error) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize ⇒ Errors
constructor
A new instance of Errors.
- #length ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize ⇒ Errors
Returns a new instance of Errors.
5 6 7 |
# File 'lib/compel/errors.rb', line 5 def initialize @errors = {} end |
Instance Method Details
#add(key, error) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/compel/errors.rb', line 9 def add(key, error) if error.nil? || error.empty? return end if error.is_a?(Compel::Errors) || error.is_a?(Hash) if @errors[key].nil? @errors[key] = {} end @errors[key].merge!(error.to_hash) else if @errors[key].nil? @errors[key] = [] end if !error.is_a?(Array) error = [error] end @errors[key].concat(error) end @errors end |
#empty? ⇒ Boolean
39 40 41 |
# File 'lib/compel/errors.rb', line 39 def empty? length == 0 end |
#length ⇒ Object
35 36 37 |
# File 'lib/compel/errors.rb', line 35 def length @errors.keys.length end |
#to_hash ⇒ Object
43 44 45 |
# File 'lib/compel/errors.rb', line 43 def to_hash @errors end |