Class: AnalyticsOps::Configuration::Writer
- Inherits:
-
Object
- Object
- AnalyticsOps::Configuration::Writer
- Defined in:
- lib/analytics_ops/configuration/writer.rb,
sig/analytics_ops.rbs
Overview
Safely creates the smallest valid configuration after interactive setup.
Defined Under Namespace
Classes: Result
Instance Method Summary collapse
Instance Method Details
#write_minimal(path, profile:, property_id:) ⇒ Result
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/analytics_ops/configuration/writer.rb', line 44 def write_minimal(path, profile:, property_id:) state = validated_state(profile, property_id) = File.(path) return existing_result(File.realpath(), state) if File.exist?() FileUtils.mkdir_p(File.dirname()) temporary = temporary_path() File.open(temporary, File::WRONLY | File::CREAT | File::EXCL, 0o644) do |file| file.write(document(state)) file.flush file.fsync end begin File.link(temporary, ) rescue Errno::EEXIST raise ConfigurationError, "Configuration #{Redaction.(path)} was created by another process" end Result.new(path: , created: true) rescue AnalyticsOps::Error raise rescue SystemCallError => error raise ConfigurationError, "Cannot write configuration #{Redaction.(path)}: #{Redaction.(error.)}" ensure File.unlink(temporary) if temporary && File.exist?(temporary) end |