dependent-auto-rails 0.1.2 → 0.1.4
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d8a5de40e738a480461d249edc98b76df49778d58e77fee8a3a54f90ffa017ad
|
4
|
+
data.tar.gz: 8bbb14703a6e1a20da97cde693f05000f77202eae0e05ecbfe37d0fd7ce8d749
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 828ba4145c234101a34c753c6d247739f4ee97734a8ab1a5c065d443e5b60cdcb97713c7180d0fc317ba536760827363ec14cb8676e4b59bd628b0f38e00f4ad
|
7
|
+
data.tar.gz: 1efacf7ea4308f2afe9e7d998ed0fc8fa9e8e23bf06bd0d8ee484c10a7e4bc5ea3cc50a61588577ab8163854b123ae884204255362287e93b832f3396ce1d806
|
@@ -2,27 +2,67 @@
|
|
2
2
|
|
3
3
|
module ActiveRecord::Associations::Builder
|
4
4
|
class Association
|
5
|
-
def self.
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
def self.create_reflection(model, name, scope, options, &block)
|
6
|
+
raise ArgumentError, "association names must be a Symbol" unless name.is_a?(Symbol)
|
7
|
+
|
8
|
+
validate_options(options)
|
9
|
+
|
10
|
+
extension = define_extensions(model, name, &block)
|
11
|
+
options[:extend] = [*options[:extend], extension] if extension
|
12
|
+
|
13
|
+
scope = build_scope(scope)
|
14
|
+
|
15
|
+
ActiveRecord::Reflection.create(macro, name, scope, dynamic_reflection_options(model, options), model)
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.dynamic_reflection_options(model, options)
|
19
|
+
DynamicReflectionOptionsHash.new.merge!(
|
20
|
+
options,
|
21
|
+
{
|
22
|
+
model_name: model.name,
|
23
|
+
association_type: if self < ActiveRecord::Associations::Builder::SingularAssociation
|
24
|
+
:singular
|
25
|
+
elsif self < ActiveRecord::Associations::Builder::CollectionAssociation
|
26
|
+
:collection
|
27
|
+
else
|
28
|
+
raise DependentAutoRails::Error, "Unsupported association type"
|
29
|
+
end
|
30
|
+
}
|
31
|
+
)
|
32
|
+
end
|
33
|
+
private_class_method :dynamic_reflection_options
|
34
|
+
|
35
|
+
class DynamicReflectionOptionsHash < Hash
|
36
|
+
def [](key)
|
37
|
+
return super unless key == :dependent && super(:dependent) == :auto
|
38
|
+
return fallback_method if defining_dependent_callbacks?
|
11
39
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
40
|
+
model = super(:model_name).constantize
|
41
|
+
return :destroy unless valid_destroy_callbacks(model).empty?
|
42
|
+
|
43
|
+
case super(:association_type)
|
44
|
+
when :singular then :delete
|
45
|
+
when :collection then :delete_all
|
46
|
+
else fallback_method
|
17
47
|
end
|
18
48
|
end
|
19
49
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
50
|
+
private
|
51
|
+
|
52
|
+
def fallback_method
|
53
|
+
:destroy
|
54
|
+
end
|
55
|
+
|
56
|
+
def defining_dependent_callbacks?
|
57
|
+
caller.any? { |line| line.include?("active_record/associations/builder/association.rb") }
|
58
|
+
end
|
59
|
+
|
60
|
+
def valid_destroy_callbacks(model)
|
61
|
+
model._destroy_callbacks.reject do |callback|
|
62
|
+
# ignore #handle_dependency callback
|
63
|
+
callback.filter.to_s.include?("active_record/associations/builder/association.rb")
|
64
|
+
end
|
65
|
+
end
|
26
66
|
end
|
27
67
|
end
|
28
68
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dependent-auto-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joshua Young
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sqlite3
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
description:
|
28
42
|
email:
|
29
43
|
- djry1999@gmail.com
|
@@ -64,6 +78,6 @@ requirements: []
|
|
64
78
|
rubygems_version: 3.5.3
|
65
79
|
signing_key:
|
66
80
|
specification_version: 4
|
67
|
-
summary: Automatically and safely decides between :destroy and :delete
|
68
|
-
associations.
|
81
|
+
summary: Automatically and safely decides between :destroy and :delete / :delete_all
|
82
|
+
for your Rails associations.
|
69
83
|
test_files: []
|