Sha256: ebbc83d22310fdadb0e9e44f2778c7481fd9f06a5d2147b0fb43daa25f8ff5f4

Contents?: true

Size: 584 Bytes

Versions: 9

Compression:

Stored size: 584 Bytes

Contents

# Helpful serializer for including pagination meta
# Source: http://stackoverflow.com/a/23002614/131208
module Tenon
  class PaginatingSerializer < ActiveModel::ArraySerializer
    def initialize(object, options = {})
      meta_key = options[:meta_key] || :meta
      options[meta_key] ||= {}
      options[meta_key][:pagination] = {
        current_page: object.current_page,
        per_page: object.per_page,
        offset: object.offset,
        total_pages: object.total_pages,
        total_entries: object.total_entries
      }
      super(object, options)
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
tenon-2.0.8 app/serializers/tenon/paginating_serializer.rb
tenon-2.0.7 app/serializers/tenon/paginating_serializer.rb
tenon-2.0.6 app/serializers/tenon/paginating_serializer.rb
tenon-2.0.5 app/serializers/tenon/paginating_serializer.rb
tenon-2.0.4 app/serializers/tenon/paginating_serializer.rb
tenon-2.0.3 app/serializers/tenon/paginating_serializer.rb
tenon-2.0.2 app/serializers/tenon/paginating_serializer.rb
tenon-2.0.1 app/serializers/tenon/paginating_serializer.rb
tenon-2.0.0 app/serializers/tenon/paginating_serializer.rb