From d9011e39357300fe78720227af4c13b4bc4ac4dd Mon Sep 17 00:00:00 2001 From: lulalala Date: Tue, 20 Mar 2018 22:39:44 +0800 Subject: Change errors Allow `each` to behave in new way if block arity is 1 Ensure dumped marshal from Rails 5 can be loaded Make errors compatible with marshal and YAML dumps from previous versions of Rails Add deprecation warnings Ensure each behave like the past, sorted by attribute --- activemodel/lib/active_model/error.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'activemodel/lib/active_model/error.rb') diff --git a/activemodel/lib/active_model/error.rb b/activemodel/lib/active_model/error.rb index 214a0b356d..b1912f2604 100644 --- a/activemodel/lib/active_model/error.rb +++ b/activemodel/lib/active_model/error.rb @@ -8,7 +8,7 @@ module ActiveModel CALLBACKS_OPTIONS = [:if, :unless, :on, :allow_nil, :allow_blank, :strict] MESSAGE_OPTIONS = [:message] - def initialize(base, attribute, type, **options) + def initialize(base, attribute, type = :invalid, **options) @base = base @attribute = attribute @raw_type = type @@ -56,5 +56,11 @@ module ActiveModel true end + + def strict_match?(attribute, type, **options) + return false unless match?(attribute, type, **options) + + full_message == Error.new(@base, attribute, type, **options).full_message + end end end -- cgit v1.2.3