Sha256: 596df069937cca6d63091745a19945fd1fe67ef34924ea7ca375dc83a14a46cb

Contents?: true

Size: 681 Bytes

Versions: 2

Compression:

Stored size: 681 Bytes

Contents

# A Grape response formatter that can be used as 'formatter :json, Grape::Formatters::ActiveModelSerializers'
#
# Serializer options can be passed as a hash from your Grape endpoint using env[:active_model_serializer_options],
# or better yet user the render helper in Grape::Helpers::ActiveModelSerializers
module Grape
  module Formatters
    module ActiveModelSerializers
      def self.call(resource, env)
        serializer_options = {}
        serializer_options.merge!(env[:active_model_serializer_options]) if env[:active_model_serializer_options]
        ::ActiveModelSerializers::SerializableResource.new(resource, serializer_options).to_json
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
active_model_serializers-0.10.0 lib/grape/formatters/active_model_serializers.rb
active_model_serializers-0.10.0.rc5 lib/grape/formatters/active_model_serializers.rb