Class: TrakFlow::Config
- Inherits:
-
Anyway::Config
- Object
- Anyway::Config
- TrakFlow::Config
- Defined in:
- lib/trak_flow/config.rb
Overview
TrakFlow Configuration using Anyway Config
Schema is defined in lib/trak_flow/config/defaults.yml (single source of truth) Configuration uses nested sections for better organization:
- TrakFlow.config.output.json
- TrakFlow.config.daemon.auto_start
- TrakFlow.config.export.error_policy
Configuration sources (lowest to highest priority):
-
Bundled defaults: lib/trak_flow/config/defaults.yml (ships with gem)
-
XDG user config: ~/.config/trak_flow/trak_flow.yml
-
Project config: ./.trak_flow/config.yml
-
Environment variables (TF_*)
-
Explicit values passed to configure block
Constant Summary collapse
- DEFAULTS_PATH =
Schema Definition (loaded from defaults.yml - single source of truth)
File.('config/defaults.yml', __dir__).freeze
- LEGACY_KEY_MAP =
Legacy API Support (for backward compatibility)
{ 'json' => %i[output json], 'stealth' => %i[output stealth], 'no_daemon' => %i[daemon disabled], 'no_auto_flush' => %i[sync auto_flush], 'no_auto_import' => %i[sync auto_import], 'no_push' => %i[sync push], 'create.require_description' => %i[create require_description], 'validation.on_create' => %i[validation on_create], 'validation.on_sync' => %i[validation on_sync], 'flush_debounce' => %i[daemon flush_debounce], 'auto_start_daemon' => %i[daemon auto_start], 'max_collision_prob' => %i[id max_collision_prob], 'min_hash_length' => %i[id min_hash_length], 'max_hash_length' => %i[id max_hash_length], 'import.orphan_handling' => %i[import orphan_handling], 'import.error_policy' => %i[import error_policy], 'export.error_policy' => %i[export error_policy], 'export.retry_attempts' => %i[export retry_attempts], 'export.retry_backoff_ms' => %i[export retry_backoff_ms], 'export.skip_encoding_errors' => %i[export skip_encoding_errors], 'actor' => [:actor] }.freeze
Class Method Summary collapse
-
.config_section_with_defaults(section_key) ⇒ Object
Type Coercion ==========================================================================.
- .deep_merge_hashes(base, overlay) ⇒ Object
Instance Method Summary collapse
- #auto_start_daemon? ⇒ Boolean
- #error_policy ⇒ Object
- #flush_debounce ⇒ Object
- #get(key) ⇒ Object
- #import_error_policy ⇒ Object
-
#json? ⇒ Boolean
Convenience Accessors (for backward compatibility) ==========================================================================.
- #max_collision_prob ⇒ Object
- #max_hash_length ⇒ Object
- #min_hash_length ⇒ Object
- #no_auto_flush? ⇒ Boolean
- #no_auto_import? ⇒ Boolean
- #no_daemon? ⇒ Boolean
- #no_push? ⇒ Boolean
- #orphan_handling ⇒ Object
- #require_description? ⇒ Boolean
- #retry_attempts ⇒ Object
- #retry_backoff_ms ⇒ Object
- #set(key, value) ⇒ Object
- #skip_encoding_errors? ⇒ Boolean
- #validation_on_create ⇒ Object
- #validation_on_sync ⇒ Object
Class Method Details
.config_section_with_defaults(section_key) ⇒ Object
Type Coercion
69 70 71 72 73 74 75 76 77 |
# File 'lib/trak_flow/config.rb', line 69 def self.config_section_with_defaults(section_key) defaults = SCHEMA[section_key] || {} ->(v) { return v if v.is_a?(ConfigSection) incoming = v || {} merged = deep_merge_hashes(defaults.dup, incoming) ConfigSection.new(merged) } end |
.deep_merge_hashes(base, overlay) ⇒ Object
79 80 81 82 83 84 85 86 87 |
# File 'lib/trak_flow/config.rb', line 79 def self.deep_merge_hashes(base, ) base.merge() do |_key, old_val, new_val| if old_val.is_a?(Hash) && new_val.is_a?(Hash) deep_merge_hashes(old_val, new_val) else new_val.nil? ? old_val : new_val end end end |
Instance Method Details
#auto_start_daemon? ⇒ Boolean
117 118 119 |
# File 'lib/trak_flow/config.rb', line 117 def auto_start_daemon? daemon.auto_start end |
#error_policy ⇒ Object
169 170 171 |
# File 'lib/trak_flow/config.rb', line 169 def error_policy export.error_policy end |
#flush_debounce ⇒ Object
121 122 123 |
# File 'lib/trak_flow/config.rb', line 121 def flush_debounce daemon.flush_debounce end |
#get(key) ⇒ Object
213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/trak_flow/config.rb', line 213 def get(key) mapping = LEGACY_KEY_MAP[key.to_s] return nil unless mapping if mapping.is_a?(Array) value = self mapping.each { |k| value = value.respond_to?(k) ? value.send(k) : value[k] } value elsif mapping.is_a?(Proc) nil else send(mapping) end end |
#import_error_policy ⇒ Object
165 166 167 |
# File 'lib/trak_flow/config.rb', line 165 def import_error_policy import.error_policy end |
#json? ⇒ Boolean
Convenience Accessors (for backward compatibility)
109 110 111 |
# File 'lib/trak_flow/config.rb', line 109 def json? output.json end |
#max_collision_prob ⇒ Object
149 150 151 |
# File 'lib/trak_flow/config.rb', line 149 def max_collision_prob id.max_collision_prob end |
#max_hash_length ⇒ Object
157 158 159 |
# File 'lib/trak_flow/config.rb', line 157 def max_hash_length id.max_hash_length end |
#min_hash_length ⇒ Object
153 154 155 |
# File 'lib/trak_flow/config.rb', line 153 def min_hash_length id.min_hash_length end |
#no_auto_flush? ⇒ Boolean
125 126 127 |
# File 'lib/trak_flow/config.rb', line 125 def no_auto_flush? !sync.auto_flush end |
#no_auto_import? ⇒ Boolean
129 130 131 |
# File 'lib/trak_flow/config.rb', line 129 def no_auto_import? !sync.auto_import end |
#no_daemon? ⇒ Boolean
113 114 115 |
# File 'lib/trak_flow/config.rb', line 113 def no_daemon? daemon.disabled end |
#no_push? ⇒ Boolean
133 134 135 |
# File 'lib/trak_flow/config.rb', line 133 def no_push? !sync.push end |
#orphan_handling ⇒ Object
161 162 163 |
# File 'lib/trak_flow/config.rb', line 161 def orphan_handling import.orphan_handling end |
#require_description? ⇒ Boolean
137 138 139 |
# File 'lib/trak_flow/config.rb', line 137 def require_description? create.require_description end |
#retry_attempts ⇒ Object
173 174 175 |
# File 'lib/trak_flow/config.rb', line 173 def retry_attempts export.retry_attempts end |
#retry_backoff_ms ⇒ Object
177 178 179 |
# File 'lib/trak_flow/config.rb', line 177 def retry_backoff_ms export.retry_backoff_ms end |
#set(key, value) ⇒ Object
228 229 230 231 232 233 234 235 236 237 238 239 240 |
# File 'lib/trak_flow/config.rb', line 228 def set(key, value) mapping = LEGACY_KEY_MAP[key.to_s] return unless mapping if mapping.is_a?(Array) if mapping.length == 1 send("#{mapping[0]}=", value) else section = send(mapping[0]) section.send("#{mapping[1]}=", value) end end end |
#skip_encoding_errors? ⇒ Boolean
181 182 183 |
# File 'lib/trak_flow/config.rb', line 181 def skip_encoding_errors? export.skip_encoding_errors end |
#validation_on_create ⇒ Object
141 142 143 |
# File 'lib/trak_flow/config.rb', line 141 def validation_on_create validation.on_create end |
#validation_on_sync ⇒ Object
145 146 147 |
# File 'lib/trak_flow/config.rb', line 145 def validation_on_sync validation.on_sync end |