fields-serializer 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/fields/serializer/active_record.rb +9 -3
- data/lib/fields/serializer/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0c69ba742be7a601aa3b70928bd749a19e84f6c3
|
4
|
+
data.tar.gz: 128cfbcae08a53cc86fd70048de78a55cc92a716
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2957720a227130ffde6970297fcd80d70f19a04f8560886b4c3a50414ae5eccb6d183eddedb7e408e0673804e191f03f1e52947def00fb6e4704ae188253c7ac
|
7
|
+
data.tar.gz: 2af0d594995d6ef16cacf4b2d23e3141a29ea37d8528288e8fca9682900c96b2494200718182db91c8565056227ffe2ac389081a0827cc987c244bda16c28fc2
|
@@ -14,9 +14,7 @@ module Fields
|
|
14
14
|
# BoilerPack.fields_to_includes("id,boiler.gas_safe_code") #=> ["boiler"]
|
15
15
|
#
|
16
16
|
def fields_to_includes(fields)
|
17
|
-
|
18
|
-
nested_fields = flatten_fields.map { |field| nested_field(field.split(".")) }.compact
|
19
|
-
nested_fields.inject([{}]) do |result, attribute_structure|
|
17
|
+
nested_fields(fields).inject([{}]) do |result, attribute_structure|
|
20
18
|
if attribute_structure.is_a?(Hash)
|
21
19
|
result.first.deep_merge!(attribute_structure) { |_, u, v| u == v ? u : [u, v] }
|
22
20
|
else
|
@@ -35,9 +33,17 @@ module Fields
|
|
35
33
|
|
36
34
|
private
|
37
35
|
|
36
|
+
def array_fields(fields)
|
37
|
+
Array(fields).map { |str| str.to_s.split(",").map(&:strip) }.flatten
|
38
|
+
end
|
39
|
+
|
38
40
|
def association?(key)
|
39
41
|
reflections.keys.include?(key)
|
40
42
|
end
|
43
|
+
|
44
|
+
def nested_fields(fields)
|
45
|
+
array_fields(fields).map { |field| nested_field(field.split(".")) }.compact.uniq
|
46
|
+
end
|
41
47
|
end
|
42
48
|
end
|
43
49
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fields-serializer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stuart Chinery
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date: 2017-12-
|
13
|
+
date: 2017-12-16 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|