fields-serializer 0.2.4 → 0.3.0
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/field_serializer.rb +19 -4
- data/lib/fields/serializer/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cda8e4765ff737edeef8212adfd6a26f6dd7b34a
|
4
|
+
data.tar.gz: f7e82c6a454e90a08769d3fe7cfa4aea2c50bc3a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e61f04ad8ab6300ad6f64b271bcead2c14c70782b8a784459d1d3689dd04d2265b76bfc9941e4b9a00e2e60b309052fb4fbb4e48e0aa97098d22d95832953f61
|
7
|
+
data.tar.gz: 2c23058024f59904d56f3a9cd1fca0e19751cb52eb50999a2231196e69c95eafb302aa30908c9c62deb83dbc9623f964b5b3d8ac53bacabc26f5c6e8be49c5b2
|
@@ -25,17 +25,32 @@ class FieldSerializer < ActiveModel::Serializer
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def create_attribute_structure(attribute_stack, model)
|
28
|
-
return unless model
|
28
|
+
return model unless model.present?
|
29
29
|
parent = attribute_stack.shift
|
30
30
|
if attribute_stack.count > 0
|
31
|
-
|
32
|
-
|
31
|
+
if model.kind_of?(Array)
|
32
|
+
collection_attribute_structure(model, attribute_stack, parent)
|
33
|
+
else
|
34
|
+
attribute_structure(model, attribute_stack, parent)
|
35
|
+
end
|
33
36
|
else
|
34
|
-
|
37
|
+
value_structure(model, parent)
|
35
38
|
end
|
36
39
|
end
|
37
40
|
|
41
|
+
def attribute_structure(model, attribute_stack, parent)
|
42
|
+
{ parent => create_attribute_structure(attribute_stack, model.send(parent)) }
|
43
|
+
end
|
44
|
+
|
45
|
+
def collection_attribute_structure(models, attribute_stack, parent)
|
46
|
+
models.map { |model| attribute_structure(model, attribute_stack, parent) }
|
47
|
+
end
|
48
|
+
|
38
49
|
def merging_attributes(&block)
|
39
50
|
block.call.inject(:deep_merge!)
|
40
51
|
end
|
52
|
+
|
53
|
+
def value_structure(model, attribute_name)
|
54
|
+
{ attribute_name => model.send(attribute_name) }
|
55
|
+
end
|
41
56
|
end
|