Class: ActiveMerchant::Validateable::Errors
- Inherits:
-
HashWithIndifferentAccess
- Object
- HashWithIndifferentAccess
- ActiveMerchant::Validateable::Errors
- Defined in:
- lib/active_merchant/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
- #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 |
# File 'lib/active_merchant/common/validateable.rb', line 33 def initialize(base) @base = base end |
Instance Method Details
#add(field, error) ⇒ Object
48 49 50 51 |
# File 'lib/active_merchant/common/validateable.rb', line 48 def add(field, error) self[field] ||= [] self[field] << error end |
#add_to_base(error) ⇒ Object
53 54 55 |
# File 'lib/active_merchant/common/validateable.rb', line 53 def add_to_base(error) add(:base, error) end |
#count ⇒ Object
37 38 39 |
# File 'lib/active_merchant/common/validateable.rb', line 37 def count size end |
#each_full ⇒ Object
57 58 59 |
# File 'lib/active_merchant/common/validateable.rb', line 57 def each_full .each { |msg| yield msg } end |
#full_messages ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/active_merchant/common/validateable.rb', line 61 def result = [] self.each do |key, | 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
44 45 46 |
# File 'lib/active_merchant/common/validateable.rb', line 44 def on(field) self[field].to_a.first end |