Module: Tangle::Mixin::Directory
- Defined in:
- lib/tangle/mixin/directory.rb
Overview
Tangle mixin for loading a directory structure as a graph
Graph.new(directory: { options })
options are:
root: root directory for the structure (mandatory)
loaders: list of object loader lambdas (mandatory)
->(graph, **) { ... } => finished?
follow_links: bool for following symlinks to directories
exclude_root: bool for excluding the root directory
All bool options default to false.
A loader lambda is called with the graph as only positional argument, and a number of keyword arguments:
path: Path of current filesystem object
parent: Path of filesystem parent object
lstat: File.lstat for path
stat: File.stat for path, if lstat.symlink?
The lambdas are called in order until one returns true.
Example:
loader = lambda do |g, path:, parent:, lstat:, **|
vertex = kwargs[:lstat]
g.add_vertex(vertex, name: path)
g.add_edge(g[parent], vertex) unless parent.nil?
end
Tangle::DiGraph.new(mixins: [Tangle::Mixins::Directory],
directory: { root: '.', loaders: [loader] })
Defined Under Namespace
Modules: Graph