Class: NotionRubyMapping::RelationProperty

Inherits:
MultiProperty show all
Defined in:
lib/notion_ruby_mapping/relation_property.rb

Overview

MultiSelect property

Constant Summary collapse

TYPE =
"relation"

Instance Attribute Summary

Attributes inherited from Property

#name, #will_update

Instance Method Summary collapse

Methods included from IsEmptyIsNotEmpty

#filter_is_empty, #filter_is_not_empty

Methods included from ContainsDoesNotContain

#filter_contains, #filter_does_not_contain

Methods inherited from Property

#assert_database_property, #assert_page_property, #clear_will_update, create_from_json, #database?, #make_filter_query, #new_name=, #page?, #property_schema_json, #remove, #type, #update_from_json

Constructor Details

#initialize(name, will_update: false, json: nil, relation: nil, base_type: :page) ⇒ RelationProperty

Returns a new instance of RelationProperty.

Parameters:

  • name (String)
  • json (Hash, Array) (defaults to: nil)
  • relation (String, Array) (defaults to: nil)


42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/notion_ruby_mapping/relation_property.rb', line 42

def initialize(name, will_update: false, json: nil, relation: nil, base_type: :page)
  super name, will_update: will_update, base_type: base_type
  @json = if database?
            json || {}
          elsif relation
            Array(relation).map { |r| {"id" => r} }
          elsif json
            json
          else
            []
          end
end

Instance Method Details

#property_values_jsonHash

Returns created json.

Returns:

  • (Hash)

    created json



79
80
81
82
83
84
85
86
87
# File 'lib/notion_ruby_mapping/relation_property.rb', line 79

def property_values_json
  assert_page_property __method__
  {
    @name => {
      "type" => "relation",
      "relation" => @json,
    },
  }
end

#relationHash, Array

Returns:

  • (Hash, Array)


13
14
15
# File 'lib/notion_ruby_mapping/relation_property.rb', line 13

def relation
  @json
end

#relation=(page_ids) ⇒ Array

Returns settled relation Array.

Parameters:

  • relation (String, Array<String>)

    a id or Array of id

Returns:

  • (Array)

    settled relation Array



72
73
74
75
76
# File 'lib/notion_ruby_mapping/relation_property.rb', line 72

def relation=(page_ids)
  assert_page_property __method__
  @will_update = true
  @json = Array(page_ids).map { |r| {"id" => r} }
end

#relation_database_idString

Returns relation database_id.

Returns:

  • (String)

    relation database_id



20
21
22
23
# File 'lib/notion_ruby_mapping/relation_property.rb', line 20

def relation_database_id
  assert_database_property __method__
  @json["database_id"]
end

#replace_relation_database(database_id: nil, synced_property_name: nil) ⇒ Object

Parameters:

  • database_id (String) (defaults to: nil)
  • synced_property_name (String) (defaults to: nil)


27
28
29
30
31
32
33
# File 'lib/notion_ruby_mapping/relation_property.rb', line 27

def replace_relation_database(database_id: nil, synced_property_name: nil)
  assert_database_property __method__
  @will_update = true
  @json["database_id"] = database_id if database_id
  @json["synced_property_name"] = synced_property_name if synced_property_name
  @json
end

#update_property_schema_jsonHash

Returns:

  • (Hash)


58
59
60
61
62
63
64
65
66
# File 'lib/notion_ruby_mapping/relation_property.rb', line 58

def update_property_schema_json
  assert_database_property __method__
  ans = super
  return ans if ans != {} || !@will_update

  ans[@name] ||= {}
  ans[@name]["relation"] = @json
  ans
end