Class: ActiveMerchant::Validateable::Errors
- Inherits:
-
HashWithIndifferentAccess
- Object
- HashWithIndifferentAccess
- ActiveMerchant::Validateable::Errors
- Defined in:
- lib/active_utils/common/validateable.rb
Overview
This hash keeps the errors of the object
Instance Method Summary collapse
- #add(field, error) ⇒ Object
- #add_to_base(error) ⇒ Object
- #count ⇒ Object
- #each_full ⇒ Object
- #empty? ⇒ Boolean
- #full_messages ⇒ Object
-
#initialize(base) ⇒ Errors
constructor
A new instance of Errors.
-
#on(field) ⇒ Object
returns a specific fields error message.
Constructor Details
#initialize(base) ⇒ Errors
Returns a new instance of Errors.
33 34 35 36 |
# File 'lib/active_utils/common/validateable.rb', line 33 def initialize(base) super() { |h, k| h[k] = [] ; h[k] } @base = base end |
Instance Method Details
#add(field, error) ⇒ Object
53 54 55 |
# File 'lib/active_utils/common/validateable.rb', line 53 def add(field, error) self[field] << error end |
#add_to_base(error) ⇒ Object
57 58 59 |
# File 'lib/active_utils/common/validateable.rb', line 57 def add_to_base(error) add(:base, error) end |
#count ⇒ Object
38 39 40 |
# File 'lib/active_utils/common/validateable.rb', line 38 def count size end |
#each_full ⇒ Object
61 62 63 |
# File 'lib/active_utils/common/validateable.rb', line 61 def each_full .each { |msg| yield msg } end |
#empty? ⇒ Boolean
42 43 44 |
# File 'lib/active_utils/common/validateable.rb', line 42 def empty? all? { |k, v| v && v.empty? } end |
#full_messages ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/active_utils/common/validateable.rb', line 65 def result = [] self.each do |key, | next if .blank? if key == 'base' result << "#{.first}" else result << "#{key.to_s.humanize} #{.first}" end end result end |
#on(field) ⇒ Object
returns a specific fields error message. if more than one error is available we will only return the first. If no error is available we return an empty string
49 50 51 |
# File 'lib/active_utils/common/validateable.rb', line 49 def on(field) self[field].to_a.first end |