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 +4 -4
- data/README.md +5 -0
- data/lib/adequate_serializer/collection.rb +11 -1
- data/lib/adequate_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: 1fec099288058f8a38ccdd3fdccfe9ce2c2d67c1
|
4
|
+
data.tar.gz: d4177cde980e80c2b7adfe7b8c7a0c5f52b538cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 ||
|
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
|
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.
|
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-
|
11
|
+
date: 2015-08-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|