grape-active_model_serializers/lib/grape-active_model_serializers/formatter.rb
John Allen 9d9f166925 Moves Grape::Endpoint extension into a module
Adding methods into the Grape::Endpoint class that
ActiveModel::Serializers are relying on from ActionController as well as
a few convenience methods for Route and Namespace options. I believe we
can expand on some of the empty methods here to allow for higher (api)
level option setting and defaults. This is a first step in that
direction.
2013-05-16 09:14:11 -04:00

27 lines
662 B
Ruby

require 'active_record'
module Grape
module Formatter
module ActiveModelSerializers
class << self
attr_accessor :infer_serializers
attr_reader :endpoint
ActiveModelSerializers.infer_serializers = true
def call(resource, env)
@endpoint = env["api.endpoint"]
options = endpoint.namespace_options.merge(endpoint.route_options)
serializer = ::ActiveModel::Serializer.build_json(endpoint, resource, options)
if serializer
serializer.to_json
else
Grape::Formatter::Json.call resource, env
end
end
end
end
end
end