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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b52fd79f8a8bd124a72946938fa34252598ad9d7
4
- data.tar.gz: 89440400a40a8200d66f12e58ffefa0ba598514b
3
+ metadata.gz: cda8e4765ff737edeef8212adfd6a26f6dd7b34a
4
+ data.tar.gz: f7e82c6a454e90a08769d3fe7cfa4aea2c50bc3a
5
5
  SHA512:
6
- metadata.gz: 58ae8f9acd7b8697c680c12a705691c813c2b1efe389f320fd715a802133b4781f4835578ea044d75047ee613b2b1f6c4cf59cdd39598274d87109d1ced2291b
7
- data.tar.gz: '08c15eacdbde795f63929b9dbc87e9368286fd99d192af066bd03421a59f9a0212c845ef4ed427ba689e85551b13dc8fc1ebd9440fb42e781d1d731f3ed47e30'
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
- nested_model = model.send(parent)
32
- { parent => create_attribute_structure(attribute_stack, nested_model) }
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
- { parent => model.send(parent) }
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
@@ -1,5 +1,5 @@
1
1
  module Fields
2
2
  module Serializer
3
- VERSION = "0.2.4"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  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.2.4
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stuart Chinery