Module substitution

Module substitution 

Source
Expand description

Variable substitution engine for hooks

This module provides variable substitution functionality for hook actions. It supports placeholder parsing, variable lookup in event context, and nested paths.

§Examples

Basic variable substitution:

use ricecoder_hooks::executor::VariableSubstitutor;
use ricecoder_hooks::types::EventContext;
use serde_json::json;

let context = EventContext {
    data: json!({
        "file_path": "/path/to/file.rs",
        "size": 1024,
    }),
    metadata: json!({}),
};

let template = "Processing {{file_path}} ({{size}} bytes)";
let result = VariableSubstitutor::substitute(template, &context)?;
assert_eq!(result, "Processing /path/to/file.rs (1024 bytes)");

Nested path substitution:

let context = EventContext {
    data: json!({
        "metadata": {
            "size": 2048,
            "hash": "abc123",
        }
    }),
    metadata: json!({}),
};

let template = "File size: {{metadata.size}}, hash: {{metadata.hash}}";
let result = VariableSubstitutor::substitute(template, &context)?;
assert_eq!(result, "File size: 2048, hash: abc123");

Structs§

VariableSubstitutor
Variable substitution engine