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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4504cdc0e66927014ebd2843a52e8cef9aa5d4443b2a2cc6c31342468ebdeb08
4
- data.tar.gz: 83a6d226222bd9910addcaaf61f2c77ea131da5d0b33bcdf0ecda150d82df878
3
+ metadata.gz: 96dad22f02249aef4645ed0fe38a682480dca110dd98bf6886a9dd2683afd1ce
4
+ data.tar.gz: '09f796883e362201f81ae647718f38640753874bceb8d5aca5d4de48fac79f33'
5
5
  SHA512:
6
- metadata.gz: 8bd4eab5358c889a895dc4ab48623eb5659572312879c5c64fccc5785e62f1cf2a9d576430cae4109937b8e61574a26273d3e9e3399dd92a03e7d60673593fce
7
- data.tar.gz: f3c1994beb8627937db1827f5d5f07ba17d99809f40e752c8a3157bd38c66aa040d2db94722a14cd0643241405512be87ed6696ef5c3037283b3c930215e7709
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
 
@@ -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:
@@ -19,12 +19,16 @@ module Panko
19
19
  writer.push_object
20
20
 
21
21
  @data.each do |key, value|
22
- if value.is_a?(Panko::ArraySerializer) || value.is_a?(Panko::Serializer)
23
- writer.push_json(value.to_json, key.to_s)
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.to_s)
29
+ writer.push_json(value.value, key)
26
30
  else
27
- writer.push_value(value, key.to_s)
31
+ writer.push_value(value, key)
28
32
  end
29
33
  end
30
34
 
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Panko
3
- VERSION = "0.3.5"
3
+ VERSION = "0.3.6"
4
4
  end
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.5
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-10 00:00:00.000000000 Z
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.5
175
+ rubygems_version: 2.7.4
176
176
  signing_key:
177
177
  specification_version: 4
178
178
  summary: Fast serialization for ActiveModel