Class: LlmCostTracker::Pricing::Sync::RegistryWriter
- Inherits:
-
Object
- Object
- LlmCostTracker::Pricing::Sync::RegistryWriter
- Defined in:
- lib/llm_cost_tracker/pricing/sync/registry_writer.rb
Constant Summary collapse
- YAML_EXTENSIONS =
%w[.yml .yaml].freeze
- MANUAL_SOURCE =
"manual"
Instance Method Summary collapse
Instance Method Details
#call(path:, registry:) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/llm_cost_tracker/pricing/sync/registry_writer.rb', line 15 def call(path:, registry:) payload = render(path: path, registry: registry) FileUtils.mkdir_p(File.dirname(path)) temp_path = "#{path}.tmp-#{Process.pid}-#{Thread.current.object_id}" File.write(temp_path, payload) File.rename(temp_path, path) ensure FileUtils.rm_f(temp_path) if temp_path && File.exist?(temp_path) end |
#render(path:, registry:) ⇒ Object
25 26 27 28 |
# File 'lib/llm_cost_tracker/pricing/sync/registry_writer.rb', line 25 def render(path:, registry:) merged = canonicalize(merge_with_existing(path: path, registry: registry)) yaml_file?(path) ? YAML.dump(merged) : "#{JSON.pretty_generate(merged)}\n" end |