Class: NotionCf::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/notion_cf/resource.rb

Overview

Notionのブロック、ページ、データベースを表す抽象クラス ストラテジーパターン

Direct Known Subclasses

BlockResource, DatabaseResource, PageResource

Constant Summary collapse

AVAILABLE_TYPES =

unsupportedはNotion APIで作成できないので、テンプレートファイルには含めない

%w[paragraph to_do heading_1 heading_2 heading_3 bulleted_list_item
numbered_list_item toggle quote divider link_to_page callout image bookmark video
audio code file table_of_contents equation breadcrumb synced_block column_list
table child_database child_page].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(blueprint) ⇒ Resource

Returns a new instance of Resource.



31
32
33
34
35
36
37
38
39
# File 'lib/notion_cf/resource.rb', line 31

def initialize(blueprint)
  @blueprint = blueprint
  @object = blueprint[:object]
  @id = blueprint[:id]
  @type = blueprint[:type]
  @parent = blueprint[:parent]
  @has_children = blueprint[:has_children]
  @attributes = blueprint[@type.to_sym]
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



13
14
15
# File 'lib/notion_cf/resource.rb', line 13

def attributes
  @attributes
end

#has_childrenObject (readonly)

Returns the value of attribute has_children.



13
14
15
# File 'lib/notion_cf/resource.rb', line 13

def has_children
  @has_children
end

#idObject (readonly)

Returns the value of attribute id.



13
14
15
# File 'lib/notion_cf/resource.rb', line 13

def id
  @id
end

#objectObject (readonly)

Returns the value of attribute object.



13
14
15
# File 'lib/notion_cf/resource.rb', line 13

def object
  @object
end

#parentObject (readonly)

Returns the value of attribute parent.



13
14
15
# File 'lib/notion_cf/resource.rb', line 13

def parent
  @parent
end

#typeObject (readonly)

Returns the value of attribute type.



13
14
15
# File 'lib/notion_cf/resource.rb', line 13

def type
  @type
end

Class Method Details

.build_resource(blueprint) ⇒ Object

ファクトリーメソッド



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/notion_cf/resource.rb', line 17

def build_resource(blueprint)
  return unless blueprint

  case blueprint[:type]
  when 'child_database'
    NotionCf::DatabaseResource.new(blueprint)
  when 'child_page'
    NotionCf::PageResource.new(blueprint)
  else
    NotionCf::BlockResource.new(blueprint)
  end
end

Instance Method Details

#block?Boolean

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


41
42
43
# File 'lib/notion_cf/resource.rb', line 41

def block?
  raise NotImplementedError
end

#blueprintObject



49
50
51
# File 'lib/notion_cf/resource.rb', line 49

def blueprint
  @blueprint if available_type?
end

#deploy(_client, _parent_id = nil) ⇒ Object

Raises:

  • (NotImplementedError)


45
46
47
# File 'lib/notion_cf/resource.rb', line 45

def deploy(_client, _parent_id = nil)
  raise NotImplementedError
end

#retrieve_additional_information(_client, _blueprints) ⇒ Object

Raises:

  • (NotImplementedError)


53
54
55
# File 'lib/notion_cf/resource.rb', line 53

def retrieve_additional_information(_client, _blueprints)
  raise NotImplementedError
end