Class: Reform::Contract::Errors
- Inherits:
-
ActiveModel::Errors
- Object
- ActiveModel::Errors
- Reform::Contract::Errors
- Defined in:
- lib/reform/contract/errors.rb
Overview
The Errors class is planned to replace AM::Errors. It provides proper nested error messages.
Instance Method Summary collapse
-
#merge!(errors, prefix) ⇒ Object
def each messages.each_key do |attribute| self.each { |error| yield attribute, Array.wrap(error) } end end.
- #messages ⇒ Object
- #to_s ⇒ Object
-
#valid? ⇒ Boolean
TODO: test me in unit test.
Instance Method Details
#merge!(errors, prefix) ⇒ Object
def each
.each_key do |attribute|
self[attribute].each { |error| yield attribute, Array.wrap(error) }
end
end
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/reform/contract/errors.rb', line 14 def merge!(errors, prefix) # TODO: merge into AM. errors..each do |field, msgs| unless field.to_sym == :base field = (prefix+[field]).join(".").to_sym # TODO: why is that a symbol in Rails? end msgs = [msgs] if Reform.rails3_0? # DISCUSS: fix in #each? msgs.each do |msg| next if [field] and [field].include?(msg) add(field, msg) end # Forms now contains a plain errors hash. the errors for each item are still available in item.errors. end end |
#messages ⇒ Object
3 4 5 6 |
# File 'lib/reform/contract/errors.rb', line 3 def return super unless Reform.rails3_0? self end |
#to_s ⇒ Object
34 35 36 |
# File 'lib/reform/contract/errors.rb', line 34 def to_s .inspect end |
#valid? ⇒ Boolean
TODO: test me in unit test.
30 31 32 |
# File 'lib/reform/contract/errors.rb', line 30 def valid? # TODO: test me in unit test. blank? end |