Module: Clacky::Media::OutputDir
- Defined in:
- lib/clacky/media/output_dir.rb
Overview
Resolves the on-disk root for generated media files (images, videos, audio) according to a fixed precedence:
1. `param` — explicit `output_dir` from the API caller.
Highest priority; lets a single call land
somewhere specific (e.g. a doc's project root).
2. `configured` — user setting from AgentConfig#media_output_dir.
Set via Settings → Models → Media Output Directory.
3. `fallback` — process default; preserves legacy behavior for
configs that have neither key set.
Pure function on purpose: callers (HTTP handlers) read the configured value off AgentConfig and inject it here. Keeps this helper trivially unit-testable and free of global state.
The final on-disk path is ‘<resolved>/assets/generated/<file>` —the `assets/generated/` suffix is appended by Media::Base#save_* for stable relative-path semantics across markdown / slide outputs, and is intentionally not configurable here.
Class Method Summary collapse
- .first_present(*candidates) ⇒ Object private
-
.resolve(param:, configured:, fallback: Dir.pwd) ⇒ String
Absolute or ‘~`-prefixed path; the caller’s File.join with “assets/generated/” handles ‘~` via the surrounding FileUtils.mkdir_p call only when expanded — for safety we expand `~` here so downstream sees an absolute path.
Class Method Details
.first_present(*candidates) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
38 39 40 |
# File 'lib/clacky/media/output_dir.rb', line 38 def self.first_present(*candidates) candidates.find { |c| c.is_a?(String) && !c.strip.empty? } end |
.resolve(param:, configured:, fallback: Dir.pwd) ⇒ String
Returns absolute or ‘~`-prefixed path; the caller’s File.join with “assets/generated/” handles ‘~` via the surrounding FileUtils.mkdir_p call only when expanded — for safety we expand `~` here so downstream sees an absolute path.
32 33 34 35 |
# File 'lib/clacky/media/output_dir.rb', line 32 def self.resolve(param:, configured:, fallback: Dir.pwd) chosen = first_present(param, configured) || fallback File.(chosen.to_s) end |