Class: Cardia::Validateable::Error
- Defined in:
- lib/cardia/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) ⇒ Error
constructor
:nodoc:.
-
#on(field) ⇒ Object
returns a specific fields error message.
Constructor Details
#initialize(base) ⇒ Error
:nodoc:
35 36 37 |
# File 'lib/cardia/validateable.rb', line 35 def initialize(base) @base = base end |
Instance Method Details
#add(field, error) ⇒ Object
50 51 52 53 |
# File 'lib/cardia/validateable.rb', line 50 def add(field, error) self[field] ||= [] self[field] << error end |
#add_to_base(error) ⇒ Object
55 56 57 |
# File 'lib/cardia/validateable.rb', line 55 def add_to_base(error) add(:base, error) end |
#count ⇒ Object
39 40 41 |
# File 'lib/cardia/validateable.rb', line 39 def count size end |
#each_full ⇒ Object
59 60 61 |
# File 'lib/cardia/validateable.rb', line 59 def each_full .each { |msg| yield msg } end |
#full_messages ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/cardia/validateable.rb', line 63 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
46 47 48 |
# File 'lib/cardia/validateable.rb', line 46 def on(field) self[field].to_a.first end |