Class: Drillbit::Resource::Processors::Paging
- Inherits:
-
Object
- Object
- Drillbit::Resource::Processors::Paging
- Defined in:
- lib/drillbit/resource/processors/paging.rb
Instance Attribute Summary collapse
-
#parameters ⇒ Object
Returns the value of attribute parameters.
-
#resource ⇒ Object
Returns the value of attribute resource.
Class Method Summary collapse
- .meta(*attrs) ⇒ Object
-
.processed(*attrs) ⇒ Object
rubocop:enable Style/OptionHash.
Instance Method Summary collapse
-
#initialize(resource, parameters = {}) ⇒ Paging
constructor
rubocop:disable Style/OptionHash.
- #meta ⇒ Object
- #processed ⇒ Object
Constructor Details
#initialize(resource, parameters = {}) ⇒ Paging
rubocop:disable Style/OptionHash
13 14 15 16 |
# File 'lib/drillbit/resource/processors/paging.rb', line 13 def initialize(resource, parameters = {}) self.resource = resource self.parameters = Parameters::Page.new(parameters['page'] || {}) end |
Instance Attribute Details
#parameters ⇒ Object
Returns the value of attribute parameters.
9 10 11 |
# File 'lib/drillbit/resource/processors/paging.rb', line 9 def parameters @parameters end |
#resource ⇒ Object
Returns the value of attribute resource.
9 10 11 |
# File 'lib/drillbit/resource/processors/paging.rb', line 9 def resource @resource end |
Class Method Details
.meta(*attrs) ⇒ Object
23 24 25 |
# File 'lib/drillbit/resource/processors/paging.rb', line 23 def self.(*attrs) new(*attrs). end |
.processed(*attrs) ⇒ Object
rubocop:enable Style/OptionHash
19 20 21 |
# File 'lib/drillbit/resource/processors/paging.rb', line 19 def self.processed(*attrs) new(*attrs).processed end |
Instance Method Details
#meta ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/drillbit/resource/processors/paging.rb', line 35 def return {} unless parameters.present? { 'total-pages' => resource.total_pages, 'current-page' => resource.current_page, 'previous-page' => resource.prev_page, 'next-page' => resource.next_page, } end |
#processed ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/drillbit/resource/processors/paging.rb', line 27 def processed return resource unless parameters.present? resource .page(parameters.page_number) .per(parameters.per_page) end |