Module: FacebookAds::EdgeHasGet

Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/facebook_ads/edge.rb

Constant Summary collapse

DEFAULT_PAGE_SIZE =
10

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#has_next_pageObject

Returns the value of attribute has_next_page.



27
28
29
# File 'lib/facebook_ads/edge.rb', line 27

def has_next_page
  @has_next_page
end

#next_page_cursorObject

Returns the value of attribute next_page_cursor.



27
28
29
# File 'lib/facebook_ads/edge.rb', line 27

def next_page_cursor
  @next_page_cursor
end

Instance Method Details

#[](idx) ⇒ Object



29
30
31
32
33
# File 'lib/facebook_ads/edge.rb', line 29

def [](idx)
  # TODO Handle delegate
  fetch_next_page until idx < collection.length || !has_next_page?
  collection[idx]
end

#allObject



35
36
37
38
# File 'lib/facebook_ads/edge.rb', line 35

def all
  fetch_next_page until !has_next_page?
  collection
end

#eachObject



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/facebook_ads/edge.rb', line 40

def each
  return enum_for(:each) unless block_given?

  idx = 0

  while (e = self[idx])
    yield e
    idx += 1
  end

  self
end

#reload!Object



53
54
55
56
57
# File 'lib/facebook_ads/edge.rb', line 53

def reload!
  @collection = Array.new
  self.has_next_page = true
  self.next_page_cursor = nil
end