DCATR.Manifest.LoadPath (DCAT-R.ex v0.1.0)

Copy Markdown View Source

File discovery and classification for DCATR.Manifest loading.

Provides hierarchical file resolution with environment-aware overrides and pattern-based classification for graph assignment.

Summary

Functions

Classifies a manifest file path to determine which manifest graph it belongs to.

Resolves the load path into concrete RDF files, with environment-aware ordering.

Returns the configured load path.

Types

t()

@type t() :: [String.t()]

Functions

classify_file(path)

@spec classify_file(String.t()) :: :service_manifest | :repository_manifest | nil

Classifies a manifest file path to determine which manifest graph it belongs to.

Returns :service_manifest, :repository_manifest, or nil (unclassified).

Classification Rules

Files are classified based on their path patterns:

  • Service manifest files:

    • service.(env).(ext) - Environment-specific service files
    • /service.(ext) - Base service file
    • /service/*.(ext) - Any file in a service/ directory
  • Repository manifest files:

    • repository.(env).(ext) - Environment-specific repository files
    • /repository.(ext) - Base repository file
    • dataset.(env).(ext) - Environment-specific dataset files
    • /dataset.(ext) - Base dataset file
    • /repository/*.(ext) - Any file in a repository/ directory

Where (env) is one of the DCATR.Manifest.environments/0 values and (ext) is any supported RDF serialization format extension.

Filename patterns take precedence over directory patterns, so repository/service.ttl is classified as :service_manifest (not :repository_manifest).

Examples

iex> DCATR.Manifest.LoadPath.classify_file("config/dcatr/service.ttl")
:service_manifest

iex> DCATR.Manifest.LoadPath.classify_file("config/dcatr/service.dev.ttl")
:service_manifest

iex> DCATR.Manifest.LoadPath.classify_file("config/dcatr/service/middleware.ttl")
:service_manifest

iex> DCATR.Manifest.LoadPath.classify_file("config/dcatr/repository.ttl")
:repository_manifest

iex> DCATR.Manifest.LoadPath.classify_file("config/dcatr/dataset.ttl")
:repository_manifest

iex> DCATR.Manifest.LoadPath.classify_file("config/dcatr/agent.ttl")
nil

files(opts \\ [])

@spec files(keyword()) :: t()

Resolves the load path into concrete RDF files, with environment-aware ordering.

Only files with RDF serialization format extensions recognized by RDF.Serialization are included, in particular: .ttl, .trig, .jsonld, .nt, .nq, .rdf.

File Ordering

Files are returned in load order to ensure proper precedence during dataset merging via RDF.Dataset.put_properties/2:

  1. Per load path directory: General files before environment-specific files
  2. Across load paths: Files from earlier paths before files from later paths

Within each directory, environment-specific files can use two patterns:

  • Directory-based: dev/service.ttl, prod/service.ttl
  • Suffix-based: service.dev.ttl, service.prod.ttl

Environment-specific files are loaded after general files within the same directory, but this precedence does not apply across different load path directories.

Ignored Files

Files starting with _ (underscore) are ignored, as are non-existent paths. Duplicates across multiple load paths are removed via Enum.uniq/1.

Options

  • :env - The environment to use (defaults to Mix.env())
  • :load_path - Override the configured load path (see load_path/1)

load_path(opts \\ [])

@spec load_path(keyword()) :: t()

Returns the configured load path.

By default, the load path is config/dcatr, but can be configured with the :load_path option of the :dcatr application:

config :dcatr, load_path: ["custom/path"]