mirror of
https://github.com/samsonjs/grape-active_model_serializers.git
synced 2026-04-15 12:15:48 +00:00
32 lines
825 B
Ruby
32 lines
825 B
Ruby
module Grape
|
|
module Formatter
|
|
module ActiveModelSerializers
|
|
class << self
|
|
def call(resource, env)
|
|
options = build_options(resource, env)
|
|
serializer = fetch_serializer(resource, options)
|
|
|
|
if serializer
|
|
::ActiveModelSerializers::Adapter.create(
|
|
serializer, options
|
|
).to_json
|
|
else
|
|
Grape::Formatter::Json.call(resource, env)
|
|
end
|
|
end
|
|
|
|
def build_options(resource, env)
|
|
Grape::ActiveModelSerializers::OptionsBuilder.new(
|
|
resource, env
|
|
).options
|
|
end
|
|
|
|
def fetch_serializer(resource, options)
|
|
Grape::ActiveModelSerializers::SerializerResolver.new(
|
|
resource, options
|
|
).serializer
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|