serializr 0.4.0 β†’ 0.5.0

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
- SHA1:
3
- metadata.gz: 45ef8b2f5a3d79232f564b3291d76e7adbd45f81
4
- data.tar.gz: 274aebc3e16f6cf576eafbd109d8cfeb83933c1d
2
+ SHA256:
3
+ metadata.gz: f1c8c50f1b820e298de894473e5c2ae391db2aa2b925b57ee0d181b5e871008b
4
+ data.tar.gz: ccc4309319c18d48d32062d694c2c372aa001c8cc67d5a94bd9da63a500055b2
5
5
  SHA512:
6
- metadata.gz: b791605ab1b31590591c10459957d9c70e1a474ee6613b0ea9af475bbbb2c408f0f24ed6d0673d96e229cf084e3220a956f9551fde09cf88a95bbb0a826037c4
7
- data.tar.gz: 51d161c8e903117afa2e90f1620d1968892928c763fc72560367913cac12337ef2eda0ee2ccd5741420ff45ad74dba9de9bfd442e1560032fd112a9f9fcd3cef
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
- (_Not really, but anyway, I have the stage now, I do the typing. Fuck off and
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
- inlcude Rails.application.routes.url_helpers
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 unless object
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
@@ -30,7 +30,7 @@ class Serializr
30
30
  def collection_class_cache
31
31
  @@collection_class_cache ||= Hash.new do |hash, cls|
32
32
  hash[cls] = Class.new(cls) do
33
- def as_json
33
+ def as_json(*)
34
34
  serializer = self.class.superclass.new(nil, options)
35
35
 
36
36
  object.map do |obj|
@@ -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
- require 'serializr/integration'
9
+ if config.serializr.integration
10
+ require 'serializr/integration'
7
11
 
8
- # For Rails 5, automatically include this in the API controllers.
9
- if defined?(ActionController::API)
10
- ActionController::API.include(::Serializr::Integration)
11
- end
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
- ActionController::Base.include(::Serializr::Integration)
17
+ ActionController::Base.include(::Serializr::Integration)
18
+ end
14
19
  end
15
20
  end
16
21
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Serializr
4
- VERSION = '0.4.0'
4
+ VERSION = '0.5.0'
5
5
  end
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.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: 2017-04-29 00:00:00.000000000 Z
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.6.11
117
+ rubygems_version: 2.7.3
118
118
  signing_key:
119
119
  specification_version: 4
120
120
  summary: Plain and simple JSON serializer.