aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib/active_model/deprecated_error_methods.rb
blob: c3cc1d53ae4e8b4d46649e9d29ae8e9c1f198a78 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
module ActiveModel
  module DeprecatedErrorMethods
    def on(attribute)
      # message = "Errors#on have been deprecated, use Errors#[] instead.\n"
      # message << "Also note that the behaviour of Errors#[] has changed. Errors#[] now always returns an Array and an empty Array when "
      # message << "there are not errors on the specified attribute."
      # ActiveSupport::Deprecation.warn(message)

      errors = self[attribute]
      errors.size < 2 ? errors.first : errors
    end

    def on_base
      # ActiveSupport::Deprecation.warn "Errors#on_base have been deprecated, use Errors#[:base] instead"
      on(:base)
    end

    def add_to_base(msg)
      # ActiveSupport::Deprecation.warn "Errors#add_to_base(msg) has been deprecated, use Errors#[:base] << msg instead"
      self[:base] << msg
    end
  
    def invalid?(attribute)
      # ActiveSupport::Deprecation.warn "Errors#invalid?(attribute) has been deprecated, use Errors#[attribute].any? instead"
      self[attribute].any?
    end

    def each_full
      # ActiveSupport::Deprecation.warn "Errors#each_full has been deprecated, use Errors#to_a.each instead"
      to_a.each { |error| yield error }
    end
  end
end