Skip to content

Commit 3ae6284

Browse files
committed
Fix indentation
1 parent b60cf01 commit 3ae6284

File tree

1 file changed

+119
-119
lines changed

1 file changed

+119
-119
lines changed

activerecord/lib/active_record/persistence.rb

Lines changed: 119 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -810,159 +810,159 @@ def touch(*names, time: nil)
810810
end
811811
end
812812

813-
private
814-
def init_internals
815-
super
816-
@_trigger_destroy_callback = @_trigger_update_callback = nil
817-
@previously_new_record = false
818-
end
813+
private
814+
def init_internals
815+
super
816+
@_trigger_destroy_callback = @_trigger_update_callback = nil
817+
@previously_new_record = false
818+
end
819819

820-
def strict_loaded_associations
821-
@association_cache.find_all do |_, assoc|
822-
assoc.owner.strict_loading? && !assoc.owner.strict_loading_n_plus_one_only?
823-
end.map(&:first)
824-
end
820+
def strict_loaded_associations
821+
@association_cache.find_all do |_, assoc|
822+
assoc.owner.strict_loading? && !assoc.owner.strict_loading_n_plus_one_only?
823+
end.map(&:first)
824+
end
825825

826-
def _find_record(options)
827-
all_queries = options ? options[:all_queries] : nil
828-
base = self.class.all(all_queries: all_queries).preload(strict_loaded_associations)
826+
def _find_record(options)
827+
all_queries = options ? options[:all_queries] : nil
828+
base = self.class.all(all_queries: all_queries).preload(strict_loaded_associations)
829829

830-
if options && options[:lock]
831-
base.lock(options[:lock]).find_by!(_in_memory_query_constraints_hash)
832-
else
833-
base.find_by!(_in_memory_query_constraints_hash)
830+
if options && options[:lock]
831+
base.lock(options[:lock]).find_by!(_in_memory_query_constraints_hash)
832+
else
833+
base.find_by!(_in_memory_query_constraints_hash)
834+
end
834835
end
835-
end
836836

837-
def _in_memory_query_constraints_hash
838-
if self.class.query_constraints_list.nil?
839-
{ @primary_key => id }
840-
else
841-
self.class.query_constraints_list.index_with do |column_name|
842-
attribute(column_name)
837+
def _in_memory_query_constraints_hash
838+
if self.class.query_constraints_list.nil?
839+
{ @primary_key => id }
840+
else
841+
self.class.query_constraints_list.index_with do |column_name|
842+
attribute(column_name)
843+
end
843844
end
844845
end
845-
end
846846

847-
def apply_scoping?(options)
848-
!(options && options[:unscoped]) &&
849-
(self.class.default_scopes?(all_queries: true) || self.class.global_current_scope)
850-
end
847+
def apply_scoping?(options)
848+
!(options && options[:unscoped]) &&
849+
(self.class.default_scopes?(all_queries: true) || self.class.global_current_scope)
850+
end
851851

852-
def _query_constraints_hash
853-
if self.class.query_constraints_list.nil?
854-
{ @primary_key => id_in_database }
855-
else
856-
self.class.query_constraints_list.index_with do |column_name|
857-
attribute_in_database(column_name)
852+
def _query_constraints_hash
853+
if self.class.query_constraints_list.nil?
854+
{ @primary_key => id_in_database }
855+
else
856+
self.class.query_constraints_list.index_with do |column_name|
857+
attribute_in_database(column_name)
858+
end
858859
end
859860
end
860-
end
861-
862-
# A hook to be overridden by association modules.
863-
def destroy_associations
864-
end
865-
866-
def destroy_row
867-
_delete_row
868-
end
869861

870-
def _delete_row
871-
self.class._delete_record(_query_constraints_hash)
872-
end
862+
# A hook to be overridden by association modules.
863+
def destroy_associations
864+
end
873865

874-
def _touch_row(attribute_names, time)
875-
time ||= current_time_from_proper_timezone
866+
def destroy_row
867+
_delete_row
868+
end
876869

877-
attribute_names.each do |attr_name|
878-
_write_attribute(attr_name, time)
870+
def _delete_row
871+
self.class._delete_record(_query_constraints_hash)
879872
end
880873

881-
_update_row(attribute_names, "touch")
882-
end
874+
def _touch_row(attribute_names, time)
875+
time ||= current_time_from_proper_timezone
883876

884-
def _update_row(attribute_names, attempted_action = "update")
885-
self.class._update_record(
886-
attributes_with_values(attribute_names),
887-
_query_constraints_hash
888-
)
889-
end
877+
attribute_names.each do |attr_name|
878+
_write_attribute(attr_name, time)
879+
end
890880

891-
def create_or_update(**, &block)
892-
_raise_readonly_record_error if readonly?
893-
return false if destroyed?
894-
result = new_record? ? _create_record(&block) : _update_record(&block)
895-
result != false
896-
end
881+
_update_row(attribute_names, "touch")
882+
end
897883

