panko_serializer 0.3.5 → 0.3.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/docs/attributes.md +21 -0
- data/lib/panko/response.rb +8 -4
- data/lib/panko/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 96dad22f02249aef4645ed0fe38a682480dca110dd98bf6886a9dd2683afd1ce
|
4
|
+
data.tar.gz: '09f796883e362201f81ae647718f38640753874bceb8d5aca5d4de48fac79f33'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1e2c900a216bfe9a6ac8b41b6c2c3ba965bb748090bd43317c8d9f3a1412950ed22185bdb7bd87f94da35f6dcc5b44123af932286e9692303bf1e18fbd30c17
|
7
|
+
data.tar.gz: 50c568c4374b2b30e7f5815eafb0252c7a4e63c94a073360021bae109832ef7bf7de63e6da4c454dad7f35f329d7c8a64f3cfb1ee106fc3a043307980feb922b
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
[![Build Status](https://travis-ci.org/yosiat/panko_serializer.svg?branch=master)](https://travis-ci.org/yosiat/panko_serializer)
|
4
4
|
|
5
|
-
Panko is library which is inspired by ActiveModelSerializers 0.9 for serializing ActiveRecord objects to JSON strings, fast.
|
5
|
+
Panko is library which is inspired by ActiveModelSerializers 0.9 for serializing ActiveRecord/Ruby objects to JSON strings, fast.
|
6
6
|
|
7
7
|
To achieve it's [performance](https://yosiat.github.io/panko_serializer/performance.html):
|
8
8
|
|
data/docs/attributes.md
CHANGED
@@ -78,6 +78,27 @@ UserSerializer.new(only: [:name]).serialize(User.first)
|
|
78
78
|
UserSerializer.new(except: [:name]).serialize(User.first)
|
79
79
|
```
|
80
80
|
|
81
|
+
## Filters For
|
82
|
+
|
83
|
+
Sometimes you find yourself have the same filtering logic in actions in order to solve this duplication, Panko allows you to write the filters in the serializer.
|
84
|
+
|
85
|
+
```ruby
|
86
|
+
class UserSerializer < Panko::Serializer
|
87
|
+
attributes :id, :name, :email
|
88
|
+
|
89
|
+
def self.filters_for(context)
|
90
|
+
{
|
91
|
+
only: [:name]
|
92
|
+
}
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
# this line will return { 'name': '..' }
|
97
|
+
UserSerializer.serialize(User.first)
|
98
|
+
```
|
99
|
+
|
100
|
+
> See disucssion in: https://github.com/yosiat/panko_serializer/issues/16
|
101
|
+
|
81
102
|
## Aliases
|
82
103
|
|
83
104
|
Let's say we have attribute name that we want to expose to client as different name, the current way of doing so is using method attribute, for example:
|
data/lib/panko/response.rb
CHANGED
@@ -19,12 +19,16 @@ module Panko
|
|
19
19
|
writer.push_object
|
20
20
|
|
21
21
|
@data.each do |key, value|
|
22
|
-
|
23
|
-
|
22
|
+
key = key.to_s
|
23
|
+
|
24
|
+
if value.is_a?(Panko::ArraySerializer) ||
|
25
|
+
value.is_a?(Panko::Serializer) ||
|
26
|
+
value.is_a?(Panko::Response)
|
27
|
+
writer.push_json(value.to_json, key)
|
24
28
|
elsif value.is_a?(Panko::JsonValue)
|
25
|
-
writer.push_json(value.value, key
|
29
|
+
writer.push_json(value.value, key)
|
26
30
|
else
|
27
|
-
writer.push_value(value, key
|
31
|
+
writer.push_value(value, key)
|
28
32
|
end
|
29
33
|
end
|
30
34
|
|
data/lib/panko/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: panko_serializer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yosi Attias
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-02-
|
11
|
+
date: 2018-02-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -172,7 +172,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
172
172
|
version: '0'
|
173
173
|
requirements: []
|
174
174
|
rubyforge_project:
|
175
|
-
rubygems_version: 2.7.
|
175
|
+
rubygems_version: 2.7.4
|
176
176
|
signing_key:
|
177
177
|
specification_version: 4
|
178
178
|
summary: Fast serialization for ActiveModel
|