class Px::Service::Client::ListResponse
This class implements the methods necessary to be compatible with WillPaginate and Enumerable
Constants
- DEFAULT_PER_PAGE
Attributes
per_page[R]
response[R]
Public Class Methods
new(page_size, response, results_key, options = {})
click to toggle source
# File lib/px/service/client/list_response.rb, line 14 def initialize(page_size, response, results_key, options = {}) @response = response @results_key = results_key @options = options @per_page = page_size || DEFAULT_PER_PAGE end
Public Instance Methods
==(other)
click to toggle source
Allow comparisons with arrays e.g. in Rspec to succeed
# File lib/px/service/client/list_response.rb, line 56 def ==(other) if other.class == self.class other.results == self.results elsif other.class <= Array other == self.results else false end end
Also aliased as: eql?
current_page()
click to toggle source
Get the current page
# File lib/px/service/client/list_response.rb, line 23 def current_page response["current_page"] end
each(&block)
click to toggle source
Support Enumerable
# File lib/px/service/client/list_response.rb, line 50 def each(&block) results.each(&block) end
empty?()
click to toggle source
# File lib/px/service/client/list_response.rb, line 67 def empty? results.empty? end
method_missing(method_name, *arguments, &block)
click to toggle source
# File lib/px/service/client/list_response.rb, line 71 def method_missing(method_name, *arguments, &block) results.send(method_name, *arguments, &block) end
offset()
click to toggle source
# File lib/px/service/client/list_response.rb, line 27 def offset (current_page - 1) * per_page end
raw_results()
click to toggle source
# File lib/px/service/client/list_response.rb, line 44 def raw_results response[@results_key] end
respond_to_missing?(method_name, include_private = false)
click to toggle source
# File lib/px/service/client/list_response.rb, line 75 def respond_to_missing?(method_name, include_private = false) results.respond_to?(method_name, include_private) end
results()
click to toggle source
# File lib/px/service/client/list_response.rb, line 40 def results response[@results_key] end
total_entries()
click to toggle source
# File lib/px/service/client/list_response.rb, line 31 def total_entries response["total_items"] end
Also aliased as: total
total_pages()
click to toggle source
# File lib/px/service/client/list_response.rb, line 36 def total_pages response["total_pages"] end