rails_delete_all_and_assocs_without_instantiation 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 29a1a21db1dd7be9228776c4dd8c0f62fe53e626292fdc3423a60659ffe6bfbb
4
- data.tar.gz: f1d447a7c617b90061ad3f836074449fed01d0bbf3fd2f98f1f6f50b027fb23b
3
+ metadata.gz: cef795591d41dcdd1dfbb7c64f25d1e070640dad50d2635e605a7315be0f4bd3
4
+ data.tar.gz: 930cbbdee057d7444db66ce1855b8ca9b6e1f42f8ec9e67e88b45c8a2d9ff830
5
5
  SHA512:
6
- metadata.gz: 4d4ca0d71e2f5f4916dedbf510478e3cd3b431f48116ff83479fa7f3502e2e5c0878833348827eb5f873f7c617c50095281abe72c936cbb6189c28ee67a7aa0c
7
- data.tar.gz: 16f5c31e7c3971094b98bf90ae3a9d40fc276a3b5abd5d29502484978143e2fdb0b05c635fe75aea604c42476ed191f1e809be3f9d2c25f289c6154cbfcb2555
6
+ metadata.gz: d4a7553953c99a07638e27294dd28db610accb1bc6db8c07ef43f2ea13ee47fd5ec34dfd57a6a0b40115047c3925475c1f3234691a4db5037773d33ebf6006ed
7
+ data.tar.gz: ad2091ccff93424d1616bcca3eff51f9af9592245d1846b95a4d91509247072685bc777b7c54687dd35854d50e1b3ccaf6fca4e06f45a9445f389246244b17ab
@@ -1,5 +1,13 @@
1
1
  module RailsDeleteAllAndAssocsWithoutInstantiation
2
2
  module DeleteAllAndAssocsWithoutInstantiation
3
+ MATCH_DEPENDENT_ASSOC_VALUE = [
4
+ :destroy,
5
+ 'destroy',
6
+ :delete_all,
7
+ 'delete_all',
8
+ :destroy_async,
9
+ 'destroy_async',
10
+ ]
3
11
 
4
12
  # rails interpretation is different than expected:
5
13
  # https://makandracards.com/makandra/32175-don-t-forget-automatically-remove-join-records-on-has_many-through-associations
@@ -22,7 +30,7 @@ module RailsDeleteAllAndAssocsWithoutInstantiation
22
30
  # force_through_destroy_chains = options[:force_destroy_chain] || {}
23
31
  # do_not_destroy_self = options[:do_not_destroy] || {}
24
32
 
25
- current_class = self::class
33
+ current_class = self.name
26
34
  current_query = self
27
35
  ids = current_query.pluck(:id)
28
36
  models_and_ids_list[name] ||= []
@@ -33,14 +41,14 @@ module RailsDeleteAllAndAssocsWithoutInstantiation
33
41
  return models_and_ids_list, errors
34
42
  end
35
43
 
36
- models_and_ids_list[self.name] = ids
44
+ models_and_ids_list[self.name] += ids
37
45
 
38
46
  # if do_not_destroy_self != true
39
47
  # models_and_ids_list[name] += ids
40
48
  # end
41
49
 
42
50
  # ignore associations that aren't dependent destroyable.
43
- destroy_association_names = self.reflect_on_all_associations.reject{|v| ![:destroy, 'destroy'].include?(v.options&.dig(:dependent)) }.collect{ |v| v.name }
51
+ destroy_association_names = self.reflect_on_all_associations.reject{|v| !MATCH_DEPENDENT_ASSOC_VALUE.include?(v.options&.dig(:dependent)) }.collect{ |v| v.name }
44
52
 
45
53
 
46
54
  # associations that we might not necessarilly need to delete, but need to go through
@@ -145,6 +153,11 @@ module RailsDeleteAllAndAssocsWithoutInstantiation
145
153
  retry_due_to_errors = []
146
154
  retry_to_capture_errors = []
147
155
 
156
+ if options[:verbose]
157
+ puts "DELETION STRUCTURE"
158
+ puts built_deletions.inspect
159
+ end
160
+
148
161
  ActiveRecord::Base.transaction do
149
162
  built_deletions.keys.reverse.each do |class_name|
150
163
  begin
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{rails_delete_all_and_assocs_without_instantiation}
5
- s.version = "0.0.2"
5
+ s.version = "0.0.3"
6
6
  s.date = %q{2023-03-02}
7
7
  s.authors = ["benjamin.dana.software.dev@gmail.com"]
8
8
  s.summary = %q{Non-instantiated way of deleting records with dependencies quickly without instantiation.}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_delete_all_and_assocs_without_instantiation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - benjamin.dana.software.dev@gmail.com