Sha256: 59e1c6bb1765e50490ac625bc059c9cace21f414bd6205c93952117c4b711b89

Contents?: true

Size: 1.12 KB

Versions: 1

Compression:

Stored size: 1.12 KB

Contents

# frozen_string_literal: true
module Apress
  module Api
    module Extensions
      module Jbuilder
        module JbuilderTemplate
          def paginating_cache!(collection, key = nil, options = nil)
            if @context.controller.perform_caching
              result = Rails.cache.fetch(_cache_key(key || collection, options), options) do
                {
                  headers: _pagination_headers(collection),
                  content: _scope { yield self }
                }
              end

              _set_pagination_headers(result[:headers])

              merge! result[:content]
            else
              _set_pagination_headers(_pagination_headers(collection))

              yield
            end
          end

          private

          def _set_pagination_headers(headers)
            @context.controller.response.headers.merge!(headers)
          end

          def _pagination_headers(collection)
            ::Apress::Api::ApiController::PaginationHelper.headers(
              collection,
              @context.controller.request.url
            )
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
apress-api-1.24.2 lib/apress/api/extensions/jbuilder/jbuilder_template.rb