Class: DryCrudJsonapi::Pager
- Inherits:
-
Object
- Object
- DryCrudJsonapi::Pager
- Defined in:
- app/domain/dry_crud_jsonapi/pager.rb
Instance Attribute Summary collapse
-
#model_class ⇒ Object
readonly
Returns the value of attribute model_class.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
Instance Method Summary collapse
- #first_page ⇒ Object
-
#initialize(scope, model_class, params = {}) ⇒ Pager
constructor
A new instance of Pager.
- #last_page ⇒ Object
- #next_page ⇒ Object
- #path(params = {}) ⇒ Object
- #prev_page ⇒ Object
- #render ⇒ Object
Constructor Details
#initialize(scope, model_class, params = {}) ⇒ Pager
Returns a new instance of Pager.
9 10 11 12 13 |
# File 'app/domain/dry_crud_jsonapi/pager.rb', line 9 def initialize(scope, model_class, params = {}) @scope = scope @model_class = model_class @params = params.except(:controller, :action, :format) end |
Instance Attribute Details
#model_class ⇒ Object (readonly)
Returns the value of attribute model_class.
5 6 7 |
# File 'app/domain/dry_crud_jsonapi/pager.rb', line 5 def model_class @model_class end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
5 6 7 |
# File 'app/domain/dry_crud_jsonapi/pager.rb', line 5 def params @params end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
5 6 7 |
# File 'app/domain/dry_crud_jsonapi/pager.rb', line 5 def scope @scope end |
Instance Method Details
#first_page ⇒ Object
19 20 21 |
# File 'app/domain/dry_crud_jsonapi/pager.rb', line 19 def first_page [:first, path(page: 1)] end |
#last_page ⇒ Object
23 24 25 |
# File 'app/domain/dry_crud_jsonapi/pager.rb', line 23 def last_page [:last, path(page: total_pages)] end |
#next_page ⇒ Object
27 28 29 |
# File 'app/domain/dry_crud_jsonapi/pager.rb', line 27 def next_page [:next, path(page: current_page + 1)] unless current_page >= total_pages end |
#path(params = {}) ⇒ Object
35 36 37 |
# File 'app/domain/dry_crud_jsonapi/pager.rb', line 35 def path(params = {}) polymorphic_path(model_class, params.merge(params)) end |
#prev_page ⇒ Object
31 32 33 |
# File 'app/domain/dry_crud_jsonapi/pager.rb', line 31 def prev_page [:prev, path(page: current_page - 1)] unless current_page <= 1 end |
#render ⇒ Object
15 16 17 |
# File 'app/domain/dry_crud_jsonapi/pager.rb', line 15 def render [first_page, last_page, prev_page, next_page].compact.to_h end |