Sha256: e565a0954655b2a338f981eb47119c706783623566d3a27186d45aa968f718bb

Contents?: true

Size: 846 Bytes

Versions: 1

Compression:

Stored size: 846 Bytes

Contents

module Responders
  module PaginateResponder
    def respond
      paginate! if get? || request.head?

      super
    end

    private

    def paginate!
      adapter = ::Responders::PaginateResponder.init(self)
      @resource = adapter.paginate! if adapter
    end

    class << self
      def register(adapter)
        adapters << adapter
      end

      def adapters
        @adpaters ||= ::Set.new
      end

      def init(responder)
        if responder.controller.respond_to?(:pagination_adapter_init)
          return responder.controller.pagination_adapter_init(responder)
        end

        adapter = find(responder)
        adapter.new(responder) if adapter
      end

      def find(responder)
        adapters.find do |adapter|
          adapter.suitable?(responder.resource, responder)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
paginate-responder-2.1.0 lib/responders/paginate_responder.rb