Behavior for modules that create and update lenses.
Lensmakers are plugins that can create new lenses or enhance existing ones created by other lensmakers. This allows for a composable system where extensions can add functionality to base lenses.
Example
defmodule MyApp.SecurityLensmaker do
@behaviour Clarity.Perspective.Lensmaker
alias Clarity.Graph.Filter
alias Clarity.Perspective.Lens
@impl Clarity.Perspective.Lensmaker
def make_lens do
%Lens{
id: "security",
name: "Security Audit",
description: "Focus on security-related vertices",
icon: fn -> ~H"🛡️" end,
filter: Filter.vertex_type([Auth.Module, Permission.Module])
}
end
endExtension Example
defmodule MyApp.SecurityReportExtension do
@behaviour Clarity.Perspective.Lensmaker
@impl Clarity.Perspective.Lensmaker
def update_lens(%{id: "security"} = lens) do
# Example: Could modify the lens's content sorter or other properties
lens
end
def update_lens(lens), do: lens
endConfiguration
Register lensmakers in your application configuration:
config :my_app, :clarity_perspective_lensmakers, [
MyApp.SecurityLensmaker,
MyApp.SecurityReportExtension
]Two-Phase Lens Creation
- Creation Phase: Calls
make_lens/0on lensmakers that implement it - Enhancement Phase: Calls
update_lens/1on all lensmakers for each lens
This allows extensions to enhance base lenses created by other modules.
Summary
Callbacks
Creates a new lens.
Updates an existing lens, potentially enhancing it with additional functionality.
Types
Callbacks
@callback make_lens() :: Clarity.Perspective.Lens.t()
Creates a new lens.
@callback update_lens(lens :: Clarity.Perspective.Lens.t()) :: Clarity.Perspective.Lens.t()
Updates an existing lens, potentially enhancing it with additional functionality.
Extensions typically check the lens ID and only modify lenses they are designed to enhance.