Class: LaunchDarkly::Config
- Inherits:
-
Object
- Object
- LaunchDarkly::Config
- 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.
Instance Attribute Summary collapse
-
#base_uri ⇒ String
readonly
The base URL for the LaunchDarkly server.
-
#cache_store ⇒ Object
readonly
The store for the Faraday HTTP caching library.
-
#capacity ⇒ Integer
readonly
The capacity of the events buffer.
-
#connect_timeout ⇒ Float
readonly
The connect timeout for network connections in seconds.
-
#events_uri ⇒ String
readonly
The base URL for the LaunchDarkly events server.
-
#feature_store ⇒ Object
readonly
A store for feature flag configuration rules.
-
#flush_interval ⇒ Float
readonly
The number of seconds between flushes of the event buffer.
-
#logger ⇒ Logger
readonly
The configured logger for the LaunchDarkly client.
-
#poll_interval ⇒ Object
readonly
The number of seconds to wait before polling for feature flag updates.
-
#read_timeout ⇒ Float
readonly
The read timeout for network connections in seconds.
-
#stream_uri ⇒ String
readonly
The base URL for the LaunchDarkly streaming server.
Class Method Summary collapse
-
.default ⇒ Config
The default LaunchDarkly client configuration.
- .default_base_uri ⇒ Object
- .default_cache_store ⇒ Object
- .default_capacity ⇒ Object
- .default_connect_timeout ⇒ Object
- .default_events_uri ⇒ Object
- .default_feature_store ⇒ Object
- .default_flush_interval ⇒ Object
- .default_logger ⇒ Object
- .default_offline ⇒ Object
- .default_poll_interval ⇒ Object
- .default_read_timeout ⇒ Object
- .default_stream ⇒ Object
- .default_stream_uri ⇒ Object
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ type
constructor
Constructor for creating custom LaunchDarkly configurations.
-
#offline? ⇒ Boolean
TODO docs.
-
#stream? ⇒ Boolean
Whether streaming mode should be enabled.
Constructor Details
#initialize(opts = {}) ⇒ type
Constructor for creating custom LaunchDarkly configurations.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/ldclient-rb/config.rb', line 45 def initialize(opts = {}) @base_uri = (opts[:base_uri] || Config.default_base_uri).chomp("/") @stream_uri = (opts[:stream_uri] || Config.default_stream_uri).chomp("/") @events_uri = (opts[:events_uri] || Config.default_events_uri).chomp("/") @capacity = opts[:capacity] || Config.default_capacity @logger = opts[:logger] || Config.default_logger @cache_store = opts[:cache_store] || Config.default_cache_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 @feature_store = opts[:feature_store] || Config.default_feature_store @stream = opts.has_key?(:stream) ? opts[:stream] : Config.default_stream @offline = opts.has_key?(:offline) ? opts[:offline] : Config.default_offline @poll_interval = opts.has_key?(:poll_interval) && opts[:poll_interval] > 1 ? opts[:poll_interval] : Config.default_poll_interval end |
Instance Attribute Details
#base_uri ⇒ String (readonly)
The base URL for the LaunchDarkly server.
65 66 67 |
# File 'lib/ldclient-rb/config.rb', line 65 def base_uri @base_uri end |
#cache_store ⇒ Object (readonly)
The store for the Faraday HTTP caching library. Stores should respond to ‘read’ and ‘write’ requests.
127 128 129 |
# File 'lib/ldclient-rb/config.rb', line 127 def cache_store @cache_store end |
#capacity ⇒ Integer (readonly)
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.
120 121 122 |
# File 'lib/ldclient-rb/config.rb', line 120 def capacity @capacity end |
#connect_timeout ⇒ Float (readonly)
The connect timeout for network connections in seconds.
139 140 141 |
# File 'lib/ldclient-rb/config.rb', line 139 def connect_timeout @connect_timeout end |
#events_uri ⇒ String (readonly)
The base URL for the LaunchDarkly events server.
77 78 79 |
# File 'lib/ldclient-rb/config.rb', line 77 def events_uri @events_uri end |
#feature_store ⇒ Object (readonly)
A store for feature flag configuration rules.
144 145 146 |
# File 'lib/ldclient-rb/config.rb', line 144 def feature_store @feature_store end |
#flush_interval ⇒ Float (readonly)
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.
98 99 100 |
# File 'lib/ldclient-rb/config.rb', line 98 def flush_interval @flush_interval end |
#logger ⇒ Logger (readonly)
The configured logger for the LaunchDarkly client. The client library uses the log to print warning and error messages.
110 111 112 |
# File 'lib/ldclient-rb/config.rb', line 110 def logger @logger end |
#poll_interval ⇒ Object (readonly)
The number of seconds to wait before polling for feature flag updates. This option has no effect unless streaming is disabled
103 104 105 |
# File 'lib/ldclient-rb/config.rb', line 103 def poll_interval @poll_interval end |
#read_timeout ⇒ Float (readonly)
The read timeout for network connections in seconds.
133 134 135 |
# File 'lib/ldclient-rb/config.rb', line 133 def read_timeout @read_timeout end |
#stream_uri ⇒ String (readonly)
The base URL for the LaunchDarkly streaming server.
71 72 73 |
# File 'lib/ldclient-rb/config.rb', line 71 def stream_uri @stream_uri end |
Class Method Details
.default ⇒ Config
The default LaunchDarkly client configuration. This configuration sets reasonable defaults for most users.
151 152 153 |
# File 'lib/ldclient-rb/config.rb', line 151 def self.default Config.new end |
.default_base_uri ⇒ Object
159 160 161 |
# File 'lib/ldclient-rb/config.rb', line 159 def self.default_base_uri "https://app.launchdarkly.com" end |
.default_cache_store ⇒ Object
171 172 173 |
# File 'lib/ldclient-rb/config.rb', line 171 def self.default_cache_store defined?(Rails) && Rails.respond_to?(:cache) ? Rails.cache : ThreadSafeMemoryStore.new end |
.default_capacity ⇒ Object
155 156 157 |
# File 'lib/ldclient-rb/config.rb', line 155 def self.default_capacity 10000 end |
.default_connect_timeout ⇒ Object
183 184 185 |
# File 'lib/ldclient-rb/config.rb', line 183 def self.default_connect_timeout 2 end |
.default_events_uri ⇒ Object
167 168 169 |
# File 'lib/ldclient-rb/config.rb', line 167 def self.default_events_uri "https://events.launchdarkly.com" end |
.default_feature_store ⇒ Object
201 202 203 |
# File 'lib/ldclient-rb/config.rb', line 201 def self.default_feature_store InMemoryFeatureStore.new end |
.default_flush_interval ⇒ Object
175 176 177 |
# File 'lib/ldclient-rb/config.rb', line 175 def self.default_flush_interval 10 end |
.default_logger ⇒ Object
187 188 189 190 191 192 193 194 195 |
# File 'lib/ldclient-rb/config.rb', line 187 def self.default_logger if defined?(Rails) && Rails.respond_to?(:logger) Rails.logger else log = ::Logger.new($stdout) log.level = ::Logger::WARN log end end |
.default_offline ⇒ Object
205 206 207 |
# File 'lib/ldclient-rb/config.rb', line 205 def self.default_offline false end |
.default_poll_interval ⇒ Object
209 210 211 |
# File 'lib/ldclient-rb/config.rb', line 209 def self.default_poll_interval 1 end |
.default_read_timeout ⇒ Object
179 180 181 |
# File 'lib/ldclient-rb/config.rb', line 179 def self.default_read_timeout 10 end |
.default_stream ⇒ Object
197 198 199 |
# File 'lib/ldclient-rb/config.rb', line 197 def self.default_stream true end |
.default_stream_uri ⇒ Object
163 164 165 |
# File 'lib/ldclient-rb/config.rb', line 163 def self.default_stream_uri "https://stream.launchdarkly.com" end |
Instance Method Details
#offline? ⇒ Boolean
TODO docs
89 90 91 |
# File 'lib/ldclient-rb/config.rb', line 89 def offline? @offline end |
#stream? ⇒ Boolean
Whether streaming mode should be enabled. Streaming mode asynchronously updates feature flags in real-time using server-sent events.
84 85 86 |
# File 'lib/ldclient-rb/config.rb', line 84 def stream? @stream end |