AshBaml.CodeWriter (ash_baml v0.2.0)

View Source

Handles writing and formatting generated Elixir code files.

Summary

Functions

Ensures a .gitkeep or README exists in the types directory.

Converts a module name to a file path.

Writes a module definition to a file.

Functions

ensure_types_directory(types_dir)

Ensures a .gitkeep or README exists in the types directory.

Returns

  • :ok on success
  • {:error, reason} on failure

module_to_path(module_name, base_path)

Converts a module name to a file path.

Example: MyApp.BamlClient.Types.Foo -> "lib/my_app/baml_client/types/foo.ex"

write_module(module_name, module_code, base_path)

Writes a module definition to a file.

Parameters

  • module_name - Full module name (e.g., MyApp.Types.Foo)
  • module_code - String containing the module definition
  • base_path - Base directory for output (e.g., "lib")

Returns

  • {:ok, file_path} on success
  • {:error, reason} on failure