Class: NotionRb::Utils::BlockCache
- Inherits:
-
Object
- Object
- NotionRb::Utils::BlockCache
- Includes:
- Singleton
- Defined in:
- lib/notion_rb/utils/block_cache.rb
Instance Method Summary collapse
- #add_collection_view_blocks(block) ⇒ Object
- #children(notion_id) ⇒ Object
- #clear ⇒ Object
- #contains?(notion_id) ⇒ Boolean
- #find(notion_id) ⇒ Object
-
#initialize ⇒ BlockCache
constructor
A new instance of BlockCache.
Constructor Details
#initialize ⇒ BlockCache
Returns a new instance of BlockCache.
8 9 10 |
# File 'lib/notion_rb/utils/block_cache.rb', line 8 def initialize @blocks = [] end |
Instance Method Details
#add_collection_view_blocks(block) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/notion_rb/utils/block_cache.rb', line 34 def add_collection_view_blocks(block) return unless block[:block_type] == 'collection_view_page' = block[:metadata] query_collection = NotionRb::Api::QueryCollection.new(collection_id: [:collection_id], view_id: [:view_ids][0]) block[:children] = [[:collection_id]] add_blocks(query_collection.blocks) end |
#children(notion_id) ⇒ Object
24 25 26 27 28 |
# File 'lib/notion_rb/utils/block_cache.rb', line 24 def children(notion_id) return nil unless find(notion_id) find(notion_id)[:children] end |
#clear ⇒ Object
30 31 32 |
# File 'lib/notion_rb/utils/block_cache.rb', line 30 def clear @blocks = [] end |
#contains?(notion_id) ⇒ Boolean
12 13 14 |
# File 'lib/notion_rb/utils/block_cache.rb', line 12 def contains?(notion_id) @blocks.any? { |block| block[:notion_id] == notion_id } end |
#find(notion_id) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/notion_rb/utils/block_cache.rb', line 16 def find(notion_id) add_block(notion_id) unless contains?(notion_id) @blocks.find { |block| block[:notion_id] == notion_id } rescue Mechanize::ResponseCodeError nil end |