Module: Zendesk::Paginator

Includes:
Enumerable
Included in:
Collection
Defined in:
lib/zendesk/paginator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



54
55
56
# File 'lib/zendesk/paginator.rb', line 54

def method_missing(method, *args)
  fetch.send(method, *args)
end

Instance Attribute Details

#queryObject (readonly)

Returns the value of attribute query



5
6
7
# File 'lib/zendesk/paginator.rb', line 5

def query
  @query
end

Instance Method Details

#[](idx) ⇒ Object



50
51
52
# File 'lib/zendesk/paginator.rb', line 50

def [](idx)
  fetch[idx]
end

#clear_cacheObject



7
8
9
10
# File 'lib/zendesk/paginator.rb', line 7

def clear_cache
  @cache = nil
  @query = {}
end

#eachObject

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

#fetch(force = false) ⇒ Object

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
    options = query.dup
    @cache = get(options.delete(:path), options)
  end
  @cache
end

#page(number) ⇒ Object



18
19
20
21
# File 'lib/zendesk/paginator.rb', line 18

def page(number)
  @query[:page] = number
  self
end

#per_page(count = 15) ⇒ Object

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