bulk_dependency_eraser 1.4.0 → 1.4.2

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: 9c8e832cdb51105145cc3a1ba8487d32dab71b32d5a9f25808c84026d3f82b25
4
- data.tar.gz: 556c96e6eb0a2b98aca3afbaf03ce8aad41012b793a7a45bccd4f2f459e1aaa5
3
+ metadata.gz: 734c542b83d1cf827cadf8a8a41c30d8a86ebe7f98e539e0bdce4777f917c2e9
4
+ data.tar.gz: fedb350237abe9898c2d54077db57c1c500b76c99c6913431c2445f5fd49293a
5
5
  SHA512:
6
- metadata.gz: 8b23c1429318d5c56850d7fa615956f083929751b58a72a2e584d2470feff430b4c374691cd2e436beb5890619c7d1c533d64a1fa9cd1b6aa3df7776f6c73387
7
- data.tar.gz: 06e3bebaf98dd80af62ca714a3c8edd92548873ac84b88569d344cad64709444464197c1e2ec7febc7c74a5c981e234677b5accfb29e4936ca1a1ec06acb44d1
6
+ metadata.gz: 5b69927dd186b6eac307ff85a5bd06783245c5173a6d890ff29a8abb42edbf8df105a3ed592cf3ae92f649c4547f32c289316b83ae7f02d19233a05d9a2a5d47
7
+ data.tar.gz: 9a4febdbdd779faf17bc332b8853c41bb727e722fea564ed45a8b871ee53f8e4677983c2459a4894a4304c90397a48fa927d41609e4558033ee24c43badbc4b7
@@ -1,12 +1,22 @@
1
1
  module BulkDependencyEraser
2
2
  class Base
3
+ # Default Custom Scope for all classes, no effect.
4
+ DEFAULT_SCOPE_WRAPPER = ->(query) { nil }
5
+ # Default Custom Scope for mapped-by-name classes, no effect.
6
+ DEFAULT_KLASS_MAPPED_SCOPE_WRAPPER = ->(query) { query }
7
+
3
8
  DEFAULT_OPTS = {
4
9
  # Applied to all queries. Useful for taking advantage of specific indexes
10
+ # - not indexed by klass name. Proc would handle the logic for that.
11
+ # - 3rd, and lowest, priority of scopes
12
+ # - accepts rails query as parameter
13
+ # - return nil if no applicable scope.
14
+ proc_scopes: self::DEFAULT_SCOPE_WRAPPER,
15
+ # Applied to all queries. Useful for taking advantage of specific indexes
16
+ # - 2nd highest priority of scopes
5
17
  proc_scopes_per_class_name: {},
6
18
  }.freeze
7
19
 
8
- # Default Custom Scope for all classes, no effect.
9
- DEFAULT_SCOPE_WRAPPER = ->(query) { query }
10
20
 
11
21
  # Default Database wrapper, no effect.
12
22
  DEFAULT_DB_WRAPPER = ->(block) { block.call }
@@ -27,12 +37,19 @@ module BulkDependencyEraser
27
37
 
28
38
  protected
29
39
 
30
- def custom_scope_for_klass_name(klass_name)
31
- if opts_c.proc_scopes_per_class_name.key?(klass_name)
32
- opts_c.proc_scopes_per_class_name[klass_name]
40
+ def custom_scope_for_query(query)
41
+ klass = query.klass
42
+ if opts_c.proc_scopes_per_class_name.key?(klass.name)
43
+ opts_c.proc_scopes_per_class_name[klass.name].call(query)
33
44
  else
34
- # No custom wrapper, return non-effect default
35
- DEFAULT_SCOPE_WRAPPER
45
+ # See if non-class-mapped proc returns a value
46
+ non_class_name_mapped_query = opts_c.proc_scopes.call(query)
47
+ if !non_class_name_mapped_query.nil?
48
+ return non_class_name_mapped_query
49
+ else
50
+ # No custom wrapper, return non-effect default
51
+ return self.class::DEFAULT_KLASS_MAPPED_SCOPE_WRAPPER.call(query)
52
+ end
36
53
  end
37
54
  end
38
55
 
@@ -21,8 +21,16 @@ module BulkDependencyEraser
21
21
  # A specific read batching disable option
22
22
  disable_read_batching: nil,
23
23
  # Applied to all queries. Useful for taking advantage of specific indexes
24
+ # - not indexed by klass name. Proc would handle the logic for that.
25
+ # - 3rd, and lowest, priority of scopes
26
+ # - accepts rails query as parameter
27
+ # - return nil if no applicable scope.
28
+ proc_scopes: self::DEFAULT_SCOPE_WRAPPER,
29
+ # Applied to all queries. Useful for taking advantage of specific indexes
30
+ # - 2nd highest priority of scopes
24
31
  proc_scopes_per_class_name: {},
25
- # Applied to deletion queries
32
+ # Applied to reading queries
33
+ # - 1st priority of scopes
26
34
  reading_proc_scopes_per_class_name: {},
27
35
  }.freeze
28
36
 
@@ -155,11 +163,12 @@ module BulkDependencyEraser
155
163
  attr_reader :table_names_to_parsed_klass_names
156
164
  attr_reader :ignore_table_name_and_dependencies, :ignore_klass_name_and_dependencies
157
165
 
158
- def custom_scope_for_klass_name(klass_name)
159
- if opts_c.reading_proc_scopes_per_class_name.key?(klass_name)
160
- opts_c.reading_proc_scopes_per_class_name[klass_name]
166
+ def custom_scope_for_query(query)
167
+ klass = query.klass
168
+ if opts_c.reading_proc_scopes_per_class_name.key?(klass.name)
169
+ opts_c.reading_proc_scopes_per_class_name[klass.name].call(query)
161
170
  else
