Class: TrakFlow::Config

Inherits:
Anyway::Config
  • Object
show all
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):

  1. Bundled defaults: lib/trak_flow/config/defaults.yml (ships with gem)

  2. XDG user config: ~/.config/trak_flow/trak_flow.yml

  3. Project config: ./.trak_flow/config.yml

  4. Environment variables (TF_*)

  5. Explicit values passed to configure block

Examples:

Configure with environment variables

export TF_OUTPUT__JSON=true
export TF_DAEMON__AUTO_START=false
export TF_ACTOR=robot

Configure with Ruby block

TrakFlow.configure do |config|
  config.output.json = true
  config.daemon.auto_start = false
end

Constant Summary collapse

DEFAULTS_PATH =

Schema Definition (loaded from defaults.yml - single source of truth)

File.expand_path('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

Instance Method Summary collapse

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, overlay)
  base.merge(overlay) 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

Returns:

  • (Boolean)


117
118
119
# File 'lib/trak_flow/config.rb', line 117

def auto_start_daemon?
  daemon.auto_start
end

#error_policyObject



169
170
171
# File 'lib/trak_flow/config.rb', line 169

def error_policy
  export.error_policy
end

#flush_debounceObject



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_policyObject



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)

Returns:

  • (Boolean)


109
110
111
# File 'lib/trak_flow/config.rb', line 109

def json?
  output.json
end

#max_collision_probObject



149
150
151
# File 'lib/trak_flow/config.rb', line 149

def max_collision_prob
  id.max_collision_prob
end

#max_hash_lengthObject



157
158
159
# File 'lib/trak_flow/config.rb', line 157

def max_hash_length
  id.max_hash_length
end

#min_hash_lengthObject



153
154
155
# File 'lib/trak_flow/config.rb', line 153

def min_hash_length
  id.min_hash_length
end

#no_auto_flush?Boolean

Returns:

  • (Boolean)


125
126
127
# File 'lib/trak_flow/config.rb', line 125

def no_auto_flush?
  !sync.auto_flush
end

#no_auto_import?Boolean

Returns:

  • (Boolean)


129
130
131
# File 'lib/trak_flow/config.rb', line 129

def no_auto_import?
  !sync.auto_import
end

#no_daemon?Boolean

Returns:

  • (Boolean)


113
114
115
# File 'lib/trak_flow/config.rb', line 113

def no_daemon?
  daemon.disabled
end

#no_push?Boolean

Returns:

  • (Boolean)


133
134
135
# File 'lib/trak_flow/config.rb', line 133

def no_push?
  !sync.push
end

#orphan_handlingObject



161
162
163
# File 'lib/trak_flow/config.rb', line 161

def orphan_handling
  import.orphan_handling
end

#require_description?Boolean

Returns:

  • (Boolean)


137
138
139
# File 'lib/trak_flow/config.rb', line 137

def require_description?
  create.require_description
end

#retry_attemptsObject



173
174
175
# File 'lib/trak_flow/config.rb', line 173

def retry_attempts
  export.retry_attempts
end

#retry_backoff_msObject



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

Returns:

  • (Boolean)


181
182
183
# File 'lib/trak_flow/config.rb', line 181

def skip_encoding_errors?
  export.skip_encoding_errors
end

#validation_on_createObject



141
142
143
# File 'lib/trak_flow/config.rb', line 141

def validation_on_create
  validation.on_create
end

#validation_on_syncObject



145
146
147
# File 'lib/trak_flow/config.rb', line 145

def validation_on_sync
  validation.on_sync
end