pragmatic_serializer 0.4.3 → 0.4.4
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
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ccb87bd6b0b7e66bf5ec4d49cbb62fccdbebecb
|
4
|
+
data.tar.gz: e339d3feccefaa403f3c9e0f65262cd8126e5075
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe3106f6c2385de323dc4a29faa7e1be160d1e10def841d71ec3fe89b57b71c7c7a2338ce2bf5de3888566fb07039cdd86d77d473aaf89b75757102d48e86205
|
7
|
+
data.tar.gz: bbf4bb7e5b7a8b40b156ae4f945c795cc50a49c09ca20409e3d9be27941e600731fd60b3becc0aab7edb8a6ff422b1b8dc7e0bb775c33d874acfd8505330f0ba
|
data/README.md
CHANGED
@@ -142,14 +142,12 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERN
|
|
142
142
|
#### paginated list
|
143
143
|
|
144
144
|
```ruby
|
145
|
-
|
146
145
|
paginated_comments = @comments.limit(limit).offset(offset)
|
147
146
|
|
148
147
|
serializer = CommentSerializer.collection(paginated_comments)
|
149
148
|
serializer.limit = limit
|
150
149
|
serializer.offset = offset
|
151
150
|
serializer.total = @comments.size
|
152
|
-
# serializer.resource_serializer_wrapper = ->(x) { begin x; rescue ActiveRecor::Base; end}
|
153
151
|
# serializer.resource_options.include_work = true # to pass more options to individual resource serializer
|
154
152
|
# serializer.include_resources_json = false # to skip rendering resources json array
|
155
153
|
serializer.pagination_evaluator = ->(limit:, offset:) {
|
@@ -158,6 +156,22 @@ serializer.pagination_evaluator = ->(limit:, offset:) {
|
|
158
156
|
serializer.as_json
|
159
157
|
```
|
160
158
|
|
159
|
+
#### Skip missing records in serializer
|
160
|
+
|
161
|
+
```ruby
|
162
|
+
module CustomResourceSerializerWrapper
|
163
|
+
def self.call
|
164
|
+
begin
|
165
|
+
yield
|
166
|
+
rescue ActiveRecord::Base
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
serializer.resource_serializer_wrapper = CustomResourceSerializerWrapper
|
172
|
+
|
173
|
+
```
|
174
|
+
|
161
175
|
## License
|
162
176
|
|
163
177
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/lib/pragmatic_serializer.rb
CHANGED
@@ -3,6 +3,7 @@ require 'ostruct'
|
|
3
3
|
require 'active_support/core_ext/string/inflections'
|
4
4
|
|
5
5
|
require "pragmatic_serializer/version"
|
6
|
+
require "pragmatic_serializer/resource_serializer_wrapper"
|
6
7
|
require "pragmatic_serializer/configuration"
|
7
8
|
require "pragmatic_serializer/config_interface"
|
8
9
|
|
@@ -64,13 +64,15 @@ module PragmaticSerializer
|
|
64
64
|
def as_unprefixed_json
|
65
65
|
collection_serializers
|
66
66
|
.map do |rs|
|
67
|
-
resource_serializer_wrapper.call
|
67
|
+
resource_serializer_wrapper.call do
|
68
|
+
rs.send(serialization_method)
|
69
|
+
end
|
68
70
|
end
|
69
71
|
.compact
|
70
72
|
end
|
71
73
|
|
72
74
|
def resource_serializer_wrapper
|
73
|
-
@resource_serializer_wrapper ||=
|
75
|
+
@resource_serializer_wrapper ||= PragmaticSerializer::ResourceSerializerWrapper
|
74
76
|
end
|
75
77
|
|
76
78
|
private
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pragmatic_serializer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tomas Valent
|
@@ -96,6 +96,7 @@ files:
|
|
96
96
|
- lib/pragmatic_serializer/pagination_json.rb
|
97
97
|
- lib/pragmatic_serializer/prefixes.rb
|
98
98
|
- lib/pragmatic_serializer/resource_interface.rb
|
99
|
+
- lib/pragmatic_serializer/resource_serializer_wrapper.rb
|
99
100
|
- lib/pragmatic_serializer/version.rb
|
100
101
|
- pragmatic_serializer.gemspec
|
101
102
|
homepage: https://github.com/equivalent/pragmatic_serializer
|