panko_serializer 0.7.0 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +8 -3
- data/docs/associations.md +1 -1
- data/docs/attributes.md +18 -10
- data/docs/getting-started.md +14 -1
- data/lib/panko/version.rb +1 -1
- data/panko_serializer.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da5e3519b69aef1b8ada75ae3a245b6eb760a4168aad14e732288b1deaffdf57
|
4
|
+
data.tar.gz: 55dfcbe193da0e64285ebe006f98ac414b29a3f1270e7ae503986e3281332fc7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e49c292a8ffa051e82333f3ec89865c5a50643a150a18a2f0b4755f3a0a0cc3fbfce33bf853a66a3deaed6972f0824d5bf5a52537ff0c1d03c4152fee04659f1
|
7
|
+
data.tar.gz: 7c9084df275f4a096a7f58c95e14304fde32824ae415dc21d1979fab9726884a4d75c2654d060aecebc033751df89a81185a8f044fa887f08812b45d089a5fc7
|
data/.travis.yml
CHANGED
@@ -2,9 +2,9 @@ sudo: false
|
|
2
2
|
cache: bundler
|
3
3
|
language: ruby
|
4
4
|
rvm:
|
5
|
-
- 2.5.
|
6
|
-
- 2.6.
|
7
|
-
- 2.7.0-
|
5
|
+
- 2.5.7
|
6
|
+
- 2.6.5
|
7
|
+
- 2.7.0-rc2
|
8
8
|
|
9
9
|
env:
|
10
10
|
global:
|
@@ -27,3 +27,8 @@ env:
|
|
27
27
|
- "RAILS_VERSION=4.2.0"
|
28
28
|
- "RAILS_VERSION=5.2.0"
|
29
29
|
- "RAILS_VERSION=6.0.0"
|
30
|
+
|
31
|
+
jobs:
|
32
|
+
exclude:
|
33
|
+
- rvm: 2.7.0-rc2
|
34
|
+
- env: RAILS_VERSION=4.2.0
|
data/docs/associations.md
CHANGED
data/docs/attributes.md
CHANGED
@@ -9,11 +9,11 @@ There are two types of attributes:
|
|
9
9
|
|
10
10
|
```ruby
|
11
11
|
class UserSerializer < Panko::Serializer
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
12
|
+
attributes :full_name
|
13
|
+
|
14
|
+
def full_name
|
15
|
+
"#{object.first_name} #{object.last_name}"
|
16
|
+
end
|
17
17
|
end
|
18
18
|
```
|
19
19
|
|
@@ -32,9 +32,11 @@ The serializer's attribute methods can access the object being serialized as `ob
|
|
32
32
|
|
33
33
|
```ruby
|
34
34
|
class PostSerializer < Panko::Serializer
|
35
|
-
|
36
|
-
|
37
|
-
|
35
|
+
attributes :author_name
|
36
|
+
|
37
|
+
def author_name
|
38
|
+
"#{object.author.first_name} #{object.author.last_name}"
|
39
|
+
end
|
38
40
|
end
|
39
41
|
```
|
40
42
|
|
@@ -78,9 +80,16 @@ UserSerializer.new(only: [:name]).serialize(User.first)
|
|
78
80
|
UserSerializer.new(except: [:name]).serialize(User.first)
|
79
81
|
```
|
80
82
|
|
83
|
+
> **Note** that if you want to user filter on an associations, the `:name`
|
84
|
+
> property is not taken into account.
|
85
|
+
> If you have a `has_many :state_transitions, name: :history` association
|
86
|
+
> defined, the key to use in filters is `:state_transitions`
|
87
|
+
> (e.g. `{ except: [:state_statitions] }`)
|
88
|
+
|
81
89
|
## Filters For
|
82
90
|
|
83
|
-
Sometimes you find yourself have the same filtering logic in actions in order to
|
91
|
+
Sometimes you find yourself have the same filtering logic in actions in order to
|
92
|
+
solve this duplication, Panko allows you to write the filters in the serializer.
|
84
93
|
|
85
94
|
```ruby
|
86
95
|
class UserSerializer < Panko::Serializer
|
@@ -122,4 +131,3 @@ class PostSerializer < Panko::Serializer
|
|
122
131
|
aliases created_at: :published_at
|
123
132
|
end
|
124
133
|
```
|
125
|
-
|
data/docs/getting-started.md
CHANGED
@@ -31,6 +31,20 @@ class UserSerializer < Panko::Serializer
|
|
31
31
|
end
|
32
32
|
```
|
33
33
|
|
34
|
+
### Serializing an object
|
35
|
+
|
36
|
+
And now serialize a single object
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
# Using Oj serializer
|
40
|
+
PostSerializer.new.serialize_to_json(Post.first)
|
41
|
+
|
42
|
+
# or, similar to #serializable_hash
|
43
|
+
PostSerializer.new.serialize(Post.first).to_json
|
44
|
+
```
|
45
|
+
|
46
|
+
### Using the serializers in a controller
|
47
|
+
|
34
48
|
As you can see, defining serializers is simple and resembles ActiveModelSerializers 0.9,
|
35
49
|
To utilize the `UserSerializer` inside a Rails controller and serialize some users, all we need to do is:
|
36
50
|
|
@@ -44,4 +58,3 @@ end
|
|
44
58
|
```
|
45
59
|
|
46
60
|
And voila, we have endpoint which serialize users using Panko!
|
47
|
-
|
data/lib/panko/version.rb
CHANGED
data/panko_serializer.gemspec
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.7.
|
4
|
+
version: 0.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yosi Attias
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-12-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oj
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 3.
|
19
|
+
version: 3.10.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 3.
|
26
|
+
version: 3.10.0
|
27
27
|
description:
|
28
28
|
email:
|
29
29
|
- yosy101@gmail.com
|