Skip to main content

ConfigEnvironment

Trait ConfigEnvironment 

Source
pub trait ConfigEnvironment: Send + Sync {
    // Required methods
    fn unified_config_path(&self) -> Option<PathBuf>;
    fn file_exists(&self, path: &Path) -> bool;
    fn read_file(&self, path: &Path) -> Result<String>;
    fn write_file(&self, path: &Path, content: &str) -> Result<()>;
    fn create_dir_all(&self, path: &Path) -> Result<()>;

    // Provided method
    fn prompt_path(&self) -> PathBuf { ... }
}
Expand description

Trait for configuration environment access.

This trait abstracts all external side effects needed for configuration:

  • Path resolution (which may depend on environment variables)
  • File existence checks
  • File reading and writing
  • Directory creation

By injecting this trait, configuration code becomes pure and testable.

Required Methods§

Source

fn unified_config_path(&self) -> Option<PathBuf>

Get the path to the unified config file.

In production, this returns ~/.config/ralph-workflow.toml or $XDG_CONFIG_HOME/ralph-workflow.toml if the env var is set.

Returns None if the path cannot be determined (e.g., no home directory).

Source

fn file_exists(&self, path: &Path) -> bool

Check if a file exists at the given path.

Source

fn read_file(&self, path: &Path) -> Result<String>

Read the contents of a file.

Source

fn write_file(&self, path: &Path, content: &str) -> Result<()>

Write content to a file, creating parent directories if needed.

Source

fn create_dir_all(&self, path: &Path) -> Result<()>

Create directories recursively.

Provided Methods§

Source

fn prompt_path(&self) -> PathBuf

Get the path to the PROMPT.md file.

In production, this returns ./PROMPT.md (relative to current directory). Tests may override this to use a different path.

Implementors§