seed_reaper 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/seed_reaper/config_evaluator.rb +26 -0
- data/lib/seed_reaper/seedifier.rb +11 -2
- data/lib/seed_reaper/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1fad4ebc284e6a5e6a30df7e9a3305c70d48060d4d12a4a48f69391149fc975a
|
4
|
+
data.tar.gz: a66337b1c8749eb67a42b1fb1bb9d601e8f1cc21cf2002cb22044e534007b81f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9f5756b19dd5aaac7567cfbe78669e96e0c936d9cad7f50f1ecddbc9272581018b4bf1ef27d88bbee83b713c40d5278f36e777956cf473f1b533f480cc49d884
|
7
|
+
data.tar.gz: f78cedba61282dfe2f36c25b80c637630a39a2051bf35471df3922d9efed6d9d31d4058919ceec443f6b5b66d36ef177c76e9ecf8156593649bf7a1082942bfb
|
@@ -14,6 +14,32 @@ module SeedReaper
|
|
14
14
|
@config
|
15
15
|
end
|
16
16
|
|
17
|
+
def belongs_to_schema(instance)
|
18
|
+
return nil unless schema
|
19
|
+
return schema.select { |k| instance._reflections[k.to_s].belongs_to? } if schema.is_a?(Hash)
|
20
|
+
return schema.select do |c|
|
21
|
+
if c.is_a?(Hash)
|
22
|
+
instance._reflections[c.first[0].to_s].belongs_to?
|
23
|
+
else
|
24
|
+
instance._reflections[c.to_s].belongs_to?
|
25
|
+
end
|
26
|
+
end if schema.is_a?(Array)
|
27
|
+
return schema if instance._reflections[schema.to_s].belongs_to?
|
28
|
+
end
|
29
|
+
|
30
|
+
def non_belongs_to_schema(instance)
|
31
|
+
return nil unless schema
|
32
|
+
return schema.reject { |k| instance._reflections[k.to_s].belongs_to? } if schema.is_a?(Hash)
|
33
|
+
return schema.reject do |c|
|
34
|
+
if c.is_a?(Hash)
|
35
|
+
instance._reflections[c.first[0].to_s].belongs_to?
|
36
|
+
else
|
37
|
+
instance._reflections[c.to_s].belongs_to?
|
38
|
+
end
|
39
|
+
end if schema.is_a?(Array)
|
40
|
+
return schema unless instance._reflections[schema.to_s].belongs_to?
|
41
|
+
end
|
42
|
+
|
17
43
|
%i[count joins].each do |meta_field|
|
18
44
|
define_method meta_field do
|
19
45
|
meta(meta_field)
|
@@ -8,6 +8,7 @@ module SeedReaper
|
|
8
8
|
class Seedifier
|
9
9
|
def initialize(config)
|
10
10
|
@config = config
|
11
|
+
@serialized = []
|
11
12
|
end
|
12
13
|
|
13
14
|
def seedify
|
@@ -31,7 +32,10 @@ module SeedReaper
|
|
31
32
|
def seedify_collection(collection, config)
|
32
33
|
ce = ConfigEvaluator.new(config)
|
33
34
|
evaluated_collection(collection, ce).reduce('') do |str, instance|
|
34
|
-
str +=
|
35
|
+
str +=
|
36
|
+
seedify_associations(instance, ce.belongs_to_schema(instance)) +
|
37
|
+
serialize(instance) +
|
38
|
+
seedify_associations(instance, ce.non_belongs_to_schema(instance))
|
35
39
|
end
|
36
40
|
end
|
37
41
|
|
@@ -84,7 +88,12 @@ module SeedReaper
|
|
84
88
|
end
|
85
89
|
|
86
90
|
def serialize(instance)
|
87
|
-
"#{instance.class}.new(\n#{serialize_attrs(instance)}\n).save!(validate: false)\n\n"
|
91
|
+
seed = "#{instance.class}.new(\n#{serialize_attrs(instance)}\n).save!(validate: false)\n\n"
|
92
|
+
hashed_seed = Digest::SHA2.hexdigest(seed)
|
93
|
+
return '' if @serialized.include?(hashed_seed)
|
94
|
+
|
95
|
+
@serialized << hashed_seed
|
96
|
+
seed
|
88
97
|
end
|
89
98
|
|
90
99
|
def serialize_attrs(instance)
|
data/lib/seed_reaper/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: seed_reaper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Butts
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-02-
|
11
|
+
date: 2022-02-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|