aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/persistence.rb
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2019-04-29 18:49:12 +0900
committerRyuta Kamizono <kamipo@gmail.com>2019-04-29 18:49:12 +0900
commit302d739855306f9061f1f2357844cb8d76f20ae9 (patch)
treee219a57c33e4f72035d0f330c6ddc55ca7c05e9c /activerecord/lib/active_record/persistence.rb
parente6c177e07cd4ea42df751b5baef8858efa97dfbd (diff)
downloadrails-302d739855306f9061f1f2357844cb8d76f20ae9.tar.gz
rails-302d739855306f9061f1f2357844cb8d76f20ae9.tar.bz2
rails-302d739855306f9061f1f2357844cb8d76f20ae9.zip
Extract `_raise_record_not_touched_error`
Diffstat (limited to 'activerecord/lib/active_record/persistence.rb')
-rw-r--r--activerecord/lib/active_record/persistence.rb22
1 files changed, 12 insertions, 10 deletions
diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb
index adfd564695..a58c5fd48a 100644
--- a/activerecord/lib/active_record/persistence.rb
+++ b/activerecord/lib/active_record/persistence.rb
@@ -849,12 +849,7 @@ module ActiveRecord
# ball.touch(:updated_at) # => raises ActiveRecordError
#
def touch(*names, time: nil)
- unless persisted?
- raise ActiveRecordError, <<-MSG.squish
- cannot touch on a new or destroyed record object. Consider using
- persisted?, new_record?, or destroyed? before touching
- MSG
- end
+ _raise_record_not_touched_error unless persisted?
attribute_names = timestamp_attributes_for_update_in_model
attribute_names |= names.map!(&:to_s).map! { |name|
@@ -954,14 +949,21 @@ module ActiveRecord
@_association_destroy_exception = nil
end
+ def _raise_readonly_record_error
+ raise ReadOnlyRecord, "#{self.class} is marked as readonly"
+ end
+
+ def _raise_record_not_touched_error
+ raise ActiveRecordError, <<~MSG.squish
+ Cannot touch on a new or destroyed record object. Consider using
+ persisted?, new_record?, or destroyed? before touching.
+ MSG
+ end
+
# The name of the method used to touch a +belongs_to+ association when the
# +:touch+ option is used.
def belongs_to_touch_method
:touch
end
-
- def _raise_readonly_record_error
- raise ReadOnlyRecord, "#{self.class} is marked as readonly"
- end
end
end