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
SECTION_KEYS =

Nested section attributes (defined as hashes, converted to ConfigSection)

i[output daemon sync create validation id import export storage database mcp].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



71
72
73
74
75
76
77
78
79
# File 'lib/trak_flow/config.rb', line 71

def self.config_section_with_defaults(section_key)
  defaults = SCHEMA[section_key] || {}
  lambda { |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



81
82
83
84
85
86
87
88
89
# File 'lib/trak_flow/config.rb', line 81

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



107
108
109
# File 'lib/trak_flow/config.rb', line 107

def auto_start_daemon?
  daemon.auto_start
end

#error_policyObject



159
160
161
# File 'lib/trak_flow/config.rb', line 159

def error_policy
  export.error_policy
end

#flush_debounceObject



111
112
113
# File 'lib/trak_flow/config.rb', line 111

def flush_debounce
  daemon.flush_debounce
end

#get(key) ⇒ Object



203
204
205
206
207
208
209
210
211
212
213
214
215
216
# File 'lib/trak_flow/config.rb', line 203

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



155
156
157
# File 'lib/trak_flow/config.rb', line 155

def import_error_policy
  import.error_policy
end

#json?Boolean

==========================================================================

Convenience Accessors (for backward compatibility)



99
100
101
# File 'lib/trak_flow/config.rb', line 99

def json?
  output.json
end

#max_collision_probObject



139
140
141
# File 'lib/trak_flow/config.rb', line 139

def max_collision_prob
  id.max_collision_prob
end

#max_hash_lengthObject



147
148
149
# File 'lib/trak_flow/config.rb', line 147

def max_hash_length
  id.max_hash_length
end

#min_hash_lengthObject



143
144
145
# File 'lib/trak_flow/config.rb', line 143

def min_hash_length
  id.min_hash_length
end

#no_auto_flush?Boolean



115
116
117
# File 'lib/trak_flow/config.rb', line 115

def no_auto_flush?
  !sync.auto_flush
end

#no_auto_import?Boolean



119
120
121
# File 'lib/trak_flow/config.rb', line 119

def no_auto_import?
  !sync.auto_import
end

#no_daemon?Boolean



103
104
105
# File 'lib/trak_flow/config.rb', line 103

def no_daemon?
  daemon.disabled
end

#no_push?Boolean



123
124
125
# File 'lib/trak_flow/config.rb', line 123

def no_push?
  !sync.push
end

#orphan_handlingObject



151
152
153
# File 'lib/trak_flow/config.rb', line 151

def orphan_handling
  import.orphan_handling
end

#require_description?Boolean



127
128
129
# File 'lib/trak_flow/config.rb', line 127

def require_description?
  create.require_description
end

#retry_attemptsObject



163
164
165
# File 'lib/trak_flow/config.rb', line 163

def retry_attempts
  export.retry_attempts
end

#retry_backoff_msObject



167
168
169
# File 'lib/trak_flow/config.rb', line 167

def retry_backoff_ms
  export.retry_backoff_ms
end

#set(key, value) ⇒ Object



218
219
220
221
222
223
224
225
226
227
228
229
# File 'lib/trak_flow/config.rb', line 218

def set(key, value)
  mapping = LEGACY_KEY_MAP[key.to_s]
  return unless mapping

  return unless mapping.is_a?(Array)
  if mapping.length == 1
    send("#{mapping[0]}=", value)
  else
    section = send(mapping[0])
    section.send("#{mapping[1]}=", value)
  end
end

#skip_encoding_errors?Boolean



171
172
173
# File 'lib/trak_flow/config.rb', line 171

def skip_encoding_errors?
  export.skip_encoding_errors
end

#validation_on_createObject



131
132
133
# File 'lib/trak_flow/config.rb', line 131

def validation_on_create
  validation.on_create
end

#validation_on_syncObject



135
136
137
# File 'lib/trak_flow/config.rb', line 135

def validation_on_sync
  validation.on_sync
end