Sha256: bda0c52918a7c2cc209fbd3a71a32d81d6ee5913405ce36136ebbe88c7c6961f

Contents?: true

Size: 1021 Bytes

Versions: 8

Compression:

Stored size: 1021 Bytes

Contents

# The Errors class is planned to replace AM::Errors. It provides proper nested error messages.
class Reform::Contract::Errors < ActiveModel::Errors
  def messages
    return super unless Reform.rails3_0?
    self
  end

  # def each
  #   messages.each_key do |attribute|
  #     self[attribute].each { |error| yield attribute, Array.wrap(error) }
  #   end
  # end

  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

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

  def to_s
    messages.inspect
  end
end # Errors

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
reform-2.0.0.rc1 lib/reform/contract/errors.rb
reform-2.0.0.beta2 lib/reform/contract/errors.rb
reform-2.0.0.beta1 lib/reform/contract/errors.rb
reform-1.2.6 lib/reform/contract/errors.rb
reform-1.2.5 lib/reform/contract/errors.rb
reform-1.2.4 lib/reform/contract/errors.rb
reform-1.2.3 lib/reform/contract/errors.rb
reform-1.2.2 lib/reform/contract/errors.rb