restpack_serializer 0.6.8 → 0.6.9
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: 0b5d29308f78d471315415d81716156301b5d464
|
4
|
+
data.tar.gz: ec390f593922863ed5040d26ecd809e0b0b469a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fbb33bb2ddbe116b6c98cad8abbab15e6005d834a34357a82a9953297e72d0a8059029734101236beab8e438368b2601fff856165900054e741ca810948c3e2f
|
7
|
+
data.tar.gz: e8cc28915755375162ff7aa63f7ce3e28a1190264aae77551dc53016aa3e96edad5e7cc10660ba921069d4dc13f83cf2f74c4dfd7dc4e4627150919cce9592df
|
@@ -34,7 +34,7 @@ module RestPack
|
|
34
34
|
def as_json(model, context = {})
|
35
35
|
return if model.nil?
|
36
36
|
if model.kind_of?(Array)
|
37
|
-
return model.map { |item| as_json(item, context) }
|
37
|
+
return model.map { |item| self.class.new.as_json(item, context) }
|
38
38
|
end
|
39
39
|
|
40
40
|
apply_whitelist_and_blacklist(context)
|
@@ -79,6 +79,27 @@ describe RestPack::Serializer do
|
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
82
|
+
context "serializer instance variables" do
|
83
|
+
class MemoizingSerializer
|
84
|
+
include RestPack::Serializer
|
85
|
+
|
86
|
+
attributes :id, :memoized_id
|
87
|
+
|
88
|
+
def memoized_id
|
89
|
+
@memoized_id ||= id
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
it "does not reuse instance variable values" do
|
94
|
+
people = [Person.new(id: 123), Person.new(id: 456)]
|
95
|
+
serialized = MemoizingSerializer.as_json(people)
|
96
|
+
expect(serialized).to eq([
|
97
|
+
{ id: "123", memoized_id: "123" },
|
98
|
+
{ id: "456", memoized_id: "456" }
|
99
|
+
])
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
82
103
|
class PersonSerializer
|
83
104
|
include RestPack::Serializer
|
84
105
|
attributes :id, :name, :description, :href, :admin_info, :string_keys
|
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.6.
|
4
|
+
version: 0.6.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gavin Joyce
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|