From b55f5a3ed9134ed86993fcda3ea9b6fb2e97f09e Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Mon, 27 May 2019 06:41:31 +0900 Subject: [PATCH] Extract `readonly_attribute?` --- activerecord/lib/active_record/attribute_methods.rb | 6 +----- activerecord/lib/active_record/persistence.rb | 2 +- activerecord/lib/active_record/readonly_attributes.rb | 4 ++++ 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/activerecord/lib/active_record/attribute_methods.rb b/activerecord/lib/active_record/attribute_methods.rb index 220043c061e17..6e4f76aa73eea 100644 --- a/activerecord/lib/active_record/attribute_methods.rb +++ b/activerecord/lib/active_record/attribute_methods.rb @@ -437,7 +437,7 @@ def attributes_with_values(attribute_names) def attributes_for_update(attribute_names) attribute_names &= self.class.column_names attribute_names.delete_if do |name| - readonly_attribute?(name) + self.class.readonly_attribute?(name) end end @@ -460,10 +460,6 @@ def format_for_inspect(value) end end - def readonly_attribute?(name) - self.class.readonly_attributes.include?(name) - end - def pk_attribute?(name) name == @primary_key end diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb index a58c5fd48a108..b7bc4b3b8ebac 100644 --- a/activerecord/lib/active_record/persistence.rb +++ b/activerecord/lib/active_record/persistence.rb @@ -939,7 +939,7 @@ def _create_record(attribute_names = self.attribute_names) end def verify_readonly_attribute(name) - raise ActiveRecordError, "#{name} is marked as readonly" if self.class.readonly_attributes.include?(name) + raise ActiveRecordError, "#{name} is marked as readonly" if self.class.readonly_attribute?(name) end def _raise_record_not_destroyed diff --git a/activerecord/lib/active_record/readonly_attributes.rb b/activerecord/lib/active_record/readonly_attributes.rb index 7bc26993d54d5..c851ed52c33f0 100644 --- a/activerecord/lib/active_record/readonly_attributes.rb +++ b/activerecord/lib/active_record/readonly_attributes.rb @@ -19,6 +19,10 @@ def attr_readonly(*attributes) def readonly_attributes _attr_readonly end + + def readonly_attribute?(name) # :nodoc: + _attr_readonly.include?(name) + end end end end