Class: OKF::Bundle::Folder
- Inherits:
-
Object
- Object
- OKF::Bundle::Folder
- Defined in:
- lib/okf/bundle/folder.rb
Overview
A bundle on disk — the directory-level handle. Reads a directory into a pure OKF::Bundle once, exposes the analyzers over it, and can materialize an in-memory bundle back to disk. Part of the shell.
folder = OKF::Bundle::Folder.load("docs")
folder.bundle # => OKF::Bundle (pure)
folder.validate; folder.lint; folder.graph
folder.concept("tables/orders") # => OKF::Concept::File (or nil)
# build in memory (the Rails / snapshot-publisher path) and write it out:
OKF::Bundle::Folder.new(bundle: pure_bundle, root: "out/dir").save
Instance Attribute Summary collapse
-
#bundle ⇒ Object
readonly
Returns the value of attribute bundle.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Class Method Summary collapse
Instance Method Summary collapse
- #catalog ⇒ Object
-
#concept(id) ⇒ Object
A single-file handle for one concept id (read live from disk), or nil when no concept in the loaded bundle has that id.
- #concepts ⇒ Object
- #directory_index ⇒ Object
- #graph(minimal: false, body: true) ⇒ Object
-
#initialize(bundle:, root:) ⇒ Folder
constructor
A new instance of Folder.
- #lint(**options) ⇒ Object
-
#name ⇒ Object
Human-readable "parent/dir" name — the default HTML title.
- #reload ⇒ Object
-
#save(overwrite: false) ⇒ Object
Materialize the in-memory bundle to disk (Writer validates §9 before publishing, so a malformed bundle is never written).
- #validate ⇒ Object
Constructor Details
Instance Attribute Details
#bundle ⇒ Object (readonly)
Returns the value of attribute bundle.
17 18 19 |
# File 'lib/okf/bundle/folder.rb', line 17 def bundle @bundle end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
17 18 19 |
# File 'lib/okf/bundle/folder.rb', line 17 def root @root end |
Class Method Details
Instance Method Details
#catalog ⇒ Object
45 46 47 |
# File 'lib/okf/bundle/folder.rb', line 45 def catalog @bundle.catalog end |
#concept(id) ⇒ Object
A single-file handle for one concept id (read live from disk), or nil when no
concept in the loaded bundle has that id. The id may be a frontmatter id, so
it is resolved to a path through the bundle rather than assumed to be "id.md".
62 63 64 65 |
# File 'lib/okf/bundle/folder.rb', line 62 def concept(id) path = @bundle.paths_by_id[id] or return nil Concept::File.read(root: @root, path: path) end |
#concepts ⇒ Object
29 30 31 |
# File 'lib/okf/bundle/folder.rb', line 29 def concepts @bundle.concepts end |
#directory_index ⇒ Object
49 50 51 |
# File 'lib/okf/bundle/folder.rb', line 49 def directory_index @bundle.directory_index end |
#graph(minimal: false, body: true) ⇒ Object
41 42 43 |
# File 'lib/okf/bundle/folder.rb', line 41 def graph(minimal: false, body: true) @bundle.graph(minimal: minimal, body: body) end |
#lint(**options) ⇒ Object
37 38 39 |
# File 'lib/okf/bundle/folder.rb', line 37 def lint(**) @bundle.lint(**) end |
#name ⇒ Object
Human-readable "parent/dir" name — the default HTML title.
54 55 56 57 |
# File 'lib/okf/bundle/folder.rb', line 54 def name pathname = Pathname.new(@root) "#{pathname.parent.basename}/#{pathname.basename}" end |
#reload ⇒ Object
80 81 82 83 |
# File 'lib/okf/bundle/folder.rb', line 80 def reload @bundle = Reader.read(@root) self end |
#save(overwrite: false) ⇒ Object
Materialize the in-memory bundle to disk (Writer validates §9 before publishing, so a malformed bundle is never written).
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/okf/bundle/folder.rb', line 69 def save(overwrite: false) Writer.call( bundle_path: @root, concepts: @bundle.concepts, index_files: reserved_hash("index.md"), log_files: reserved_hash("log.md"), overwrite: overwrite ) self end |
#validate ⇒ Object
33 34 35 |
# File 'lib/okf/bundle/folder.rb', line 33 def validate @bundle.validate end |