Class: Grape::Pagy::Wrapper

Inherits:
Struct
  • Object
show all
Includes:
Pagy::Backend
Defined in:
lib/grape/pagy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#paramsObject

Returns the value of attribute params

Returns:

  • (Object)

    the current value of params



12
13
14
# File 'lib/grape/pagy.rb', line 12

def params
  @params
end

#requestObject

Returns the value of attribute request

Returns:

  • (Object)

    the current value of request



12
13
14
# File 'lib/grape/pagy.rb', line 12

def request
  @request
end

Instance Method Details

#paginate(collection, using: nil, **opts, &block) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/grape/pagy.rb', line 15

def paginate(collection, using: nil, **opts, &block)
  opts = pagy_countless_get_vars(nil, opts)
  using ||= if collection.respond_to?(:arel_table)
              :arel
            elsif collection.is_a?(Array)
              :array
            end

  method = [:pagy, using].compact.join('_')
  page, scope = send(method, collection, **opts)

  pagy_headers(page).each(&block)
  scope
end