Class: Reform::Contract::Errors

Inherits:
ActiveModel::Errors
  • Object
show all
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

Instance Method Details

#merge!(errors, prefix) ⇒ Object

def each

messages.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.messages.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 messages[field] and messages[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

#messagesObject



3
4
5
6
# File 'lib/reform/contract/errors.rb', line 3

def messages
  return super unless Reform.rails3_0?
  self
end

#to_sObject



34
35
36
# File 'lib/reform/contract/errors.rb', line 34

def to_s
  messages.inspect
end

#valid?Boolean

TODO: test me in unit test.

Returns:

  • (Boolean)


30
31
32
# File 'lib/reform/contract/errors.rb', line 30

def valid? # TODO: test me in unit test.
  blank?
end