Class: LlmCostTracker::PriceSync::RegistryWriter
- Inherits:
-
Object
- Object
- LlmCostTracker::PriceSync::RegistryWriter
- Defined in:
- lib/llm_cost_tracker/price_sync/registry_writer.rb
Constant Summary collapse
- YAML_EXTENSIONS =
%w[.yml .yaml].freeze
Instance Method Summary collapse
Instance Method Details
#call(path:, registry:) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/llm_cost_tracker/price_sync/registry_writer.rb', line 12 def call(path:, registry:) FileUtils.mkdir_p(File.dirname(path)) payload = yaml_file?(path) ? YAML.dump(registry) : "#{JSON.pretty_generate(registry)}\n" 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 |