Fact.Seam (Fact v0.2.0)
View SourceThis module is the foundation for building flexible, versioned, and configurable components throughout the Fact system, providing consistency and reducing boilerplate.
Fact.Seam defines a standard interface and default implementation for modules
that expose configurable components, providing:
- Identification:
id/0,family/0, andversion/0to uniquely identify implementations. - Options management: mechanisms to define default options, validate user-provided options, normalize options, and prepare them for internal use.
- Meta-programming helpers: a
__using__/1macro to easily inject behaviour and standard implementation into other modules.
Key Features
Behaviour Definition Modules that
use Fact.Seammust implement:id/0– returns a{family, version}tuplefamily/0– the component familyversion/0– numeric version of the componentdefault_options/0– default configuration optionsinit/1– initializes the module with validated optionsnormalize_options/1– normalizes and validates a given options mapoption_specs/0– specifications for each option including parsing and allowed valuesprepare_options/1– prepares the validated options for struct creation
Option Validation Validates options against a provided
option_specs/0map, applying parsing functions, checking allowed values, and returning detailed errors for unknown or invalid options.Struct Initialization Automatically merges user-provided options with defaults, validates them, and constructs a struct for the module.
Meta-programming Convenience Injects default implementations for behaviours via the
__using__/1macro, allowing modules to focus on implementing only unique functionality.