Class: NotionRubyMapping::RelationProperty
- Inherits:
-
MultiProperty
- Object
- Property
- MultiProperty
- NotionRubyMapping::RelationProperty
- Defined in:
- lib/notion_ruby_mapping/properties/relation_property.rb
Overview
MultiSelect property
Constant Summary collapse
- TYPE =
"relation"
Instance Attribute Summary
Attributes inherited from Property
#name, #property_cache, #property_id, #will_update
Instance Method Summary collapse
- #add_relation(page_id_or_json) ⇒ Object
- #database_id ⇒ Object
-
#initialize(name, will_update: false, json: nil, relation: nil, base_type: :page, property_id: nil, property_cache: nil, query: nil) ⇒ RelationProperty
constructor
A new instance of RelationProperty.
-
#property_values_json ⇒ Hash
Created json.
- #relation ⇒ Hash, ...
-
#relation=(page_ids_or_jsons) ⇒ Array
Settled relation Array.
-
#relation_database_id ⇒ String
Relation database_id.
- #replace_relation_database(database_id: nil, type: "dual_property") ⇒ Object
- #synced_property_id ⇒ Object
- #synced_property_name ⇒ Object
- #update_property_schema_json ⇒ Hash
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, #contents?, create_from_json, #database?, #make_filter_query, #new_name=, #page?, #property_schema_json, #remove, #retrieve_page_property, #type, #update_from_json
Constructor Details
#initialize(name, will_update: false, json: nil, relation: nil, base_type: :page, property_id: nil, property_cache: nil, query: nil) ⇒ RelationProperty
Returns a new instance of RelationProperty.
74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/notion_ruby_mapping/properties/relation_property.rb', line 74 def initialize(name, will_update: false, json: nil, relation: nil, base_type: :page, property_id: nil, property_cache: nil, query: nil) super name, will_update: will_update, base_type: base_type, property_id: property_id, property_cache: property_cache, query: query @json = if database? json || {} elsif relation Array(relation).map { |r| {"id" => r} } else json || [] end end |
Instance Method Details
#add_relation(page_id_or_json) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/notion_ruby_mapping/properties/relation_property.rb', line 22 def add_relation(page_id_or_json) assert_page_property __method__ @will_update = true @json << if page_id_or_json.is_a? String {"id" => page_id_or_json} else page_id_or_json end end |
#database_id ⇒ Object
100 101 102 |
# File 'lib/notion_ruby_mapping/properties/relation_property.rb', line 100 def database_id @json["database_id"] end |
#property_values_json ⇒ Hash
Returns created json.
113 114 115 116 117 118 119 120 121 |
# File 'lib/notion_ruby_mapping/properties/relation_property.rb', line 113 def property_values_json assert_page_property __method__ { @name => { "type" => "relation", "relation" => @json, }, } end |
#relation ⇒ Hash, ...
14 15 16 |
# File 'lib/notion_ruby_mapping/properties/relation_property.rb', line 14 def relation @json end |
#relation=(page_ids_or_jsons) ⇒ Array
Returns settled relation Array.
35 36 37 38 39 40 41 42 43 |
# File 'lib/notion_ruby_mapping/properties/relation_property.rb', line 35 def relation=(page_ids_or_jsons) assert_page_property __method__ @will_update = true page_ids_or_jsons = [page_ids_or_jsons] unless page_ids_or_jsons.is_a? Array @json = page_ids_or_jsons.map do |page_id_or_json| page_id_or_json.is_a?(String) ? {"id" => page_id_or_json} : page_id_or_json end end |
#relation_database_id ⇒ String
Returns relation database_id.
49 50 51 52 |
# File 'lib/notion_ruby_mapping/properties/relation_property.rb', line 49 def relation_database_id assert_database_property __method__ @json["database_id"] end |
#replace_relation_database(database_id: nil, type: "dual_property") ⇒ Object
57 58 59 60 61 62 63 64 65 |
# File 'lib/notion_ruby_mapping/properties/relation_property.rb', line 57 def replace_relation_database(database_id: nil, type: "dual_property") assert_database_property __method__ @will_update = true @json["database_id"] = database_id if database_id @json["type"] = type @json[type] = {} @json.delete type == "dual_property" ? "single_property" : "dual_property" @json end |
#synced_property_id ⇒ Object
104 105 106 |
# File 'lib/notion_ruby_mapping/properties/relation_property.rb', line 104 def synced_property_id @json["type"] == "dual_property" ? @json["dual_property"]["synced_property_id"] : nil end |
#synced_property_name ⇒ Object
108 109 110 |
# File 'lib/notion_ruby_mapping/properties/relation_property.rb', line 108 def synced_property_name @json["type"] == "dual_property" ? @json["dual_property"]["synced_property_name"] : nil end |
#update_property_schema_json ⇒ Hash
90 91 92 93 94 95 96 97 98 |
# File 'lib/notion_ruby_mapping/properties/relation_property.rb', line 90 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 |