delete_recursively 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bc815c840d3f1514a41c2254278aa84205aa1b29
4
- data.tar.gz: 144a4055f89143dbd6e3744839fa7fe4897c6300
3
+ metadata.gz: d174e58b83ad4760dc556b4bfe0936bbf18a8a91
4
+ data.tar.gz: e43d15f393363bc73fc9cacc04f08eba03daf538
5
5
  SHA512:
6
- metadata.gz: 91b7bc103274442ad9e424e4058b9bd7b66e460f98146ef0110e63bb6764e3f1b43fa0668ee7b017a5a3072840ca880e235f1f48324353ac2aecd7f5be440c7c
7
- data.tar.gz: b07cbf652da91fcc0fe961affb61edef238097456c5fcc63cba249474b977e9631e62d93f9e5bc0e80637b798a01eb894d799f2520880ef7a61f6dd12bd1348d
6
+ metadata.gz: ff1d3b1e231ea7ae1ecb75bdbb4a8e778b9865f3d6ca63cbe0f73a55709d35a6a718d31028a2268db5e19f2c87703b0a2378888ee3824601cd2c871e3cc899f8
7
+ data.tar.gz: bfed595f4a0dd34b857586145c10330802c879e7b72d84954e544ab8bb1679a51b0fd05b36f64603e50d7ee772a9a031530be72289eeec8c46ff3fd35ebc5e3e
@@ -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
- dependent_ids = dependent_ids(record_class, record_ids, sub_reflection)
39
- delete_recursively(sub_reflection, dependent_ids)
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
- [:destroy, :destroy_all].include?(reflection.options[:dependent])
64
+ %i[destroy destroy_all].include?(reflection.options[:dependent])
63
65
  end
64
66
 
65
67
  def deleting?(reflection)
66
- [:delete, :delete_all].include?(reflection.options[:dependent])
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
- .where(owner_foreign_key => owner_ids).pluck(dependent_foreign_key)
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
- .map(&:through_reflection)
98
- .find { |tr| tr && tr.klass == through_class }
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(BelongsTo HasMany HasOne).each do |assoc_name|
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
 
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DeleteRecursively
4
+ VERSION = '1.0.1'
5
+ end
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.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-05-15 00:00:00.000000000 Z
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