serializr 0.4.0 β 0.5.0
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 +5 -5
- data/README.md +5 -8
- data/lib/serializr.rb +1 -1
- data/lib/serializr/railtie.rb +11 -6
- data/lib/serializr/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f1c8c50f1b820e298de894473e5c2ae391db2aa2b925b57ee0d181b5e871008b
|
4
|
+
data.tar.gz: ccc4309319c18d48d32062d694c2c372aa001c8cc67d5a94bd9da63a500055b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 225b4811ddc1a06f5f17bfe385b715b21334f1b85a63b3fb4f28d8d2774fcda3e46d4bb53b1f8afc98da5f0af023b7fefffe3c4ecec7f349df36f389949c3db3
|
7
|
+
data.tar.gz: 95043ddd75bfeb38e88e5a4041606f29e838222872fbf61a57ceb5d5816e221f43947a003e19a0ec2ccd266470b169c7ea7dbdacef9c7a49ad86ba29c0503942
|
data/README.md
CHANGED
@@ -100,7 +100,7 @@ class FriendsController < ApplicationController
|
|
100
100
|
end
|
101
101
|
```
|
102
102
|
|
103
|
-
Being explicit here may have performance benefits, as to guess the Serializer
|
103
|
+
Being explicit here may have performance benefits, as to guess the `Serializer`
|
104
104
|
class to use, we need to unroll the collection. The explicit usage, unarguably,
|
105
105
|
looks pretty awesome as well, so you can wow your friends! Which, is always
|
106
106
|
cool, you know. π
|
@@ -117,10 +117,7 @@ end
|
|
117
117
|
|
118
118
|
And this is how you drop `Action View` off your API's, kids!
|
119
119
|
|
120
|
-
|
121
|
-
call my therapist!_)
|
122
|
-
|
123
|
-
### π Last Thing
|
120
|
+
### βοΈ Last Thing
|
124
121
|
|
125
122
|
To fill the API clichΓ©, we need to go over one last file:
|
126
123
|
`app/serializers/application_serializer.rb`. At first, it looks like this:
|
@@ -142,7 +139,7 @@ For example:
|
|
142
139
|
class ApplicationSerializer < Serializr
|
143
140
|
# You may need the routes helpers, so you can link between resources in your
|
144
141
|
# JSON responses.
|
145
|
-
|
142
|
+
include Rails.application.routes.url_helpers
|
146
143
|
|
147
144
|
cattr_reader :serializer_class_cache do
|
148
145
|
Hash.new do |hash, cls|
|
@@ -167,7 +164,7 @@ class ApplicationSerializer < Serializr
|
|
167
164
|
#
|
168
165
|
# No extra DSL, but still: clean, consise and flexible view code.
|
169
166
|
def render_one(object, serializer: nil)
|
170
|
-
return
|
167
|
+
return if object.nil?
|
171
168
|
|
172
169
|
serializer ||= serializer_class_cache[object.class]
|
173
170
|
serializer.new(object)
|
@@ -188,7 +185,7 @@ Serializr? Really? I know. It's fine.
|
|
188
185
|
|
189
186
|
You can require `serializr`, you can require `serializer` as well. The
|
190
187
|
constants? Both of `Serializr` and `Serializer` point to the same thing. Same
|
191
|
-
for the generators. Use whatever your brain and π like.
|
188
|
+
for the generators. Use whatever your brain and π (fingers) like.
|
192
189
|
|
193
190
|
## Contributing
|
194
191
|
|
data/lib/serializr.rb
CHANGED
data/lib/serializr/railtie.rb
CHANGED
@@ -2,15 +2,20 @@
|
|
2
2
|
|
3
3
|
class Serializr
|
4
4
|
class Railtie < ::Rails::Railtie
|
5
|
+
config.serializr = config.serializer = ActiveSupport::OrderedOptions.new
|
6
|
+
config.serializr.integration = true
|
7
|
+
|
5
8
|
initializer 'serializr.initialize' do
|
6
|
-
|
9
|
+
if config.serializr.integration
|
10
|
+
require 'serializr/integration'
|
7
11
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
+
# For Rails 5, automatically include this in the API controllers.
|
13
|
+
if defined?(ActionController::API)
|
14
|
+
ActionController::API.include(::Serializr::Integration)
|
15
|
+
end
|
12
16
|
|
13
|
-
|
17
|
+
ActionController::Base.include(::Serializr::Integration)
|
18
|
+
end
|
14
19
|
end
|
15
20
|
end
|
16
21
|
end
|
data/lib/serializr/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: serializr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Genadi Samokovarov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-03-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -114,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
114
114
|
version: '0'
|
115
115
|
requirements: []
|
116
116
|
rubyforge_project:
|
117
|
-
rubygems_version: 2.
|
117
|
+
rubygems_version: 2.7.3
|
118
118
|
signing_key:
|
119
119
|
specification_version: 4
|
120
120
|
summary: Plain and simple JSON serializer.
|