JsonRemedy.LayerBehaviour behaviour (json_remedy v0.1.3)

View Source

Defines the contract that all repair layers must implement.

Each layer is responsible for one specific type of repair concern and should be composable with other layers in the pipeline.

Summary

Callbacks

Return a human-readable name for this layer. Used in logging and debugging.

Return the priority order for this layer (lower = earlier). Used to determine layer execution order.

Process input string and apply layer-specific repairs.

Check if this layer can handle the given input. Used for optimization and layer selection.

Validate layer configuration and options. Called during pipeline setup.

Functions

Check if a position in the input is inside a string literal. Used to avoid applying repairs to string content.

Types

layer_result()

@type layer_result() ::
  {:ok, String.t(), repair_context()}
  | {:continue, String.t(), repair_context()}
  | {:error, String.t()}

repair_action()

@type repair_action() :: %{
  layer: atom(),
  action: String.t(),
  position: non_neg_integer() | nil,
  original: String.t() | nil,
  replacement: String.t() | nil
}

repair_context()

@type repair_context() :: %{
  repairs: [repair_action()],
  options: keyword(),
  metadata: map()
}

Callbacks

name()

@callback name() :: String.t()

Return a human-readable name for this layer. Used in logging and debugging.

priority()

@callback priority() :: non_neg_integer()

Return the priority order for this layer (lower = earlier). Used to determine layer execution order.

process(input, context)

@callback process(input :: String.t(), context :: repair_context()) :: layer_result()

Process input string and apply layer-specific repairs.

Returns:

  • {:ok, processed_input, updated_context} - Layer completed successfully
  • {:continue, input, context} - Layer doesn't apply, pass to next layer
  • {:error, reason} - Layer failed, stop pipeline

supports?(input)

@callback supports?(input :: String.t()) :: boolean()

Check if this layer can handle the given input. Used for optimization and layer selection.

validate_options(options)

(optional)
@callback validate_options(options :: keyword()) :: :ok | {:error, String.t()}

Validate layer configuration and options. Called during pipeline setup.

Functions

inside_string?(input, position)

@spec inside_string?(input :: String.t(), position :: non_neg_integer()) :: boolean()

Check if a position in the input is inside a string literal. Used to avoid applying repairs to string content.