Class: Woods::Obsidian::VaultExporter
- Inherits:
-
Object
- Object
- Woods::Obsidian::VaultExporter
- Defined in:
- lib/woods/obsidian/vault_exporter.rb
Overview
Orchestrates exporting Woods extraction output to a self-contained Obsidian vault.
Reads the flat extraction directory via IndexReader (using raw_graph_data, so string keys + persisted pagerank), then writes:
- one Markdown note per exported unit (NoteBuilder),
- per-type `_index.md` MOCs + a root `_Overview.md`,
- a `_woods/` machine sidecar (id<->path manifest + verbatim graph copies),
- `.obsidian/` config + `Units.base` (only into a woods-owned vault),
- a `.woods-vault` ownership sentinel.
Finally it sweeps stale woods-managed notes — guarded so it can never delete a user's own notes or run against a foreign vault.
All dependency edges come from one in-memory edge_map (the graph's edges/reverse); per-unit JSON is read only for note bodies.
Constant Summary collapse
- MAX_ERRORS =
100- PURGE_GUARD_FRACTION =
0.30- PURGE_GUARD_MIN_DOCS =
10- SENTINEL =
'.woods-vault'- SIDECAR_DIR =
'_woods'- FRAMEWORK_TYPES =
%w[rails_source gem_source].freeze
- MAX_FRONTMATTER_LINES =
Upper bound on frontmatter lines scanned when identifying a managed note during the sweep — our frontmatter is ~12 lines; this just bounds work on a malformed file that opens with "---" but never closes the fence.
200
Instance Method Summary collapse
-
#export_all ⇒ Hash
Generate the full vault.
-
#initialize(index_dir:, vault_path:, config: Woods.configuration, reader: nil, include_source: false, include_framework: false, force_purge: false, output: $stdout) ⇒ VaultExporter
constructor
A new instance of VaultExporter.
Constructor Details
#initialize(index_dir:, vault_path:, config: Woods.configuration, reader: nil, include_source: false, include_framework: false, force_purge: false, output: $stdout) ⇒ VaultExporter
Returns a new instance of VaultExporter.
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/woods/obsidian/vault_exporter.rb', line 57 def initialize(index_dir:, vault_path:, config: Woods.configuration, reader: nil, include_source: false, include_framework: false, force_purge: false, output: $stdout) @config = config @vault = Pathname.new(vault_path.to_s) @reader = reader || build_reader(index_dir) @include_source = include_source @include_framework = include_framework @force_purge = force_purge @output = output end |
Instance Method Details
#export_all ⇒ Hash
Generate the full vault. Idempotent: re-running against an unchanged extraction produces byte-identical output.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/woods/obsidian/vault_exporter.rb', line 72 def export_all graph = @reader.raw_graph_data || {} @nodes = graph['nodes'] || {} @pagerank = graph['pagerank'] || {} analysis = safe_graph_analysis owned = vault_owned_at_start? emitted, skipped = partition_emitted mapper = build_mapper(emitted) edge_map = build_edge_map(emitted.to_set, graph) builder = build_note_builder(mapper, analysis) written = Set.new errors = [] exported = write_notes(emitted, mapper, edge_map, builder, written, errors) indexes = write_indexes(emitted, mapper, written) write_sidecar(emitted, mapper, graph, analysis, written) write_owned_assets(emitted) if owned swept = owned && errors.empty? ? sweep(written) : 0 warn_foreign unless owned { exported: exported, indexes: indexes, swept: swept, skipped: skipped, errors: cap_errors(errors) } end |