Class: Honeybadger::Api::Paginator
- Inherits:
-
Object
- Object
- Honeybadger::Api::Paginator
- Defined in:
- lib/honeybadger-api/paginator.rb
Instance Attribute Summary collapse
-
#current_page ⇒ Object
readonly
Returns the value of attribute current_page.
-
#pages ⇒ Object
readonly
Returns the value of attribute pages.
-
#total_page_count ⇒ Object
readonly
Returns the value of attribute total_page_count.
Instance Method Summary collapse
- #collection ⇒ Object
-
#initialize(path, filters, handler) ⇒ Paginator
constructor
A new instance of Paginator.
- #next ⇒ Object
- #next? ⇒ Boolean
- #previous ⇒ Object
- #previous? ⇒ Boolean
Constructor Details
#initialize(path, filters, handler) ⇒ Paginator
Returns a new instance of Paginator.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/honeybadger-api/paginator.rb', line 7 def initialize(path, filters, handler) @path = path @filters = filters @handler = handler @pages = {} @filters.merge!({ :page => 1 }) if !@filters.has_key?(:page) response = Honeybadger::Api.client.get(@path, @filters) @current_page = response[:current_page] @total_page_count = response[:num_pages] @pages[current_page] = response[:results].map do |r| @handler.call(r) end end |
Instance Attribute Details
#current_page ⇒ Object (readonly)
Returns the value of attribute current_page.
5 6 7 |
# File 'lib/honeybadger-api/paginator.rb', line 5 def current_page @current_page end |
#pages ⇒ Object (readonly)
Returns the value of attribute pages.
5 6 7 |
# File 'lib/honeybadger-api/paginator.rb', line 5 def pages @pages end |
#total_page_count ⇒ Object (readonly)
Returns the value of attribute total_page_count.
5 6 7 |
# File 'lib/honeybadger-api/paginator.rb', line 5 def total_page_count @total_page_count end |
Instance Method Details
#collection ⇒ Object
67 68 69 |
# File 'lib/honeybadger-api/paginator.rb', line 67 def collection @pages.values.flatten end |
#next ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/honeybadger-api/paginator.rb', line 33 def next if next? response = Honeybadger::Api.client.get(@path, @filters.merge({:page => current_page + 1})) @current_page = response[:current_page] @total_page_count = response[:num_pages] @pages[current_page] = response[:results].map do |r| @handler.call(r) end @pages[current_page] else nil end end |
#next? ⇒ Boolean
25 26 27 |
# File 'lib/honeybadger-api/paginator.rb', line 25 def next? current_page < total_page_count end |
#previous ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/honeybadger-api/paginator.rb', line 50 def previous if previous? response = Honeybadger::Api.client.get(@path, @filters.merge({:page => current_page - 1})) @current_page = response[:current_page] @total_page_count = response[:num_pages] @pages[current_page] = response[:results].map do |r| @handler.call(r) end @pages[current_page] else nil end end |
#previous? ⇒ Boolean
29 30 31 |
# File 'lib/honeybadger-api/paginator.rb', line 29 def previous? current_page > 1 end |