Class: LaunchDarkly::Config

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

Overview

This class exposes advanced configuration options for the LaunchDarkly client library. Most users will not need to use a custom configuration– the default configuration sets sane defaults for most use cases.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ type

Constructor for creating custom LaunchDarkly configurations.

Parameters:

  • (defaults to: {})

    the configuration options

Options Hash (opts):

  • :logger (Logger)

    A logger to use for messages from the LaunchDarkly client. Defaults to the Rails logger in a Rails environment, or stdout otherwise.

  • :base_uri (String) — default: "https://app.launchdarkly.com"

    The base URL for the LaunchDarkly server. Most users should use the default value.

  • :capacity (Integer) — default: 10000

    The capacity of the events buffer. The client buffers up to this many events in memory before flushing. If the capacity is exceeded before the buffer is flushed, events will be discarded.

  • :flush_interval (Float) — default: 30

    The number of seconds between flushes of the event buffer.

  • :read_timeout (Float) — default: 10

    The read timeout for network connections in seconds.

  • :connect_timeout (Float) — default: 2

    The connect timeout for network connections in seconds.

  • :store (Object)

    A cache store for the Faraday HTTP caching library. Defaults to the Rails cache in a Rails environment, or a thread-safe in-memory store otherwise.



24
25
26
27
28
29
30
31
32
33
# File 'lib/ldclient-rb/config.rb', line 24

def initialize(opts = {})
  @base_uri = (opts[:base_uri] || Config.default_base_uri).chomp("/")
  @capacity = opts[:capacity] || Config.default_capacity
  @logger = opts[:logger] || Config.default_logger
  @store = opts[:store] || Config.default_store
  @flush_interval = opts[:flush_interval] || Config.default_flush_interval
  @connect_timeout = opts[:connect_timeout] || Config.default_connect_timeout
  @read_timeout = opts[:read_timeout] || Config.default_read_timeout
  @log_timings = opts[:log_timings] || Config.default_log_timings
end

Class Method Details

.defaultConfig

The default LaunchDarkly client configuration. This configuration sets reasonable defaults for most users.

Returns:

  • The default LaunchDarkly configuration.



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

def self.default
  Config.new()
end

.default_base_uriObject



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

def self.default_base_uri
  "https://app.launchdarkly.com"
end

.default_capacityObject



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

def self.default_capacity
  10000
end

.default_connect_timeoutObject



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

def self.default_connect_timeout
  2
end

.default_flush_intervalObject



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

def self.default_flush_interval
  10
end

.default_log_timingsObject



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

def self.default_log_timings
  false
end

.default_loggerObject



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

def self.default_logger
  defined?(Rails) && Rails.respond_to?(:logger) ? Rails.logger : ::Logger.new($stdout)
end

.default_read_timeoutObject



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

def self.default_read_timeout
  10
end

.default_storeObject



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

def self.default_store
  defined?(Rails) && Rails.respond_to?(:cache) ? Rails.cache : ThreadSafeMemoryStore.new
end

Instance Method Details

#base_uriString

The base URL for the LaunchDarkly server.

Returns:

  • The configured base URL for the LaunchDarkly server.



39
40
41
# File 'lib/ldclient-rb/config.rb', line 39

def base_uri
  @base_uri
end

#capacityInteger

The capacity of the events buffer. The client buffers up to this many events in memory before flushing. If the capacity is exceeded before the buffer is flushed, events will be discarded. Increasing the capacity means that events are less likely to be discarded, at the cost of consuming more memory.

Returns:

  • The configured capacity of the event buffer



66
67
68
# File 'lib/ldclient-rb/config.rb', line 66

def capacity
  @capacity
end

#connect_timeoutFloat

The connect timeout for network connections in seconds.

Returns:

  • The connect timeout in seconds.



90
91
92
# File 'lib/ldclient-rb/config.rb', line 90

def connect_timeout
  @connect_timeout
end

#flush_intervalFloat

The number of seconds between flushes of the event buffer. Decreasing the flush interval means that the event buffer is less likely to reach capacity.

Returns:

  • The configured number of seconds between flushes of the event buffer.



48
49
50
# File 'lib/ldclient-rb/config.rb', line 48

def flush_interval
  @flush_interval
end

#log_timings?Boolean

Whether timing information should be logged. If it is logged, it will be logged to the DEBUG level on the configured logger. This can be very verbose.

Returns:

  • True if timing information should be logged.



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

def log_timings?
  @log_timings
end

#loggerLogger

The configured logger for the LaunchDarkly client. The client library uses the log to print warning and error messages.

Returns:

  • The configured logger



57
58
59
# File 'lib/ldclient-rb/config.rb', line 57

def logger
  @logger
end

#read_timeoutFloat

The read timeout for network connections in seconds.

Returns:

  • The read timeout in seconds.



82
83
84
# File 'lib/ldclient-rb/config.rb', line 82

def read_timeout
  @read_timeout
end

#storeObject

The store for the Faraday HTTP caching library. Stores should respond to ‘read’ and ‘write’ requests.

Returns:

  • The configured store for the Faraday HTTP caching library.



74
75
76
# File 'lib/ldclient-rb/config.rb', line 74

def store
  @store
end