Sha256: 7dad9fdccad39a360a4d0ca9106523a7aef821a74cdf72cd614b13bbb0842fe4

Contents?: true

Size: 751 Bytes

Versions: 5

Compression:

Stored size: 751 Bytes

Contents

module Encore
  module Serializer
    module MetaManager
      extend ActiveSupport::Concern

      def self.paginate_collection(collection, options)
        return collection if options[:skip_paging]

        collection.page(options[:page]).per(options[:per_page])
      end

      def self.add(collection, serializer, options)
        return {} if options[:skip_paging]

        { serializer.root_key => pagination_for(collection) }
      end

      def self.pagination_for(collection)
        {
          page: collection.current_page,
          count: collection.total_count,
          page_count: collection.num_pages,
          previous_page: collection.prev_page,
          next_page: collection.next_page
        }
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
encore-0.2.3 lib/encore/serializer/meta_manager.rb
encore-0.2.2 lib/encore/serializer/meta_manager.rb
encore-0.2.1 lib/encore/serializer/meta_manager.rb
encore-0.2 lib/encore/serializer/meta_manager.rb
encore-0.1 lib/encore/serializer/meta_manager.rb