Class: Notion::Objects::List

Inherits:
Base
  • Object
show all
Includes:
Enumerable
Defined in:
lib/notion/objects/list.rb

Instance Attribute Summary

Attributes inherited from Base

#raw

Instance Method Summary collapse

Methods inherited from Base

#[], #deconstruct_keys, #in_trash?, #initialize, #inspect, #method_missing, #respond_to_missing?

Constructor Details

This class inherits a constructor from Notion::Objects::Base

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Notion::Objects::Base

Instance Method Details

#each(&block) ⇒ Object



17
18
19
20
21
# File 'lib/notion/objects/list.rb', line 17

def each(&block)
  return enum_for(__method__) unless block

  results.each(&block)
end

#each_pageObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/notion/objects/list.rb', line 23

def each_page
  return enum_for(__method__) unless block_given?

  page = self
  pages = 0
  results = 0
  loop do
    pages += 1
    results += page.results.length
    yield page
    break unless page.has_more? && page.fetcher

    page = page.fetcher.call(page.next_cursor)
  end
  Middleware::Instrumentation.publish("pagination.notion", pages: pages, results: results)
end

#each_result(&block) ⇒ Object



40
41
42
43
44
# File 'lib/notion/objects/list.rb', line 40

def each_result(&block)
  return enum_for(__method__) unless block

  each_page { |page| page.results.each(&block) }
end

#has_more?Boolean

Returns:

  • (Boolean)


15
# File 'lib/notion/objects/list.rb', line 15

def has_more? = !!raw["has_more"]

#next_cursorObject



14
# File 'lib/notion/objects/list.rb', line 14

def next_cursor = raw["next_cursor"]

#resultsObject



10
11
12
# File 'lib/notion/objects/list.rb', line 10

def results
  @results ||= Array(raw["results"]).map { |result| ObjectFactory.build(result) }
end

#with_fetcher(&fetcher) ⇒ Object



46
47
48
49
# File 'lib/notion/objects/list.rb', line 46

def with_fetcher(&fetcher)
  @fetcher = fetcher
  self
end