2008-03-31 19:40:34 -04:00
|
|
|
module ActiveModel
|
|
|
|
module DeprecatedErrorMethods
|
|
|
|
def on(attribute)
|
2009-03-20 13:36:22 -04:00
|
|
|
message = "Errors#on have been deprecated, use Errors#[] instead.\n"
|
2009-03-20 14:12:21 -04:00
|
|
|
message << "Also note that the behaviour of Errors#[] has changed. Errors#[] now always returns an Array. An empty Array is "
|
|
|
|
message << "returned when there are no errors on the specified attribute."
|
2009-03-20 13:36:22 -04:00
|
|
|
ActiveSupport::Deprecation.warn(message)
|
2009-03-20 11:27:55 -04:00
|
|
|
|
2009-03-19 19:28:59 -04:00
|
|
|
errors = self[attribute]
|
|
|
|
errors.size < 2 ? errors.first : errors
|
2008-03-31 19:40:34 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def on_base
|
2009-03-21 14:29:15 -04:00
|
|
|
ActiveSupport::Deprecation.warn "Errors#on_base have been deprecated, use Errors#[:base] instead"
|
|
|
|
ActiveSupport::Deprecation.silence { on(:base) }
|
2008-03-31 19:40:34 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def add_to_base(msg)
|
2009-03-21 14:29:15 -04:00
|
|
|
ActiveSupport::Deprecation.warn "Errors#add_to_base(msg) has been deprecated, use Errors#[:base] << msg instead"
|
2008-03-31 19:40:34 -04:00
|
|
|
self[:base] << msg
|
|
|
|
end
|
2009-06-08 21:32:08 -04:00
|
|
|
|
2008-03-31 19:40:34 -04:00
|
|
|
def invalid?(attribute)
|
2009-03-21 14:29:15 -04:00
|
|
|
ActiveSupport::Deprecation.warn "Errors#invalid?(attribute) has been deprecated, use Errors#[attribute].any? instead"
|
2008-03-31 19:40:34 -04:00
|
|
|
self[attribute].any?
|
|
|
|
end
|
|
|
|
|
|
|
|
def each_full
|
2009-03-21 14:29:15 -04:00
|
|
|
ActiveSupport::Deprecation.warn "Errors#each_full has been deprecated, use Errors#to_a.each instead"
|
2008-03-31 19:40:34 -04:00
|
|
|
to_a.each { |error| yield error }
|
|
|
|
end
|
|
|
|
end
|
2009-06-08 21:32:08 -04:00
|
|
|
end
|