Sha256: 435ec99dbddb8ac5bd2eb3f081cb2db3ff211d71ae1a89e46178b17a9c04feef

Contents?: true

Size: 711 Bytes

Versions: 1

Compression:

Stored size: 711 Bytes

Contents

require 'thron/paginator'

module Thron
  module Pageable
    module ClassMethods
      def paginate(*apis)
        (@paginated_apis = apis).each do |api|
          define_method("#{api}_paginator") do |*args|
            options = args.empty? ? {} : args.last
            limit = options.delete(:limit) { Paginator::MAX_LIMIT }
            body = ->(limit, offset) { send(api, options.merge!({ offset: offset, limit: limit })) }
            Paginator::new(body: body, limit: limit)
          end
        end
      end

      def paginator_methods
        Array(@paginated_apis).map { |api| :"#{api}_paginator" }
      end
    end

    def self.included(klass)
      klass.extend ClassMethods
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
thron-0.7.0 lib/thron/pageable.rb