Class: Validatable::Errors
Instance Method Summary collapse
-
#add(attribute, message) ⇒ Object
:nodoc:.
-
#count ⇒ Object
:nodoc:.
-
#errors ⇒ Object
:nodoc:.
-
#full_messages ⇒ Object
call-seq: full_messages -> an_array_of_messages.
-
#humanize(lower_case_and_underscored_word) ⇒ Object
:nodoc:.
-
#merge!(errors) ⇒ Object
:nodoc:.
-
#on(attribute) ⇒ Object
call-seq: on(attribute).
-
#raw(attribute) ⇒ Object
call-seq: raw(attribute).
-
#replace(attribute, value) ⇒ Object
call-seq: replace(attribute).
Methods included from Enumerable
Instance Method Details
#add(attribute, message) ⇒ Object
:nodoc:
18 19 20 21 |
# File 'lib/gems/validatable-1.6.7/lib/errors.rb', line 18 def add(attribute, ) #:nodoc: errors[attribute.to_sym] = [] if errors[attribute.to_sym].nil? errors[attribute.to_sym] << end |
#count ⇒ Object
:nodoc:
46 47 48 |
# File 'lib/gems/validatable-1.6.7/lib/errors.rb', line 46 def count #:nodoc: errors.values.flatten.size end |
#errors ⇒ Object
:nodoc:
42 43 44 |
# File 'lib/gems/validatable-1.6.7/lib/errors.rb', line 42 def errors #:nodoc: @errors ||= {} end |
#full_messages ⇒ Object
call-seq: full_messages -> an_array_of_messages
Returns an array containing the full list of error messages.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/gems/validatable-1.6.7/lib/errors.rb', line 53 def = [] errors.each_key do |attribute| errors[attribute].each do |msg| next if msg.nil? if attribute.to_s == "base" << msg else << humanize(attribute.to_s) + " " + msg end end end end |
#humanize(lower_case_and_underscored_word) ⇒ Object
:nodoc:
70 71 72 |
# File 'lib/gems/validatable-1.6.7/lib/errors.rb', line 70 def humanize(lower_case_and_underscored_word) #:nodoc: lower_case_and_underscored_word.to_s.gsub(/_id$/, "").gsub(/_/, " ").capitalize end |
#merge!(errors) ⇒ Object
:nodoc:
23 24 25 26 |
# File 'lib/gems/validatable-1.6.7/lib/errors.rb', line 23 def merge!(errors) #:nodoc: errors.each_pair{|k, v| add(k,v)} self end |
#on(attribute) ⇒ Object
call-seq: on(attribute)
-
Returns nil, if no errors are associated with the specified
attribute
. -
Returns the error message, if one error is associated with the specified
attribute
. -
Returns an array of error messages, if more than one error is associated with the specified
attribute
.
13 14 15 16 |
# File 'lib/gems/validatable-1.6.7/lib/errors.rb', line 13 def on(attribute) return nil if errors[attribute.to_sym].nil? errors[attribute.to_sym].size == 1 ? errors[attribute.to_sym].first : errors[attribute.to_sym] end |
#raw(attribute) ⇒ Object
call-seq: raw(attribute)
-
Returns an array of error messages associated with the specified
attribute
.
38 39 40 |
# File 'lib/gems/validatable-1.6.7/lib/errors.rb', line 38 def raw(attribute) errors[attribute.to_sym] end |
#replace(attribute, value) ⇒ Object
call-seq: replace(attribute)
-
Replaces the errors value for the given
attribute
31 32 33 |
# File 'lib/gems/validatable-1.6.7/lib/errors.rb', line 31 def replace(attribute, value) errors[attribute.to_sym] = value end |