Class: PromptWarden::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/prompt_warden/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



11
12
13
14
15
16
17
18
19
20
# File 'lib/prompt_warden/configuration.rb', line 11

def initialize
  @project_token  = ENV['PROMPT_WARDEN_TOKEN']
  @flush_interval = 1.0
  @batch_bytes    = 256 * 1024
  @max_retries    = 3
  @logger         = defined?(Rails) ? Rails.logger : Logger.new($stdout)
  @api_url        = ENV['PROMPT_WARDEN_API'] || 'https://staging.promptwarden.dev/api/v1/ingest'
  @price_overrides = {}   # e.g., { "gpt-4o" => 0.005 }
  @adapter_blocks  = {}   # lazily‑executed registration procs
end

Instance Attribute Details

#api_urlObject

Returns the value of attribute api_url.



7
8
9
# File 'lib/prompt_warden/configuration.rb', line 7

def api_url
  @api_url
end

#batch_bytesObject

Returns the value of attribute batch_bytes.



7
8
9
# File 'lib/prompt_warden/configuration.rb', line 7

def batch_bytes
  @batch_bytes
end

#flush_intervalObject

Returns the value of attribute flush_interval.



7
8
9
# File 'lib/prompt_warden/configuration.rb', line 7

def flush_interval
  @flush_interval
end

#loggerObject

Returns the value of attribute logger.



7
8
9
# File 'lib/prompt_warden/configuration.rb', line 7

def logger
  @logger
end

#max_retriesObject

Returns the value of attribute max_retries.



7
8
9
# File 'lib/prompt_warden/configuration.rb', line 7

def max_retries
  @max_retries
end

#price_overridesObject

Returns the value of attribute price_overrides.



7
8
9
# File 'lib/prompt_warden/configuration.rb', line 7

def price_overrides
  @price_overrides
end

#project_tokenObject

Returns the value of attribute project_token.



7
8
9
# File 'lib/prompt_warden/configuration.rb', line 7

def project_token
  @project_token
end

Instance Method Details

#register_adapter(key, &block) ⇒ Object

— adapter registration ——————————————- Called by host app for custom SDKs



29
30
31
32
# File 'lib/prompt_warden/configuration.rb', line 29

def register_adapter(key, &block)
  @adapter_blocks[key] = block
  block.call if Gem.loaded_specs.key?(key.to_s) # execute immediately if gem already loaded
end

#run_pending_adaptersObject

Invoked by internal loader after all built‑in auto‑detects



35
36
37
# File 'lib/prompt_warden/configuration.rb', line 35

def run_pending_adapters
  @adapter_blocks.each_value(&:call)
end

#validate!Object

— validation ——————————————————

Raises:

  • (ArgumentError)


23
24
25
# File 'lib/prompt_warden/configuration.rb', line 23

def validate!
  raise ArgumentError, 'project_token is required' if @project_token.to_s.empty?
end