Class: Woods::Notion::Exporter
- Inherits:
-
Object
- Object
- Woods::Notion::Exporter
- Defined in:
- lib/woods/notion/exporter.rb
Overview
Orchestrates syncing Woods extraction data to Notion databases.
Reads extraction output from disk via IndexReader, maps model and column data to Notion page properties, and pushes via the Notion API. All syncs are idempotent —existing pages are updated, new pages are created.
Constant Summary collapse
- MAX_ERRORS =
100
Instance Method Summary collapse
-
#initialize(index_dir:, config: Woods.configuration, client: nil, reader: nil) ⇒ Exporter
constructor
A new instance of Exporter.
-
#sync_all ⇒ Hash
Sync all configured databases.
-
#sync_columns ⇒ Hash
Sync column data to the Columns Notion database.
-
#sync_data_models ⇒ Hash
Sync model units to the Data Models Notion database.
Constructor Details
#initialize(index_dir:, config: Woods.configuration, client: nil, reader: nil) ⇒ Exporter
Returns a new instance of Exporter.
27 28 29 30 31 32 33 34 35 |
# File 'lib/woods/notion/exporter.rb', line 27 def initialize(index_dir:, config: Woods.configuration, client: nil, reader: nil) api_token = config.notion_api_token raise ConfigurationError, 'notion_api_token is required for Notion export' unless api_token @database_ids = config.notion_database_ids || {} @client = client || Client.new(api_token: api_token) @reader = reader || build_reader(index_dir) @page_id_cache = {} end |
Instance Method Details
#sync_all ⇒ Hash
Sync all configured databases. Idempotent — safe to re-run.
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/woods/notion/exporter.rb', line 40 def sync_all model_stats = @database_ids[:data_models] ? sync_data_models : empty_stats column_stats = @database_ids[:columns] && @database_ids[:data_models] ? sync_columns : empty_stats all_errors = model_stats[:errors] + column_stats[:errors] { data_models: model_stats[:synced], columns: column_stats[:synced], errors: cap_errors(all_errors) } end |
#sync_columns ⇒ Hash
Sync column data to the Columns Notion database.
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/woods/notion/exporter.rb', line 71 def sync_columns database_id = @database_ids[:columns] return empty_stats unless database_id synced = 0 errors = [] each_model_unit do |entry, unit_data| synced_count, unit_errors = sync_model_columns(entry, unit_data, database_id) synced += synced_count errors.concat(unit_errors) end { synced: synced, errors: errors } end |
#sync_data_models ⇒ Hash
Sync model units to the Data Models Notion database.
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/woods/notion/exporter.rb', line 56 def sync_data_models database_id = @database_ids[:data_models] return empty_stats unless database_id migration_dates = load_migration_dates sync_units('model', database_id, 'Table Name') do |unit_data| properties = Mappers::ModelMapper.new.map(unit_data) enrich_with_migration_date(properties, migration_dates) properties end end |