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: 7af1bc27d7c8835c4661909c30fc9dd85db99379
4
- data.tar.gz: cdd08668865b3200810f2f296a6729b5aa29a1e1
3
+ metadata.gz: 0b5d29308f78d471315415d81716156301b5d464
4
+ data.tar.gz: ec390f593922863ed5040d26ecd809e0b0b469a3
5
5
  SHA512:
6
- metadata.gz: a9186bacc0ef4f585bd8e053e2ba678f980ce263f026fb6623812076bc22f3dc0d10490ac29f4bf31fa0c397dd205e86e96a59825c5cda097516a01914612fd5
7
- data.tar.gz: e7e1ab1b5d90c07c5868a106888a0079f8fa3e4ad638ec97ba2d7d5b2114f75cd9d63e6f4898563fe208625d8bac8f02496c60b2633c5582ee55dac0349784cc
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)
@@ -1,5 +1,5 @@
1
1
  module RestPack
2
2
  module Serializer
3
- VERSION = '0.6.8'
3
+ VERSION = '0.6.9'
4
4
  end
5
5
  end
@@ -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.8
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: 2016-11-24 00:00:00.000000000 Z
11
+ date: 2017-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport