class MC2P::Paginator

Paginator - class used on list requests

Attributes

count[RW]
results[RW]

Public Class Methods

new(json_dict, object_item_class, resource) click to toggle source

Initializes a paginator Params:

json_dict

Response from server

object_item_class

Class to wrapper all the items from results field

resource

Resource used to get next and previous items

# File lib/base.rb, line 12
def initialize(json_dict, object_item_class, resource)
  @count = json_dict.fetch('count', 0)
  @_previous = json_dict.fetch('previous', nil)
  @_next = json_dict.fetch('next', nil)
  @results = []
  json_dict.fetch('results', []).each do |result|
    @results.push(object_item_class.new(result, resource))
    @resource = resource
  end
end

Public Instance Methods

next_list() click to toggle source

Params: Returns: Paginator object with the next items

# File lib/base.rb, line 25
def next_list
  @_next ? @resource.list(abs_url: @_next) : nil
end
previous_list() click to toggle source

Params: Returns: Paginator object with the previous items

# File lib/base.rb, line 31
def previous_list
  @_previous ? @resource.list(abs_url: @_previous) : nil
end