fast_serializer 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/HISTORY.md +4 -0
- data/README.md +8 -1
- data/VERSION +1 -1
- data/lib/fast_serializer/serializer.rb +9 -0
- data/spec/array_serializer_spec.rb +8 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c038967d22d51bae0cd7f9993f625dbc3d1b747590ec3db6826cf4ac3c4c4ba
|
4
|
+
data.tar.gz: aeffd7e6274da8733f26556e6be03799fc182e05e8888245b4fe3a62df5c881c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d21207437c1ea463715ee99cd354de62c27a455df3f58b3ec56ed8b282276cdd1c6b632870750dbe2946d00aecd17e9457a12e1008e49d0d35cf500a05c973e
|
7
|
+
data.tar.gz: bf2888c605c80312f7fdfb457a258b86ac4c3b4810527e21b5e959c16aaec42933414fefb9121e15bde5a00a941c9cdb63b3d650070788f5712a6a73fac4976f
|
data/HISTORY.md
CHANGED
data/README.md
CHANGED
@@ -220,9 +220,16 @@ You can also pass a cache to a serializer using the `:cache` option.
|
|
220
220
|
If you have a collection of objects to serialize, you can use the `FastSerializer::ArraySerializer` to serialize an enumeration of objects.
|
221
221
|
|
222
222
|
```ruby
|
223
|
-
|
223
|
+
FastSerializer::ArraySerializer.new([a, b, c, d], :serializer => MyObjectSerializer)
|
224
224
|
```
|
225
225
|
|
226
|
+
You can also use the `array` helper class method on a serializer to do the same thing:
|
227
|
+
|
228
|
+
```ruby
|
229
|
+
PersonSerializer.array([a, b, c, d])
|
230
|
+
```
|
231
|
+
|
232
|
+
|
226
233
|
## Performance
|
227
234
|
|
228
235
|
Your mileage may vary. In many cases the performance of the serialization code doesn't particularly matter and this gem performs just about as well as other solutions. However, if you do have high throughput API or can utilize the caching features or have heavily nested models in your JSON responses, then the performance increase may be noticeable.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.1.
|
1
|
+
1.1.1
|
@@ -58,6 +58,7 @@ module FastSerializer
|
|
58
58
|
|
59
59
|
def self.included(base)
|
60
60
|
base.extend(ClassMethods)
|
61
|
+
base.extend(ArrayHelper) unless base.is_a?(FastSerializer::ArraySerializer)
|
61
62
|
end
|
62
63
|
|
63
64
|
# Return the wrapped object that is being serialized.
|
@@ -255,6 +256,14 @@ module FastSerializer
|
|
255
256
|
define_method(attribute){ object.send(field) }
|
256
257
|
end
|
257
258
|
end
|
259
|
+
|
260
|
+
module ArrayHelper
|
261
|
+
# Helper method to serialize an array of values using this serializer.
|
262
|
+
def array(values, options = nil)
|
263
|
+
options = (options ? options.merge(:serializer => self) : {:serializer => self})
|
264
|
+
FastSerializer::ArraySerializer.new(values, options)
|
265
|
+
end
|
266
|
+
end
|
258
267
|
|
259
268
|
# Create a new serializer for the specified object.
|
260
269
|
#
|
@@ -34,6 +34,14 @@ describe FastSerializer::ArraySerializer do
|
|
34
34
|
]
|
35
35
|
end
|
36
36
|
|
37
|
+
it "should be able to use the array helper method on a serializer to serialize an array of objects" do
|
38
|
+
model_1 = SimpleModel.new(:id => 1, :name => "foo")
|
39
|
+
model_2 = SimpleModel.new(:id => 2, :name => "bar")
|
40
|
+
array_serializer = FastSerializer::ArraySerializer.new([model_1, model_2], :serializer => SimpleSerializer, :serializer_options => {:include => :description})
|
41
|
+
helper_serializer = SimpleSerializer.array([model_1, model_2], :serializer_options => {:include => :description})
|
42
|
+
expect(array_serializer.to_json).to eq helper_serializer.to_json
|
43
|
+
end
|
44
|
+
|
37
45
|
it "should not respond to_hash methods" do
|
38
46
|
array = [1, 2, 3]
|
39
47
|
serializer = FastSerializer::ArraySerializer.new(array)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fast_serializer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- We Heart It
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2019-01-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|