aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib/active_model/error.rb
diff options
context:
space:
mode:
authorlulalala <mark@goodlife.tw>2018-03-20 22:39:44 +0800
committerlulalala <mark@goodlife.tw>2019-03-31 22:59:12 +0800
commitd9011e39357300fe78720227af4c13b4bc4ac4dd (patch)
treeba9b8a536f073c12c32019a4180b32b7241c0879 /activemodel/lib/active_model/error.rb
parentef68d3e35cb58f9f491993eeec6e7de99442dd06 (diff)
downloadrails-d9011e39357300fe78720227af4c13b4bc4ac4dd.tar.gz
rails-d9011e39357300fe78720227af4c13b4bc4ac4dd.tar.bz2
rails-d9011e39357300fe78720227af4c13b4bc4ac4dd.zip
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
Diffstat (limited to 'activemodel/lib/active_model/error.rb')
-rw-r--r--activemodel/lib/active_model/error.rb8
1 files changed, 7 insertions, 1 deletions
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