Class: Woods::Notion::Mappers::ColumnMapper

Inherits:
Object
  • Object
show all
Includes:
Shared
Defined in:
lib/woods/notion/mappers/column_mapper.rb

Overview

Maps individual column metadata to Notion page properties for the Columns database.

Each column from a model’s metadata becomes a separate Notion page, optionally linked to its parent Data Models page via a relation property.

Examples:

mapper = ColumnMapper.new
properties = mapper.map(column, model_identifier: "User", validations: [...], parent_page_id: "page-123")

Constant Summary

Constants included from Shared

Shared::MAX_RICH_TEXT_LENGTH

Instance Method Summary collapse

Methods included from Shared

#rich_text_property

Instance Method Details

#map(column, model_identifier: nil, validations: [], parent_page_id: nil) ⇒ Hash

Map a single column to Notion Columns page properties.

Parameters:

  • column (Hash)

    Column hash from metadata (name, type, null, default)

  • model_identifier (String) (defaults to: nil)

    Parent model name (for context)

  • validations (Array<Hash>) (defaults to: [])

    Model-level validations to match against this column

  • parent_page_id (String, nil) (defaults to: nil)

    Notion page ID of the Data Models parent page

Returns:

  • (Hash)

    Notion page properties hash



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/woods/notion/mappers/column_mapper.rb', line 27

def map(column, model_identifier: nil, validations: [], parent_page_id: nil) # rubocop:disable Lint/UnusedMethodArgument
  properties = {
    'Column Name' => { title: [{ text: { content: column['name'] } }] },
    'Data Type' => { select: { name: column['type'] } },
    'Nullable' => { checkbox: column['null'] == true },
    'Default Value' => rich_text_property(column['default'].to_s),
    'Validation Rules' => rich_text_property(format_validation_rules(column['name'], validations))
  }

  properties['Table'] = { relation: [{ id: parent_page_id }] } if parent_page_id

  properties
end