898-
# Updates the associated record with values matching those of the instance attributes.
899-
# Returns the number of affected rows.
900-
def _update_record(attribute_names = self.attribute_names)
901-
attribute_names = attributes_for_update(attribute_names)
884+
def _update_row(attribute_names, attempted_action = "update")
885+
self.class._update_record(
886+
attributes_with_values(attribute_names),
887+
_query_constraints_hash
888+
)
889+
end
902890

903-
if attribute_names.empty?
904-
affected_rows = 0
905-
@_trigger_update_callback = true
906-
else
907-
affected_rows = _update_row(attribute_names)
908-
@_trigger_update_callback = affected_rows == 1
891+
def create_or_update(**, &block)
892+
_raise_readonly_record_error if readonly?
893+
return false if destroyed?
894+
result = new_record? ? _create_record(&block) : _update_record(&block)
895+
result != false
909896
end
910897

911-
@previously_new_record = false
898+
# Updates the associated record with values matching those of the instance attributes.
899+
# Returns the number of affected rows.
900+
def _update_record(attribute_names = self.attribute_names)
901+
attribute_names = attributes_for_update(attribute_names)
912902

913-
yield(self) if block_given?
903+
if attribute_names.empty?
904+
affected_rows = 0
905+
@_trigger_update_callback = true
906+
else
907+
affected_rows = _update_row(attribute_names)
908+
@_trigger_update_callback = affected_rows == 1
909+
end
914910

915-
affected_rows
916-
end
911+
@previously_new_record = false
917912

918-
# Creates a record with values matching those of the instance attributes
919-
# and returns its id.
920-
def _create_record(attribute_names = self.attribute_names)
921-
attribute_names = attributes_for_create(attribute_names)
913+
yield(self) if block_given?
922914

923-
self.class.with_connection do |connection|
924-
returning_columns = self.class._returning_columns_for_insert(connection)
915+
affected_rows
916+
end
925917

926-
returning_values = self.class._insert_record(
927-
connection,
928-
attributes_with_values(attribute_names),
929-
returning_columns
930-
)
918+
# Creates a record with values matching those of the instance attributes
919+
# and returns its id.
920+
def _create_record(attribute_names = self.attribute_names)
921+
attribute_names = attributes_for_create(attribute_names)
931922

932-
returning_columns.zip(returning_values).each do |column, value|
933-
_write_attribute(column, value) if !_read_attribute(column)
934-
end if returning_values
935-
end
923+
self.class.with_connection do |connection|
924+
returning_columns = self.class._returning_columns_for_insert(connection)
936925

937-
@new_record = false
938-
@previously_new_record = true
926+
returning_values = self.class._insert_record(
927+
connection,
928+
attributes_with_values(attribute_names),
929+
returning_columns
930+
)
939931

940-
yield(self) if block_given?
932+
returning_columns.zip(returning_values).each do |column, value|
933+
_write_attribute(column, value) if !_read_attribute(column)
934+
end if returning_values
935+
end
941936

942-
id
943-
end
937+
@new_record = false
938+
@previously_new_record = true
944939

945-
def verify_readonly_attribute(name)
946-
raise ActiveRecordError, "#{name} is marked as readonly" if self.class.readonly_attribute?(name)
947-
end
940+
yield(self) if block_given?
948941

949-
def _raise_record_not_destroyed
950-
@_association_destroy_exception ||= nil
951-
key = self.class.primary_key
952-
raise @_association_destroy_exception || RecordNotDestroyed.new("Failed to destroy #{self.class} with #{key}=#{id}", self)
953-
ensure
954-
@_association_destroy_exception = nil
955-
end
942+
id
943+
end
956944

957-
def _raise_readonly_record_error
958-
raise ReadOnlyRecord, "#{self.class} is marked as readonly"
959-
end
945+
def verify_readonly_attribute(name)
946+
raise ActiveRecordError, "#{name} is marked as readonly" if self.class.readonly_attribute?(name)
947+
end
960948

961-
def _raise_record_not_touched_error
962-
raise ActiveRecordError, <<~MSG.squish
963-
Cannot touch on a new or destroyed record object. Consider using
964-
persisted?, new_record?, or destroyed? before touching.
965-
MSG
966-
end
949+
def _raise_record_not_destroyed
950+
@_association_destroy_exception ||= nil
951+
key = self.class.primary_key
952+
raise @_association_destroy_exception || RecordNotDestroyed.new("Failed to destroy #{self.class} with #{key}=#{id}", self)
953+
ensure
954+
@_association_destroy_exception = nil
955+
end
956+
957+
def _raise_readonly_record_error
958+
raise ReadOnlyRecord, "#{self.class} is marked as readonly"
959+
end
960+
961+
def _raise_record_not_touched_error
962+
raise ActiveRecordError, <<~MSG.squish
963+
Cannot touch on a new or destroyed record object. Consider using
964+
persisted?, new_record?, or destroyed? before touching.
965+
MSG
966+
end
967967
end
968968
end

0 commit comments

Comments
 (0)