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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8e400a352bb3a82691a3a0e11f694611b7c0dd8e
4
- data.tar.gz: 96a8af0bc2f59735656c6546525556c68cf74153
3
+ metadata.gz: 0c69ba742be7a601aa3b70928bd749a19e84f6c3
4
+ data.tar.gz: 128cfbcae08a53cc86fd70048de78a55cc92a716
5
5
  SHA512:
6
- metadata.gz: cf045e0197b430a1c5795286801ae966b9fc5199189780d36bf3a03b555c91ae0a9268b1629db2db3a678e8a0c9651aa51bc44b582977bcaeaf1b80a265017ad
7
- data.tar.gz: 0c0915f5f3e81d2516252b9ee29e351e0b0d18f9afaad8c88d698604c7ee112d95120c4293b0659ae0a2b0055841cbfe1e572387d2d391702a41ba2d0192ac6c
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
- flatten_fields = Array(fields).map { |str| str.to_s.split(",").map(&:strip) }.flatten
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
@@ -1,5 +1,5 @@
1
1
  module Fields
2
2
  module Serializer
3
- VERSION = "0.3.1"
3
+ VERSION = "0.3.2"
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.3.1
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-15 00:00:00.000000000 Z
13
+ date: 2017-12-16 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler