File: active_model_serializers.rb

package info (click to toggle)
ruby-active-model-serializers 0.10.12-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,752 kB
  • sloc: ruby: 13,138; sh: 53; makefile: 6
file content (19 lines) | stat: -rw-r--r-- 704 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# frozen_string_literal: true

# Helpers can be included in your Grape endpoint as: helpers Grape::Helpers::ActiveModelSerializers

module Grape
  module Helpers
    module ActiveModelSerializers
      # A convenience method for passing ActiveModelSerializers serializer options
      #
      # Example: To include relationships in the response: render(post, include: ['comments'])
      #
      # Example: To include pagination meta data: render(posts, meta: { page: posts.page, total_pages: posts.total_pages })
      def render(resource, active_model_serializer_options = {})
        env[:active_model_serializer_options] = active_model_serializer_options
        resource
      end
    end
  end
end