class ActiveModel::DeprecationHandlingMessageHash

Public Class Methods

new(errors) click to toggle source
Calls superclass method
# File lib/active_model/errors.rb, line 600
def initialize(errors)
  @errors = errors
  super(prepare_content)
end

Public Instance Methods

[]=(attribute, value) click to toggle source
# File lib/active_model/errors.rb, line 605
def []=(attribute, value)
  ActiveSupport::Deprecation.warn("Calling `[]=` to an ActiveModel::Errors is deprecated. Please call `ActiveModel::Errors#add` instead.")

  @errors.delete(attribute)
  Array(value).each do |message|
    @errors.add(attribute, message)
  end

  __setobj__ prepare_content
end
delete(attribute) click to toggle source
# File lib/active_model/errors.rb, line 616
def delete(attribute)
  ActiveSupport::Deprecation.warn("Calling `delete` to an ActiveModel::Errors messages hash is deprecated. Please call `ActiveModel::Errors#delete` instead.")

  @errors.delete(attribute)
end

Private Instance Methods

prepare_content() click to toggle source
# File lib/active_model/errors.rb, line 623
def prepare_content
  content = @errors.to_hash
  content.each do |attribute, value|
    content[attribute] = DeprecationHandlingMessageArray.new(value, @errors, attribute)
  end
  content.default_proc = proc do |hash, attribute|
    hash = hash.dup
    hash[attribute] = DeprecationHandlingMessageArray.new([], @errors, attribute)
    __setobj__ hash.freeze
    hash[attribute]
  end
  content.freeze
end