Module: Zendesk::Paginator
- Includes:
- Enumerable
- Included in:
- Collection
- Defined in:
- lib/zendesk/paginator.rb
Instance Attribute Summary (collapse)
-
- (Object) query
readonly
Returns the value of attribute query.
Instance Method Summary (collapse)
- - (Object) [](idx)
- - (Object) clear_cache
-
- (Object) each
call block once for each element in self.
-
- (Object) fetch(force = false)
fetches actual result of request.
- - (Object) method_missing(method, *args)
- - (Object) page(number)
-
- (Object) per_page(count = 15)
number of results to return per page.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
- (Object) method_missing(method, *args)
54 55 56 |
# File 'lib/zendesk/paginator.rb', line 54 def method_missing(method, *args) fetch.send(method, *args) end |
Instance Attribute Details
- (Object) query (readonly)
Returns the value of attribute query
5 6 7 |
# File 'lib/zendesk/paginator.rb', line 5 def query @query end |
Instance Method Details
- (Object) [](idx)
50 51 52 |
# File 'lib/zendesk/paginator.rb', line 50 def [](idx) fetch[idx] end |
- (Object) clear_cache
7 8 9 10 |
# File 'lib/zendesk/paginator.rb', line 7 def clear_cache @cache = nil @query = {} end |
- (Object) each
call block once for each element in self
46 47 48 |
# File 'lib/zendesk/paginator.rb', line 46 def each fetch.each {|result| yield result} end |
- (Object) fetch(force = false)
fetches actual result of request
37 38 39 40 41 42 43 |
# File 'lib/zendesk/paginator.rb', line 37 def fetch(force=false) if @cache.nil? || force = query.dup @cache = get(.delete(:path), ) end @cache end |
- (Object) page(number)
18 19 20 21 |
# File 'lib/zendesk/paginator.rb', line 18 def page(number) @query[:page] = number self end |
- (Object) per_page(count = 15)
number of results to return per page
13 14 15 16 |
# File 'lib/zendesk/paginator.rb', line 13 def per_page(count=15) @query[:per_page] = count self end |