restpack_serializer 0.4.17 → 0.4.18
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b5d4602dfd29b489ac3e1a2a1192625f5f599374
|
4
|
+
data.tar.gz: 5d9a645df308d563842d2a0441ae432dc7b77575
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c71574252375b37bf0b2052a0c583d5eed1ce568682fe1a42ac767d253d4e5bdf38b66162d624d992d9b287f02fa157cf33322dd25408eadec50dbd6f84a5115
|
7
|
+
data.tar.gz: 561c9c63d41976b5b77111dc5301b33aa9e017cb9fe3b177ded3dc7ad5024d00acd3f54f3a6fa6f23ec150d460e467bcba40bb39a2481f17fe0683346f6c10d4
|
@@ -29,6 +29,10 @@ module RestPack
|
|
29
29
|
class InvalidInclude < Exception; end
|
30
30
|
|
31
31
|
def as_json(model, context = {})
|
32
|
+
if model.kind_of?(Array)
|
33
|
+
return model.map { |item| as_json(item, context) }
|
34
|
+
end
|
35
|
+
|
32
36
|
@model, @context = model, context
|
33
37
|
|
34
38
|
data = {}
|
@@ -74,6 +78,7 @@ module RestPack
|
|
74
78
|
|
75
79
|
module ClassMethods
|
76
80
|
attr_accessor :model_class, :key
|
81
|
+
|
77
82
|
def as_json(model, context = {})
|
78
83
|
new.as_json(model, context)
|
79
84
|
end
|
@@ -69,6 +69,22 @@ describe RestPack::Serializer do
|
|
69
69
|
}
|
70
70
|
end
|
71
71
|
|
72
|
+
context "serializes an array" do
|
73
|
+
let(:people) { [person, person] }
|
74
|
+
it "results in a serialized array" do
|
75
|
+
serializer.as_json(people).should == [
|
76
|
+
{
|
77
|
+
id: '123', name: 'Gavin', description: 'This is person #123',
|
78
|
+
href: '/people/123', custom_key: 'custom value for model id 123'
|
79
|
+
},
|
80
|
+
{
|
81
|
+
id: '123', name: 'Gavin', description: 'This is person #123',
|
82
|
+
href: '/people/123', custom_key: 'custom value for model id 123'
|
83
|
+
}
|
84
|
+
]
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
72
88
|
context "with options" do
|
73
89
|
it "excludes specified attributes" do
|
74
90
|
serializer.as_json(person, { include_description?: false }).should == {
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: restpack_serializer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.18
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gavin Joyce
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-02-
|
11
|
+
date: 2014-02-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|