restpack_serializer 0.4.4 → 0.4.5
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: 8bb868ddc338559c261cf11b8b18c971b2d80bd7
|
4
|
+
data.tar.gz: d667ad9327dd544adbb23eff8b2c15028e917e28
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ed2707234b857b4b5ea571fce09fe7247f2b8adf966f52045cc2540fbf1a2feb195a7bcff310fcd0b8d046bed11d9df70e786e1c0c073d76b6e7c61d68e248e
|
7
|
+
data.tar.gz: d663714aa5135e88a14f4418f474b367217a3b933b5da2152d864f01804ad6578814f8217fb848822837de5728cbea487f3abd297a8c863170c154e349c2bc37
|
@@ -74,6 +74,14 @@ module RestPack
|
|
74
74
|
new.as_json(model, context)
|
75
75
|
end
|
76
76
|
|
77
|
+
def serialize(models, context = {})
|
78
|
+
models = [models] unless models.kind_of?(Array)
|
79
|
+
|
80
|
+
{
|
81
|
+
self.key() => models.map {|model| self.as_json(model, context)}
|
82
|
+
}
|
83
|
+
end
|
84
|
+
|
77
85
|
def model_class
|
78
86
|
@model_class || self.name.chomp('Serializer').constantize
|
79
87
|
end
|
@@ -22,7 +22,7 @@ describe RestPack::Serializer do
|
|
22
22
|
include RestPack::Serializer
|
23
23
|
end
|
24
24
|
|
25
|
-
it "serializes to an empty hash" do
|
25
|
+
it ".as_json serializes to an empty hash" do
|
26
26
|
EmptySerializer.as_json(person).should == { }
|
27
27
|
end
|
28
28
|
end
|
@@ -50,6 +50,17 @@ describe RestPack::Serializer do
|
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
|
+
describe ".serialize" do
|
54
|
+
it "serializes to an array" do
|
55
|
+
serializer.class.serialize(person).should == {
|
56
|
+
people: [{
|
57
|
+
id: '123', name: 'Gavin', description: 'This is person #123',
|
58
|
+
href: '/people/123.json', custom_key: 'custom value for model id 123'
|
59
|
+
}]
|
60
|
+
}
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
53
64
|
describe ".as_json" do
|
54
65
|
it "serializes specified attributes" do
|
55
66
|
serializer.as_json(person).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.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gavin Joyce
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-09-
|
11
|
+
date: 2013-09-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|