@@ -179,17 +179,27 @@ def mixpanel_integration?
179
179
180
180
unless @is_smart_collection
181
181
attributes ( active_record_class ) . each do |attribute |
182
- serializer . attribute ( attribute )
182
+ serializer . attribute ( attribute ) do |x |
183
+ begin
184
+ object . send ( attribute )
185
+ rescue
186
+ nil
187
+ end
188
+ end
183
189
end
184
190
185
191
# NOTICE: Format time type fields during the serialization.
186
192
attributes_time ( active_record_class ) . each do |attribute |
187
193
serializer . attribute ( attribute ) do |x |
188
- value = object . send ( attribute )
189
- if value
190
- match = /(\d {2}:\d {2}:\d {2})/ . match ( value . to_s )
191
- ( match && match [ 1 ] ) ? match [ 1 ] : nil
192
- else
194
+ begin
195
+ value = object . send ( attribute )
196
+ if value
197
+ match = /(\d {2}:\d {2}:\d {2})/ . match ( value . to_s )
198
+ ( match && match [ 1 ] ) ? match [ 1 ] : nil
199
+ else
200
+ nil
201
+ end
202
+ rescue
193
203
nil
194
204
end
195
205
end
@@ -198,22 +208,38 @@ def mixpanel_integration?
198
208
# NOTICE: Format serialized fields.
199
209
attributes_serialized ( active_record_class ) . each do |attr , serialization |
200
210
serializer . attribute ( attr ) do |x |
201
- value = object . send ( attr )
202
- value ? value . to_json : nil
211
+ begin
212
+ value = object . send ( attr )
213
+ value ? value . to_json : nil
214
+ rescue
215
+ nil
216
+ end
203
217
end
204
218
end
205
219
206
220
# NOTICE: Format CarrierWave url attribute
207
221
if active_record_class . respond_to? ( :mount_uploader )
208
222
active_record_class . uploaders . each do |key , value |
209
- serializer . attribute ( key ) { |x | object . send ( key ) . try ( :url ) }
223
+ serializer . attribute ( key ) do |x |
224
+ begin
225
+ object . send ( key ) . try ( :url )
226
+ rescue
227
+ nil
228
+ end
229
+ end
210
230
end
211
231
end
212
232
213
233
# NOTICE: Format Paperclip url attribute
214
234
if active_record_class . respond_to? ( :attachment_definitions )
215
235
active_record_class . attachment_definitions . each do |key , value |
216
- serializer . attribute ( key ) { |x | object . send ( key ) }
236
+ serializer . attribute ( key ) do |x |
237
+ begin
238
+ object . send ( key )
239
+ rescue
240
+ nil
241
+ end
242
+ end
217
243
end
218
244
end
219
245
@@ -223,7 +249,11 @@ def mixpanel_integration?
223
249
active_record_class . acts_as_taggable . respond_to? ( :to_a )
224
250
active_record_class . acts_as_taggable . to_a . each do |key , value |
225
251
serializer . attribute ( key ) do |x |
226
- object . send ( key ) . map ( &:name )
252
+ begin
253
+ object . send ( key ) . map ( &:name )
254
+ rescue
255
+ nil
256
+ end
227
257
end
228
258
end
229
259
end
@@ -277,8 +307,7 @@ def mixpanel_integration?
277
307
serializer . send ( :has_many , :mixpanel_last_events ) { }
278
308
end
279
309
280
- ForestLiana ::SerializerFactory . define_serializer ( active_record_class ,
281
- serializer )
310
+ ForestLiana ::SerializerFactory . define_serializer ( active_record_class , serializer )
282
311
283
312
serializer
284
313
end
0 commit comments