162
- super(klass_name)
171
+ super(query)
163
172
  end
164
173
  end
165
174
 
@@ -167,7 +176,7 @@ module BulkDependencyEraser
167
176
  # ordering shouldn't matter in these queries, and would slow it down
168
177
  # - we're ignoring default_scope ordering, but assoc-defined ordering would still take effect
169
178
  query = query.reorder('')
170
- query = custom_scope_for_klass_name(query.klass.name).call(query)
179
+ query = custom_scope_for_query(query)
171
180
 
172
181
  query_ids = []
173
182
  read_from_db do
@@ -631,7 +640,7 @@ module BulkDependencyEraser
631
640
  return
632
641
  end
633
642
 
634
- query = custom_scope_for_klass_name(query.klass.name).call(query)
643
+ query = custom_scope_for_query(query)
635
644
 
636
645
  foreign_ids_by_type = read_from_db do
637
646
  if batching_disabled? || !query.where({}).limit_value.nil?
@@ -13,8 +13,16 @@ module BulkDependencyEraser
13
13
  # A specific batching size for this class, overrides the batch_size
14
14
  disable_delete_batching: nil,
15
15
  # Applied to all queries. Useful for taking advantage of specific indexes
16
+ # - not indexed by klass name. Proc would handle the logic for that.
17
+ # - 3rd, and lowest, priority of scopes
18
+ # - accepts rails query as parameter
19
+ # - return nil if no applicable scope.
20
+ proc_scopes: self::DEFAULT_SCOPE_WRAPPER,
21
+ # Applied to all queries. Useful for taking advantage of specific indexes
22
+ # - 2nd highest priority of scopes
16
23
  proc_scopes_per_class_name: {},
17
24
  # Applied to deletion queries
25
+ # - 1st priority of scopes
18
26
  deletion_proc_scopes_per_class_name: {},
19
27
  }.freeze
20
28
 
@@ -69,11 +77,12 @@ module BulkDependencyEraser
69
77
 
70
78
  attr_reader :class_names_and_ids
71
79
 
72
- def custom_scope_for_klass_name(klass_name)
73
- if opts_c.deletion_proc_scopes_per_class_name.key?(klass_name)
74
- opts_c.deletion_proc_scopes_per_class_name[klass_name]
80
+ def custom_scope_for_query(query)
81
+ klass = query.klass
82
+ if opts_c.deletion_proc_scopes_per_class_name.key?(klass.name)
83
+ opts_c.deletion_proc_scopes_per_class_name[klass.name].call(query)
75
84
  else
76
- super(klass_name)
85
+ super(query)
77
86
  end
78
87
  end
79
88
 
@@ -88,7 +97,7 @@ module BulkDependencyEraser
88
97
  def delete_by_klass_and_ids klass, ids
89
98
  puts "Deleting #{klass.name}'s IDs: #{ids}" if opts_c.verbose
90
99
  query = klass.unscoped
91
- query = custom_scope_for_klass_name(klass.name).call(query)
100
+ query = custom_scope_for_query(query)
92
101
 
93
102
  if batching_disabled?
94
103
  puts "Deleting without batching" if opts_c.verbose
@@ -15,8 +15,16 @@ module BulkDependencyEraser
15
15
  # A specific batching size for this class, overrides the batch_size
16
16
  disable_nullify_batching: nil,
17
17
  # Applied to all queries. Useful for taking advantage of specific indexes
18
+ # - not indexed by klass name. Proc would handle the logic for that.
19
+ # - 3rd, and lowest, priority of scopes
20
+ # - accepts rails query as parameter
21
+ # - return nil if no applicable scope.
22
+ proc_scopes: self::DEFAULT_SCOPE_WRAPPER,
23
+ # Applied to all queries. Useful for taking advantage of specific indexes
24
+ # - 2nd highest priority of scopes
18
25
  proc_scopes_per_class_name: {},
19
- # Applied to deletion queries
26
+ # Applied to nullification queries
27
+ # - 1st priority of scopes
20
28
  nullification_proc_scopes_per_class_name: {},
21
29
  }.freeze
22
30
 
@@ -127,11 +135,12 @@ module BulkDependencyEraser
127
135
 
128
136
  attr_reader :class_names_columns_and_ids
129
137
 
130
- def custom_scope_for_klass_name(klass_name)
131
- if opts_c.nullification_proc_scopes_per_class_name.key?(klass_name)
132
- opts_c.nullification_proc_scopes_per_class_name[klass_name]
138
+ def custom_scope_for_query(query)
139
+ klass = query.klass
140
+ if opts_c.nullification_proc_scopes_per_class_name.key?(klass.name)
141
+ opts_c.nullification_proc_scopes_per_class_name[klass.name].call(query)
133
142
  else
134
- super(klass_name)
143
+ super(query)
135
144
  end
136
145
  end
137
146
 
@@ -145,7 +154,7 @@ module BulkDependencyEraser
145
154
 
146
155
  def nullify_by_klass_column_and_ids klass, columns, ids
147
156
  query = klass.unscoped
148
- query = custom_scope_for_klass_name(klass.name).call(query)
157
+ query = custom_scope_for_query(query)
149
158
 
150
159
  nullify_columns = {}
151
160
  # supporting nullification of groups of columns simultaneously
@@ -1,3 +1,3 @@
1
1
  module BulkDependencyEraser
2
- VERSION = "1.4.0".freeze
2
+ VERSION = "1.4.2".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bulk_dependency_eraser
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - benjamin.dana.software.dev@gmail.com