Behaviour for directory-like containers with structural graph organization.
This module defines the structural layer for containers that hold DCATR.Elements
(graphs and nested directories). It provides two callbacks for direct member access
and generates derived and recursive functions for traversal.
Callbacks
graphs/1- direct graph membersdirectories/1- direct directory members
Generated Functions
members/1- all direct elements (graphs/1 ++ directories/1)all_graphs/1- all graphs recursively through sub-directoriesall_members/1- all elements recursively through sub-directoriesfind_graph/2- find a graph by ID recursively
Usage
Modules that use DCATR.Directory.Type get:
@behaviour DCATR.Directory.Typedeclareduse Grax.Schemaincluded- Default implementations of 2 callbacks (operating on
membersfield) - Implementations of 4 generated functions (using polymorphic dispatch)
- All 6 functions are
defoverridable
Override the callbacks when your module uses typed fields instead of members:
@impl DCATR.Directory.Type
def graphs(%_dataset{special_graph: special, other_graphs: graphs}), do: [special | graphs]
@impl DCATR.Directory.Type
def directories(%_dataset{directories: directories}), do: directories || []
Summary
Functions
Returns all Graphs through the entire sub-directory tree.
Returns all Elements through the entire sub-directory tree.
Default implementation of directories/1.
Finds a Graph by ID recursively through the sub-directory tree.
Default implementation of graphs/1.
Returns all direct element members.
Types
@type schema() :: Grax.Schema.t()
@type t() :: module()
Callbacks
@callback directories(container :: schema()) :: [DCATR.Directory.t()]
Returns direct directory members only.
@callback graphs(container :: schema()) :: [DCATR.Graph.t()]
Returns direct graph members only.
Functions
@spec all_graphs(schema()) :: [DCATR.Graph.t()]
Returns all Graphs through the entire sub-directory tree.
Uses polymorphic dispatch to call the correct graphs/1 and directories/1
on each nested container.
@spec all_members(schema()) :: [DCATR.Element.t()]
Returns all Elements through the entire sub-directory tree.
Uses polymorphic dispatch to call the correct members/1 on each nested container.
@spec directories(schema()) :: [DCATR.Directory.t()]
Default implementation of directories/1.
Filters members for Directory instances.
@spec find_graph(schema(), RDF.IRI.coercible()) :: DCATR.Graph.t() | nil
Finds a Graph by ID recursively through the sub-directory tree.
Uses polymorphic dispatch to search through nested containers.
@spec graphs(schema()) :: [DCATR.Graph.t()]
Default implementation of graphs/1.
Filters members for Graph instances.
@spec members(schema()) :: [DCATR.Element.t()]
Returns all direct element members.
Combines graphs/1 and directories/1 via polymorphic dispatch.