Class: ActiveModel::DeprecationHandlingMessageHash

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
activemodel/lib/active_model/errors.rb

Instance Method Summary collapse

Constructor Details

#initialize(errors) ⇒ DeprecationHandlingMessageHash

Returns a new instance of DeprecationHandlingMessageHash.


581
582
583
584
# File 'activemodel/lib/active_model/errors.rb', line 581

def initialize(errors)
  @errors = errors
  super(prepare_content)
end

Instance Method Details

#[]=(attribute, value) ⇒ Object


586
587
588
589
590
591
592
593
594
595
# File 'activemodel/lib/active_model/errors.rb', line 586

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) ⇒ Object


597
598
599
600
601
# File 'activemodel/lib/active_model/errors.rb', line 597

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