Module: Grape::Formatter::ActiveModelSerializers

Defined in:
lib/grape-active_model_serializers/formatter.rb

Class Method Summary collapse

Class Method Details

.build_options(resource, env) ⇒ Object


18
19
20
21
22
# File 'lib/grape-active_model_serializers/formatter.rb', line 18

def build_options(resource, env)
  Grape::ActiveModelSerializers::OptionsBuilder.new(
    resource, env
  ).options
end

.call(resource, env) ⇒ Object


5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/grape-active_model_serializers/formatter.rb', line 5

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

.fetch_serializer(resource, options) ⇒ Object


24
25
26
27
28
# File 'lib/grape-active_model_serializers/formatter.rb', line 24

def fetch_serializer(resource, options)
  Grape::ActiveModelSerializers::SerializerResolver.new(
    resource, options
  ).serializer
end