Class: NotionRubyMapping::PropertyCache
- Inherits:
-
Object
- Object
- NotionRubyMapping::PropertyCache
- Includes:
- Enumerable
- Defined in:
- lib/notion_ruby_mapping/property_cache.rb
Overview
PropertyCache class
Instance Attribute Summary collapse
-
#json ⇒ Object
writeonly
Sets the attribute json.
Instance Method Summary collapse
-
#[](key) ⇒ Property
Property for key.
- #add_property(property) ⇒ Object
- #clear_will_update ⇒ Object
- #each(&block) ⇒ Hash, Enumerator
- #generate_all_properties ⇒ Object
-
#initialize(json = {}, base_type: :page) ⇒ PropertyCache
constructor
A new instance of PropertyCache.
-
#property_schema_json ⇒ Hash
Created property schema json.
-
#property_values_json ⇒ Hash
Created property values json.
-
#update_property_schema_json ⇒ Hash
Created update property schema json.
- #values_at(*key) ⇒ Array
Constructor Details
#initialize(json = {}, base_type: :page) ⇒ PropertyCache
7 8 9 10 11 |
# File 'lib/notion_ruby_mapping/property_cache.rb', line 7 def initialize(json = {}, base_type: :page) @properties = {} @json = json @base_type = base_type end |
Instance Attribute Details
#json=(value) ⇒ Object (writeonly)
Sets the attribute json
12 13 14 |
# File 'lib/notion_ruby_mapping/property_cache.rb', line 12 def json=(value) @json = value end |
Instance Method Details
#[](key) ⇒ Property
16 17 18 |
# File 'lib/notion_ruby_mapping/property_cache.rb', line 16 def [](key) @properties[key] ||= Property.create_from_json key, @json[key], @base_type end |
#add_property(property) ⇒ Object
43 44 45 46 |
# File 'lib/notion_ruby_mapping/property_cache.rb', line 43 def add_property(property) @properties[property.name] = property self end |
#clear_will_update ⇒ Object
49 50 51 52 53 |
# File 'lib/notion_ruby_mapping/property_cache.rb', line 49 def clear_will_update @properties.each do |_, property| property.clear_will_update end end |
#each(&block) ⇒ Hash, Enumerator
36 37 38 39 40 |
# File 'lib/notion_ruby_mapping/property_cache.rb', line 36 def each(&block) return enum_for(:each) unless block_given? generate_all_properties.each(&block) end |
#generate_all_properties ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/notion_ruby_mapping/property_cache.rb', line 27 def generate_all_properties if @json.empty? @properties.values else @json.keys.map { |key| self[key] } end end |
#property_schema_json ⇒ Hash
66 67 68 69 70 71 72 73 |
# File 'lib/notion_ruby_mapping/property_cache.rb', line 66 def property_schema_json @properties.each_with_object({}) do |(_, property), ans| if property.will_update ans["properties"] ||= {} ans["properties"].merge! property.property_schema_json end end end |
#property_values_json ⇒ Hash
56 57 58 59 60 61 62 63 |
# File 'lib/notion_ruby_mapping/property_cache.rb', line 56 def property_values_json @properties.each_with_object({}) do |(_, property), ans| if property.will_update ans["properties"] ||= {} ans["properties"].merge! property.property_values_json end end end |
#update_property_schema_json ⇒ Hash
76 77 78 79 80 81 82 83 |
# File 'lib/notion_ruby_mapping/property_cache.rb', line 76 def update_property_schema_json @properties.each_with_object({}) do |(_, property), ans| if property.will_update ans["properties"] ||= {} ans["properties"].merge! property.update_property_schema_json end end end |
#values_at(*key) ⇒ Array
22 23 24 25 |
# File 'lib/notion_ruby_mapping/property_cache.rb', line 22 def values_at(*key) generate_all_properties @properties.values_at(*key) end |