Skip to content

Instantly share code, notes, and snippets.

View EmCousin's full-sized avatar
🐶

Emmanuel Cousin EmCousin

🐶
View GitHub Profile
@EmCousin
EmCousin / fast_jsonapi.rb
Created February 21, 2018 19:00
fast_jsonapi formatter for Grape
module Grape
module Formatter
module FastJsonapi
class << self
def call(object, _env)
return object if object.is_a?(String)
return ::Grape::Json.dump(serialize(object)) if serializable?(object)
return object.to_json if object.respond_to?(:to_json)
::Grape::Json.dump(object)