Class: NotionRb::Block
Constant Summary
Utils::Types::TYPE_MAPPER
Instance Attribute Summary collapse
Instance Method Summary
collapse
#select_parser, #valid_block_type?
#parse_from_hex, #parse_from_url, #parse_uuid
Constructor Details
#initialize(url_or_uuid) ⇒ Block
Returns a new instance of Block.
10
11
12
13
14
|
# File 'lib/notion_rb/block.rb', line 10
def initialize(url_or_uuid)
@block_container = NotionRb::Utils::BlockCache.instance
@uuid = parse_uuid url_or_uuid
get_resource
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
85
86
87
88
89
90
91
|
# File 'lib/notion_rb/block.rb', line 85
def method_missing(method, *args, &block)
if schema_methods.include?(method)
send_schema_method(method)
else
super
end
end
|
Instance Attribute Details
#uuid ⇒ Object
Returns the value of attribute uuid.
8
9
10
|
# File 'lib/notion_rb/block.rb', line 8
def uuid
@uuid
end
|
Instance Method Details
#children ⇒ Object
44
45
46
47
48
49
50
|
# File 'lib/notion_rb/block.rb', line 44
def children
if type == 'collection_view_page'
@children ||= [self.class.new(metadata[:collection_id])]
else
@children ||= @block_container.children(@uuid).map { |child_uuid| self.class.new(child_uuid) }
end
end
|
#create_child ⇒ Object
52
53
54
55
56
57
58
|
# File 'lib/notion_rb/block.rb', line 52
def create_child
creator = NotionRb::Api::Create.new(parent_id: @uuid)
return nil unless creator.success?
@block[:children] << creator.block_uuid
self.class.new(creator.block_uuid)
end
|
#destroy ⇒ Object
65
66
67
|
# File 'lib/notion_rb/block.rb', line 65
def destroy
NotionRb::Api::Destroy.new(notion_id: @uuid, parent_id: @block[:parent_id]).success?
end
|
36
37
38
|
# File 'lib/notion_rb/block.rb', line 36
def metadata
@block[:metadata].except(:properties)
end
|
#parent ⇒ Object
40
41
42
|
# File 'lib/notion_rb/block.rb', line 40
def parent
@parent ||= self.class.new(@block[:parent_id])
end
|
#restore ⇒ Object
69
70
71
|
# File 'lib/notion_rb/block.rb', line 69
def restore
NotionRb::Api::Restore.new(notion_id: @uuid, parent_id: @block[:parent_id]).success?
end
|
#save ⇒ Object
60
61
62
63
|
# File 'lib/notion_rb/block.rb', line 60
def save
post_resource
end
|
#title ⇒ Object
16
17
18
|
# File 'lib/notion_rb/block.rb', line 16
def title
@block[:title]
end
|
#title=(title) ⇒ Object
20
21
22
23
|
# File 'lib/notion_rb/block.rb', line 20
def title=(title)
@block[:title] = title
save
end
|
#type ⇒ Object
25
26
27
|
# File 'lib/notion_rb/block.rb', line 25
def type
@block[:block_type]
end
|
#type=(type) ⇒ Object
29
30
31
32
33
34
|
# File 'lib/notion_rb/block.rb', line 29
def type=(type)
return unless valid_block_type?(type)
@block[:block_type] = type
save
end
|