delete_recursively 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/delete_recursively.rb +11 -8
- data/lib/delete_recursively/version.rb +5 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d174e58b83ad4760dc556b4bfe0936bbf18a8a91
|
4
|
+
data.tar.gz: e43d15f393363bc73fc9cacc04f08eba03daf538
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ff1d3b1e231ea7ae1ecb75bdbb4a8e778b9865f3d6ca63cbe0f73a55709d35a6a718d31028a2268db5e19f2c87703b0a2378888ee3824601cd2c871e3cc899f8
|
7
|
+
data.tar.gz: bfed595f4a0dd34b857586145c10330802c879e7b72d84954e544ab8bb1679a51b0fd05b36f64603e50d7ee772a9a031530be72289eeec8c46ff3fd35ebc5e3e
|
data/lib/delete_recursively.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#
|
2
4
|
# DeleteRecursively
|
3
5
|
#
|
@@ -35,8 +37,8 @@ module DeleteRecursively
|
|
35
37
|
record_class = reflection.klass
|
36
38
|
if recurse_on?(reflection)
|
37
39
|
record_class.reflect_on_all_associations.each do |sub_reflection|
|
38
|
-
|
39
|
-
delete_recursively(sub_reflection,
|
40
|
+
sub_ref_ids = dependent_ids(record_class, record_ids, sub_reflection)
|
41
|
+
delete_recursively(sub_reflection, sub_ref_ids)
|
40
42
|
end
|
41
43
|
end
|
42
44
|
destroy_or_delete(reflection, record_class, record_ids)
|
@@ -59,11 +61,11 @@ module DeleteRecursively
|
|
59
61
|
end
|
60
62
|
|
61
63
|
def destructive?(reflection)
|
62
|
-
[
|
64
|
+
%i[destroy destroy_all].include?(reflection.options[:dependent])
|
63
65
|
end
|
64
66
|
|
65
67
|
def deleting?(reflection)
|
66
|
-
[
|
68
|
+
%i[delete delete_all].include?(reflection.options[:dependent])
|
67
69
|
end
|
68
70
|
|
69
71
|
def dependent_ids(owner_class, owner_ids, reflection)
|
@@ -88,14 +90,15 @@ module DeleteRecursively
|
|
88
90
|
foreign_key(dependent_class, dependent_through_reflection)
|
89
91
|
|
90
92
|
through_reflection.klass
|
91
|
-
|
93
|
+
.where(owner_foreign_key => owner_ids)
|
94
|
+
.pluck(dependent_foreign_key)
|
92
95
|
end
|
93
96
|
|
94
97
|
def inverse_through_reflection(reflection)
|
95
98
|
through_class = reflection.through_reflection.klass
|
96
99
|
reflection.klass.reflect_on_all_associations
|
97
|
-
|
98
|
-
|
100
|
+
.map(&:through_reflection)
|
101
|
+
.find { |thr_ref| thr_ref && thr_ref.klass == through_class }
|
99
102
|
end
|
100
103
|
|
101
104
|
def foreign_key(owner_class, reflection)
|
@@ -125,7 +128,7 @@ end
|
|
125
128
|
|
126
129
|
require 'active_record'
|
127
130
|
|
128
|
-
%w
|
131
|
+
%w[BelongsTo HasMany HasOne].each do |assoc_name|
|
129
132
|
assoc_builder = ActiveRecord::Associations::Builder.const_get(assoc_name)
|
130
133
|
assoc_builder.singleton_class.prepend(DeleteRecursively::OptionPermission)
|
131
134
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: delete_recursively
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Janosch Müller
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-07-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -142,6 +142,7 @@ extensions: []
|
|
142
142
|
extra_rdoc_files: []
|
143
143
|
files:
|
144
144
|
- lib/delete_recursively.rb
|
145
|
+
- lib/delete_recursively/version.rb
|
145
146
|
homepage: https://github.com/janosch-x/delete_recursively
|
146
147
|
licenses:
|
147
148
|
- MIT
|