Presubmit.Adapter behaviour (presubmit v0.2.2)

Copy Markdown View Source

Behaviour for library-aware adapters that turn a module's facts into a domain model: an Ecto schema's fields, a Phoenix router's routes, a supervisor's children.

Adapters work purely on Presubmit.Source.Facts.Module — the module's uses and body AST — so they recognise conventional shapes, not macro semantics. Each adapter documents the shapes it understands.

Summary

Callbacks

Extracts the model. Only called when recognize?/1 returned true.

Whether this adapter has a model for the module.

Functions

Extracts the model for module if the adapter recognises it.

Callbacks

extract(t)

@callback extract(Presubmit.Source.Facts.Module.t()) :: struct()

Extracts the model. Only called when recognize?/1 returned true.

recognize?(t)

@callback recognize?(Presubmit.Source.Facts.Module.t()) :: boolean()

Whether this adapter has a model for the module.

Functions

model(adapter, module)

@spec model(module(), Presubmit.Source.Facts.Module.t()) :: struct() | nil

Extracts the model for module if the adapter recognises it.