Class: Togul::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/togul/config.rb

Constant Summary collapse

DEFAULT_BASE_URL =
'https://api.togul.io'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(environment:, api_key: '', timeout: 5, cache_ttl: 30, fallback_mode: :fail_closed, retry_count: 2, base_url: nil) ⇒ Config

Returns a new instance of Config.

Parameters:

  • environment (String)

    Environment key (e.g. “production”)

  • api_key (String) (defaults to: '')

    Environment API key for evaluate/stream requests

  • timeout (Numeric) (defaults to: 5)

    HTTP timeout in seconds

  • cache_ttl (Integer) (defaults to: 30)

    Cache TTL in seconds

  • fallback_mode (Symbol) (defaults to: :fail_closed)

    :fail_closed or :fail_open

  • retry_count (Integer) (defaults to: 2)

    Number of retry attempts

  • base_url (String, nil) (defaults to: nil)

    Override default base URL (optional)



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/togul/config.rb', line 16

def initialize(
  environment:,
  api_key: '',
  timeout: 5,
  cache_ttl: 30,
  fallback_mode: :fail_closed,
  retry_count: 2,
  base_url: nil
)
  @base_url = base_url&.chomp('/') || DEFAULT_BASE_URL
  @api_key = api_key
  @environment = environment
  @timeout = timeout
  @cache_ttl = cache_ttl
  @fallback_mode = fallback_mode
  @retry_count = retry_count
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



7
8
9
# File 'lib/togul/config.rb', line 7

def api_key
  @api_key
end

#base_urlObject (readonly)

Returns the value of attribute base_url.



7
8
9
# File 'lib/togul/config.rb', line 7

def base_url
  @base_url
end

#cache_ttlObject (readonly)

Returns the value of attribute cache_ttl.



7
8
9
# File 'lib/togul/config.rb', line 7

def cache_ttl
  @cache_ttl
end

#environmentObject (readonly)

Returns the value of attribute environment.



7
8
9
# File 'lib/togul/config.rb', line 7

def environment
  @environment
end

#fallback_modeObject (readonly)

Returns the value of attribute fallback_mode.



7
8
9
# File 'lib/togul/config.rb', line 7

def fallback_mode
  @fallback_mode
end

#retry_countObject (readonly)

Returns the value of attribute retry_count.



7
8
9
# File 'lib/togul/config.rb', line 7

def retry_count
  @retry_count
end

#timeoutObject (readonly)

Returns the value of attribute timeout.



7
8
9
# File 'lib/togul/config.rb', line 7

def timeout
  @timeout
end