deep_cloneable_checked 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/.gitignore +2 -0
- data/Gemfile.lock +2 -2
- data/deep_cloneable_checked.gemspec +2 -2
- data/lib/deep_cloneable_checked/deep_clone_checked.rb +7 -45
- data/lib/deep_cloneable_checked/utilities.rb +24 -0
- data/lib/deep_cloneable_checked/version.rb +1 -1
- data/lib/deep_cloneable_checked.rb +5 -2
- metadata +9 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae5f15517f7b64bd368d8300ea9837609f3d6b1f8f38dde1f3981d5cc421f69c
|
4
|
+
data.tar.gz: ceb59ba3f33a98bd04a452dab32395ee56cd37796b061efb93322541ebc3210e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1952904ebd2460c0f7277123f73db60a40451641a011989257af0f3e053a2e4a07a6459b87792c19e6c1c363082e3519d58f8a3fba92a2e89319e8b37198adf4
|
7
|
+
data.tar.gz: 4e74c7ff8b65d57445ad752581878035845ab52e377585d688485aa5e103950c0d77a7e45ffbe2b0f8188842874691805b71a6b767eaf76b0d7047748a45d798
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
deep_cloneable_checked (
|
4
|
+
deep_cloneable_checked (1.0.0)
|
5
5
|
deep_cloneable (~> 3.2.0)
|
6
6
|
|
7
7
|
GEM
|
@@ -23,7 +23,7 @@ GEM
|
|
23
23
|
diff-lcs (1.5.0)
|
24
24
|
i18n (1.12.0)
|
25
25
|
concurrent-ruby (~> 1.0)
|
26
|
-
minitest (5.16.
|
26
|
+
minitest (5.16.3)
|
27
27
|
rake (12.3.3)
|
28
28
|
rspec (3.11.0)
|
29
29
|
rspec-core (~> 3.11.0)
|
@@ -6,8 +6,8 @@ Gem::Specification.new do |spec|
|
|
6
6
|
spec.authors = ["Kaori Kohama", "Tinco Andringa"]
|
7
7
|
spec.email = ["kaori@aeroscan.nl", "tinco@aeroscan.nl"]
|
8
8
|
|
9
|
-
spec.summary = %q{Use this gem to enforce all associations
|
10
|
-
spec.description = %q{Use this gem to enforce all associations
|
9
|
+
spec.summary = %q{Use this gem to enforce all associations explicitly cloned with deep_clone}
|
10
|
+
spec.description = %q{Use this gem to enforce all associations explicitly cloned with deep_clone}
|
11
11
|
spec.homepage = "https://github.com/aeroscan-nl/deep_cloneable_checked"
|
12
12
|
spec.license = "MIT"
|
13
13
|
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
@@ -1,14 +1,6 @@
|
|
1
1
|
module DeepCloneableChecked
|
2
2
|
module DeepCloneChecked
|
3
3
|
def deep_clone_checked(options)
|
4
|
-
if options[:include].is_a?(Hash) || options[:include].is_a?(Symbol)
|
5
|
-
options[:include] = [options[:include]]
|
6
|
-
end
|
7
|
-
|
8
|
-
if options[:exclude].is_a?(Hash) || options[:exclude].is_a?(Symbol)
|
9
|
-
options[:exclude] = [options[:exclude]]
|
10
|
-
end
|
11
|
-
|
12
4
|
missing = validate_clone_check(options)
|
13
5
|
|
14
6
|
unless missing.empty?
|
@@ -19,56 +11,26 @@ module DeepCloneableChecked
|
|
19
11
|
end
|
20
12
|
|
21
13
|
def validate_clone_check(options)
|
22
|
-
find_symbol_or_hash = lambda do |options, association_name|
|
23
|
-
|
24
|
-
result = options.find do |option|
|
25
|
-
if option.is_a? Symbol
|
26
|
-
option.to_s == association_name
|
27
|
-
elsif option.is_a? Hash
|
28
|
-
option[association_name.to_sym]
|
29
|
-
else
|
30
|
-
nil
|
31
|
-
end
|
32
|
-
end
|
33
|
-
result
|
34
|
-
end
|
35
|
-
|
36
14
|
check_missing = lambda do |klass, includes, excludes|
|
15
|
+
includes = DeepCloneableChecked.options_to_hash(includes)
|
16
|
+
excludes = DeepCloneableChecked.options_to_hash(excludes)
|
37
17
|
# puts "-----------\n klass: #{klass.name}, includes: #{includes.inspect}, excludes: #{excludes.inspect}"
|
38
18
|
associations = klass.reflections
|
39
19
|
|
40
20
|
associations.map do |association_name, reflection|
|
21
|
+
next_excludes = excludes[association_name.to_sym]
|
22
|
+
next_includes = includes[association_name.to_sym]
|
41
23
|
|
42
|
-
|
43
|
-
if to_exclude.is_a? Symbol
|
44
|
-
next_excludes = []
|
45
|
-
elsif to_exclude.is_a? Array
|
46
|
-
next_excludes = to_exclude
|
47
|
-
elsif to_exclude.nil?
|
48
|
-
next_excludes = []
|
49
|
-
else
|
50
|
-
next_excludes = to_exclude[association_name.to_sym]
|
51
|
-
end
|
52
|
-
|
53
|
-
inclusion = find_symbol_or_hash[includes, association_name]
|
54
|
-
|
55
|
-
if inclusion.is_a? Symbol
|
56
|
-
# puts "inclusion: #{inclusion.inspect}, association_name: #{association_name}"
|
57
|
-
result = check_missing[reflection.klass, [], next_excludes]
|
58
|
-
if !result.blank?
|
59
|
-
# puts "missing from #{reflection.klass.name}, #{association_name}"
|
60
|
-
Hash[association_name.to_sym, result]
|
61
|
-
end
|
62
|
-
elsif inclusion.is_a? Hash
|
24
|
+
if next_includes
|
63
25
|
# puts "inclusion: #{inclusion.inspect}, association_name: #{association_name}"
|
64
|
-
result = check_missing[reflection.klass,
|
26
|
+
result = check_missing[reflection.klass, next_includes, next_excludes]
|
65
27
|
if !result.blank?
|
66
28
|
# puts "missing from #{reflection.klass.name}, #{association_name}"
|
67
29
|
Hash[association_name.to_sym, result]
|
68
30
|
end
|
69
31
|
else
|
70
32
|
# puts "No inclusion for #{association_name}, inclusion: #{inclusion.inspect}, to_exclude: #{to_exclude.inspect}"
|
71
|
-
if
|
33
|
+
if next_excludes
|
72
34
|
nil
|
73
35
|
else
|
74
36
|
# puts "No exclusion either"
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module DeepCloneableChecked
|
2
|
+
def self.options_to_hash(options)
|
3
|
+
case options
|
4
|
+
when Hash
|
5
|
+
options
|
6
|
+
when Array
|
7
|
+
options_array_to_hash(options)
|
8
|
+
else
|
9
|
+
options_array_to_hash([options])
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.options_array_to_hash(options)
|
14
|
+
hash = {}
|
15
|
+
options.each do |o|
|
16
|
+
if o.is_a? Hash
|
17
|
+
hash.deep_merge! o
|
18
|
+
else
|
19
|
+
hash[o] = []
|
20
|
+
end
|
21
|
+
end
|
22
|
+
hash
|
23
|
+
end
|
24
|
+
end
|
@@ -1,11 +1,14 @@
|
|
1
1
|
require "deep_cloneable_checked/version"
|
2
2
|
require 'deep_cloneable'
|
3
|
+
require 'deep_cloneable_checked/utilities'
|
3
4
|
require 'deep_cloneable_checked/deep_clone_checked'
|
4
5
|
|
5
6
|
module DeepCloneableChecked
|
6
7
|
class MissingAssociationError < StandardError; end
|
7
8
|
end
|
8
9
|
|
9
|
-
ActiveSupport
|
10
|
-
|
10
|
+
if defined?(ActiveSupport)
|
11
|
+
ActiveSupport.on_load :active_record do
|
12
|
+
include DeepCloneableChecked::DeepCloneChecked
|
13
|
+
end
|
11
14
|
end
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deep_cloneable_checked
|
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
|
- Kaori Kohama
|
8
8
|
- Tinco Andringa
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2022-
|
12
|
+
date: 2022-09-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: deep_cloneable
|
@@ -25,8 +25,7 @@ dependencies:
|
|
25
25
|
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: 3.2.0
|
28
|
-
description: Use this gem to enforce all associations
|
29
|
-
with deep_clone
|
28
|
+
description: Use this gem to enforce all associations explicitly cloned with deep_clone
|
30
29
|
email:
|
31
30
|
- kaori@aeroscan.nl
|
32
31
|
- tinco@aeroscan.nl
|
@@ -49,6 +48,7 @@ files:
|
|
49
48
|
- deep_cloneable_checked.gemspec
|
50
49
|
- lib/deep_cloneable_checked.rb
|
51
50
|
- lib/deep_cloneable_checked/deep_clone_checked.rb
|
51
|
+
- lib/deep_cloneable_checked/utilities.rb
|
52
52
|
- lib/deep_cloneable_checked/version.rb
|
53
53
|
homepage: https://github.com/aeroscan-nl/deep_cloneable_checked
|
54
54
|
licenses:
|
@@ -57,7 +57,7 @@ metadata:
|
|
57
57
|
homepage_uri: https://github.com/aeroscan-nl/deep_cloneable_checked
|
58
58
|
source_code_uri: https://github.com/aeroscan-nl/deep_cloneable_checked
|
59
59
|
changelog_uri: https://github.com/aeroscan-nl/deep_cloneable_checked/blob/main/CHANGELOG.md
|
60
|
-
post_install_message:
|
60
|
+
post_install_message:
|
61
61
|
rdoc_options: []
|
62
62
|
require_paths:
|
63
63
|
- lib
|
@@ -72,9 +72,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
72
72
|
- !ruby/object:Gem::Version
|
73
73
|
version: '0'
|
74
74
|
requirements: []
|
75
|
-
rubygems_version: 3.1.
|
76
|
-
signing_key:
|
75
|
+
rubygems_version: 3.1.2
|
76
|
+
signing_key:
|
77
77
|
specification_version: 4
|
78
|
-
summary: Use this gem to enforce all associations
|
79
|
-
with deep_clone
|
78
|
+
summary: Use this gem to enforce all associations explicitly cloned with deep_clone
|
80
79
|
test_files: []
|