14
15
16
17
18
19
20
21
22
23
|
# File 'lib/llm_cost_tracker/pricing/sync/registry_writer.rb', line 14
def call(path:, registry:)
FileUtils.mkdir_p(File.dirname(path))
merged = canonicalize(merge_with_existing(path: path, registry: registry))
payload = yaml_file?(path) ? YAML.dump(merged) : "#{JSON.pretty_generate(merged)}\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
|