adequate_serializer 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fa402c6b2f3c574115120ec0fecd0bf881f3ba8b
4
- data.tar.gz: 4751584ac3ac456908d745fe16ab76c2a8d662e7
3
+ metadata.gz: 1fec099288058f8a38ccdd3fdccfe9ce2c2d67c1
4
+ data.tar.gz: d4177cde980e80c2b7adfe7b8c7a0c5f52b538cb
5
5
  SHA512:
6
- metadata.gz: 4547364833383fb4a1f88e18c4753e7fb9acdf9ebf56e7d9a75936b940f6538e728101a374dc7ca0dca1160a88e6e0bf09209ec81153e4819779591ee0a10536
7
- data.tar.gz: f2651a12bafe90ef26f70feb711497c4e95738ae21c6af9119dd444345ea3db20789a1ac39f2146d0eb8874c7798570bfb7f768b7cc737899a7d7cc0bdc5b7be
6
+ metadata.gz: ef07a512dc0006b231d6d8f512b2c1423ea7d0eb9ff1a948aa3ba25bf5cc276e6dfc91018e47e9ef07f572541b64a36b6eb3db87c5f36118c4cdc92fac8a8c22
7
+ data.tar.gz: 79eca37e71344bccda080dac51425395d612a576c9e5cdc11943c3be836cbcf2684b697a7dca8c8c7239a21c6fb3ec7a4c36b49e8fa4241a79fdcaff87193829
data/README.md CHANGED
@@ -69,6 +69,11 @@ or use no root at all:
69
69
  serialize(@user, root: false)
70
70
  ```
71
71
 
72
+ It works with a ActiveRecord::Relation or an array. However, if you could end
73
+ up serializing an empty array, you should define a root yourself. Otherwise it
74
+ cannot infer the root key and you will end up with a `nil` key. This
75
+ isn't needed for ActiveRecord::Relations.
76
+
72
77
  ### Attributes
73
78
 
74
79
  You can specify which attributes of your objects will be serialized in the
@@ -29,7 +29,17 @@ module AdequateSerializer
29
29
  private
30
30
 
31
31
  def root_name
32
- (root || collection.first.class.name.underscore.parameterize.pluralize).to_sym
32
+ (root || build_root).to_sym
33
+ end
34
+
35
+ def build_root
36
+ if collection.respond_to?(:klass)
37
+ klass = collection.klass
38
+ else
39
+ klass = collection.first.class
40
+ end
41
+
42
+ klass == NilClass ? 'nil' : klass.name.underscore.parameterize.pluralize
33
43
  end
34
44
  end
35
45
  end
@@ -1,3 +1,3 @@
1
1
  module AdequateSerializer
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: adequate_serializer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bastian Bartmann
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-08-13 00:00:00.000000000 Z
11
+ date: 2015-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport