Class: NotionRubyMapping::RelationProperty
- Inherits:
-
MultiProperty
- Object
- Property
- MultiProperty
- NotionRubyMapping::RelationProperty
- Defined in:
- lib/notion_ruby_mapping/relation_property.rb
Overview
MultiSelect property
Constant Summary collapse
- TYPE =
"relation"
Instance Attribute Summary
Attributes inherited from Property
Instance Method Summary collapse
-
#initialize(name, will_update: false, json: nil, relation: nil, base_type: :page) ⇒ RelationProperty
constructor
A new instance of RelationProperty.
-
#property_values_json ⇒ Hash
Created json.
- #relation ⇒ Hash, Array
-
#relation=(page_ids) ⇒ Array
Settled relation Array.
-
#relation_database_id ⇒ String
Relation database_id.
- #replace_relation_database(database_id: nil, synced_property_name: nil) ⇒ 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, 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.
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_json ⇒ Hash
Returns 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 |
#relation ⇒ 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.
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_id ⇒ String
Returns 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
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_json ⇒ 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 |