Class: Rails::Surrender::PaginationBuilder
- Inherits:
-
Object
- Object
- Rails::Surrender::PaginationBuilder
- 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
-
#pagination ⇒ Object
readonly
Returns the value of attribute pagination.
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
Instance Method Summary collapse
- #build! ⇒ Object
-
#initialize(resource:, pagination:) ⇒ PaginationBuilder
constructor
A new instance of PaginationBuilder.
- #paginatable? ⇒ Boolean
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
#pagination ⇒ Object (readonly)
Returns the value of attribute pagination.
7 8 9 |
# File 'lib/rails/surrender/helpers/pagination_builder.rb', line 7 def pagination @pagination end |
#resource ⇒ Object (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
20 21 22 |
# File 'lib/rails/surrender/helpers/pagination_builder.rb', line 20 def paginatable? resource.respond_to?(:page) end |