Class: Rails::Surrender::PaginationBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/rails/surrender/helpers/pagination_builder.rb

Overview

apply pagination directives to the given resource, based on the given pagination controls

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource:, pagination:) ⇒ PaginationBuilder

Returns a new instance of PaginationBuilder.



9
10
11
12
# File 'lib/rails/surrender/helpers/pagination_builder.rb', line 9

def initialize(resource:, pagination:)
  @resource = resource
  @pagination = pagination
end

Instance Attribute Details

#paginationObject (readonly)

Returns the value of attribute pagination.



7
8
9
# File 'lib/rails/surrender/helpers/pagination_builder.rb', line 7

def pagination
  @pagination
end

#resourceObject (readonly)

Returns the value of attribute resource.



7
8
9
# File 'lib/rails/surrender/helpers/pagination_builder.rb', line 7

def resource
  @resource
end

Instance Method Details

#build!Object



14
15
16
17
18
# File 'lib/rails/surrender/helpers/pagination_builder.rb', line 14

def build!
  return resource unless paginatable?

  resource.page(pagination.page).per(pagination.per)
end

#paginatable?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/rails/surrender/helpers/pagination_builder.rb', line 20

def paginatable?
  resource.respond_to?(:page)
end