Method: NotionRubyMapping::Base#parent

Defined in:
lib/notion_ruby_mapping/blocks/base.rb

#parent(dry_run: false) ⇒ Object

Parameters:

  • dry_run (Boolean) (defaults to: false)

    true if dry_run

Raises:

  • (StandardError)


295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
# File 'lib/notion_ruby_mapping/blocks/base.rb', line 295

def parent(dry_run: false)
  parent_json = @json && @json["parent"]
  raise StandardError, "Unknown parent" if parent_json.nil?

  type = parent_json["type"]
  klass = case type
          when "data_source_id"
            DataSource
          when "database_id"
            Database
          when "page_id"
            Page
          when "block_id"
            Block
          else
            raise StandardError, "List does not have any parent"
          end
  klass.find parent_json[type], dry_run: dry_run
end