Class: Riveter::RunsPage

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/riveter/page.rb

Overview

One page of runs. #each iterates the page; #auto_paging_each walks every following page too.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, fetch_page) ⇒ RunsPage

Returns a new instance of RunsPage.



11
12
13
14
15
16
17
# File 'lib/riveter/page.rb', line 11

def initialize(data, fetch_page)
  data = data.is_a?(Hash) ? data : {}
  @runs = (data["runs"] || []).map { |item| RunListItem.new(item) }
  @pagination = Pagination.new(data["pagination"] || {})
  @monitor_id = data["monitor_id"]
  @fetch_page = fetch_page
end

Instance Attribute Details

#monitor_idObject (readonly)

Returns the value of attribute monitor_id.



9
10
11
# File 'lib/riveter/page.rb', line 9

def monitor_id
  @monitor_id
end

#paginationObject (readonly)

Returns the value of attribute pagination.



9
10
11
# File 'lib/riveter/page.rb', line 9

def pagination
  @pagination
end

#runsObject (readonly)

Returns the value of attribute runs.



9
10
11
# File 'lib/riveter/page.rb', line 9

def runs
  @runs
end

Instance Method Details

#auto_paging_each(&block) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/riveter/page.rb', line 31

def auto_paging_each(&block)
  return enum_for(:auto_paging_each) unless block

  page = self
  loop do
    page.runs.each(&block)
    break unless page.next_page?

    page = page.next_page
  end
end

#each(&block) ⇒ Object



19
20
21
# File 'lib/riveter/page.rb', line 19

def each(&block)
  @runs.each(&block)
end

#next_pageObject



27
28
29
# File 'lib/riveter/page.rb', line 27

def next_page
  RunsPage.new(@fetch_page.call((pagination.page || 1) + 1), @fetch_page)
end

#next_page?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/riveter/page.rb', line 23

def next_page?
  (pagination.page || 1) < (pagination.total_pages || 1)
end