Class: SplitIoClient::SplitConfig
- Inherits:
-
Object
- Object
- SplitIoClient::SplitConfig
- Defined in:
- lib/splitclient-rb/split_config.rb
Overview
This class manages configuration options for the split client library. If not custom configuration is required the default configuration values will be used
Instance Attribute Summary collapse
-
#base_uri ⇒ String
readonly
The base URL for split API end points.
-
#block_until_ready ⇒ Integer
readonly
The number of seconds to wait for SDK readiness or false to disable waiting.
-
#cache_adapter ⇒ Object
readonly
The cache adapter to store splits/segments in.
-
#connection_timeout ⇒ Int
readonly
The connection timeout for network connections in seconds.
-
#debug_enabled ⇒ Boolean
readonly
The boolean that represents the state of the debug log level.
-
#events_uri ⇒ String
readonly
The base URL for split events API end points.
-
#features_refresh_rate ⇒ Object
readonly
Returns the value of attribute features_refresh_rate.
-
#impressions_refresh_rate ⇒ Object
readonly
Returns the value of attribute impressions_refresh_rate.
-
#local_store ⇒ Object
readonly
The store for the Faraday HTTP caching library.
-
#logger ⇒ Logger
readonly
The configured logger.
-
#machine_ip ⇒ Object
readonly
Returns the value of attribute machine_ip.
-
#machine_name ⇒ Object
readonly
Returns the value of attribute machine_name.
-
#metrics_refresh_rate ⇒ Object
readonly
Returns the value of attribute metrics_refresh_rate.
-
#read_timeout ⇒ Int
readonly
The read timeout for network connections in seconds.
-
#segments_refresh_rate ⇒ Object
readonly
Returns the value of attribute segments_refresh_rate.
-
#transport_debug_enabled ⇒ Boolean
readonly
Enable to log the content retrieved from endpoints.
Class Method Summary collapse
-
.default ⇒ Config
The default split client configuration.
-
.default_base_uri ⇒ string
The default base uri for api calls.
-
.default_cache_adapter ⇒ LocalStore
Configuration value for local cache store.
-
.default_connection_timeout ⇒ int
The default connection timeout value.
-
.default_debug ⇒ boolean
The default debug value.
- .default_events_uri ⇒ Object
- .default_features_refresh_rate ⇒ Object
- .default_impressions_refresh_rate ⇒ Object
-
.default_logger ⇒ object
The default logger object.
- .default_metrics_refresh_rate ⇒ Object
-
.default_read_timeout ⇒ int
The default read timeout value.
- .default_segments_refresh_rate ⇒ Object
-
.get_hostname ⇒ string
gets the hostname where the sdk gem is running.
-
.get_ip ⇒ string
gets the ip where the sdk gem is running.
-
.transport_debug ⇒ boolean
The default transport_debug_enabled value.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ type
constructor
Constructor for creating custom split client config.
-
#log_found_exception(caller, exn) ⇒ void
custom logger of exceptions.
-
#log_loaded_cache ⇒ void
log which cache class was loaded.
Constructor Details
#initialize(opts = {}) ⇒ type
Constructor for creating custom split client config
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/splitclient-rb/split_config.rb', line 27 def initialize(opts = {}) @base_uri = (opts[:base_uri] || SplitConfig.default_base_uri).chomp('/') @events_uri = (opts[:events_uri] || SplitConfig.default_events_uri).chomp('/') @cache_adapter = opts[:cache_adapter] || SplitConfig.default_cache_adapter @connection_timeout = opts[:connection_timeout] || SplitConfig.default_connection_timeout @read_timeout = opts[:read_timeout] || SplitConfig.default_read_timeout @features_refresh_rate = opts[:features_refresh_rate] || SplitConfig.default_features_refresh_rate @segments_refresh_rate = opts[:segments_refresh_rate] || SplitConfig.default_segments_refresh_rate @metrics_refresh_rate = opts[:metrics_refresh_rate] || SplitConfig.default_metrics_refresh_rate @impressions_refresh_rate = opts[:impressions_refresh_rate] || SplitConfig.default_impressions_refresh_rate @logger = opts[:logger] || SplitConfig.default_logger @debug_enabled = opts[:debug_enabled] || SplitConfig.default_debug @transport_debug_enabled = opts[:transport_debug_enabled] || SplitConfig.default_debug @block_until_ready = opts[:block_until_ready] || false @machine_name = SplitConfig.get_hostname @machine_ip = SplitConfig.get_ip log_loaded_cache end |
Instance Attribute Details
#base_uri ⇒ String (readonly)
The base URL for split API end points
51 52 53 |
# File 'lib/splitclient-rb/split_config.rb', line 51 def base_uri @base_uri end |
#block_until_ready ⇒ Integer (readonly)
The number of seconds to wait for SDK readiness or false to disable waiting
107 108 109 |
# File 'lib/splitclient-rb/split_config.rb', line 107 def block_until_ready @block_until_ready end |
#cache_adapter ⇒ Object (readonly)
The cache adapter to store splits/segments in
76 77 78 |
# File 'lib/splitclient-rb/split_config.rb', line 76 def cache_adapter @cache_adapter end |
#connection_timeout ⇒ Int (readonly)
The connection timeout for network connections in seconds.
82 83 84 |
# File 'lib/splitclient-rb/split_config.rb', line 82 def connection_timeout @connection_timeout end |
#debug_enabled ⇒ Boolean (readonly)
The boolean that represents the state of the debug log level
95 96 97 |
# File 'lib/splitclient-rb/split_config.rb', line 95 def debug_enabled @debug_enabled end |
#events_uri ⇒ String (readonly)
The base URL for split events API end points
57 58 59 |
# File 'lib/splitclient-rb/split_config.rb', line 57 def events_uri @events_uri end |
#features_refresh_rate ⇒ Object (readonly)
Returns the value of attribute features_refresh_rate.
112 113 114 |
# File 'lib/splitclient-rb/split_config.rb', line 112 def features_refresh_rate @features_refresh_rate end |
#impressions_refresh_rate ⇒ Object (readonly)
Returns the value of attribute impressions_refresh_rate.
115 116 117 |
# File 'lib/splitclient-rb/split_config.rb', line 115 def impressions_refresh_rate @impressions_refresh_rate end |
#local_store ⇒ Object (readonly)
The store for the Faraday HTTP caching library. Stores should respond to ‘read’, ‘write’ and ‘delete’ requests.
64 65 66 |
# File 'lib/splitclient-rb/split_config.rb', line 64 def local_store @local_store end |
#logger ⇒ Logger (readonly)
The configured logger. The client library uses the log to print warning and error messages.
89 90 91 |
# File 'lib/splitclient-rb/split_config.rb', line 89 def logger @logger end |
#machine_ip ⇒ Object (readonly)
Returns the value of attribute machine_ip.
109 110 111 |
# File 'lib/splitclient-rb/split_config.rb', line 109 def machine_ip @machine_ip end |
#machine_name ⇒ Object (readonly)
Returns the value of attribute machine_name.
110 111 112 |
# File 'lib/splitclient-rb/split_config.rb', line 110 def machine_name @machine_name end |
#metrics_refresh_rate ⇒ Object (readonly)
Returns the value of attribute metrics_refresh_rate.
114 115 116 |
# File 'lib/splitclient-rb/split_config.rb', line 114 def metrics_refresh_rate @metrics_refresh_rate end |
#read_timeout ⇒ Int (readonly)
The read timeout for network connections in seconds.
70 71 72 |
# File 'lib/splitclient-rb/split_config.rb', line 70 def read_timeout @read_timeout end |
#segments_refresh_rate ⇒ Object (readonly)
Returns the value of attribute segments_refresh_rate.
113 114 115 |
# File 'lib/splitclient-rb/split_config.rb', line 113 def segments_refresh_rate @segments_refresh_rate end |
#transport_debug_enabled ⇒ Boolean (readonly)
Enable to log the content retrieved from endpoints
101 102 103 |
# File 'lib/splitclient-rb/split_config.rb', line 101 def transport_debug_enabled @transport_debug_enabled end |
Class Method Details
.default ⇒ Config
The default split client configuration
121 122 123 |
# File 'lib/splitclient-rb/split_config.rb', line 121 def self.default SplitConfig.new end |
.default_base_uri ⇒ string
The default base uri for api calls
129 130 131 |
# File 'lib/splitclient-rb/split_config.rb', line 129 def self.default_base_uri 'https://sdk.split.io/api/' end |
.default_cache_adapter ⇒ LocalStore
Returns configuration value for local cache store.
138 139 140 |
# File 'lib/splitclient-rb/split_config.rb', line 138 def self.default_cache_adapter SplitIoClient::Cache::Adapters::MemoryAdapter.new end |
.default_connection_timeout ⇒ int
The default connection timeout value
154 155 156 |
# File 'lib/splitclient-rb/split_config.rb', line 154 def self.default_connection_timeout 5 end |
.default_debug ⇒ boolean
The default debug value
186 187 188 |
# File 'lib/splitclient-rb/split_config.rb', line 186 def self.default_debug false end |
.default_events_uri ⇒ Object
133 134 135 |
# File 'lib/splitclient-rb/split_config.rb', line 133 def self.default_events_uri 'https://events.split.io/api/' end |
.default_features_refresh_rate ⇒ Object
158 159 160 |
# File 'lib/splitclient-rb/split_config.rb', line 158 def self.default_features_refresh_rate 30 end |
.default_impressions_refresh_rate ⇒ Object
170 171 172 |
# File 'lib/splitclient-rb/split_config.rb', line 170 def self.default_impressions_refresh_rate 60 end |
.default_logger ⇒ object
The default logger object
178 179 180 |
# File 'lib/splitclient-rb/split_config.rb', line 178 def self.default_logger Logger.new($stdout) end |
.default_metrics_refresh_rate ⇒ Object
166 167 168 |
# File 'lib/splitclient-rb/split_config.rb', line 166 def self.default_metrics_refresh_rate 60 end |
.default_read_timeout ⇒ int
The default read timeout value
146 147 148 |
# File 'lib/splitclient-rb/split_config.rb', line 146 def self.default_read_timeout 5 end |
.default_segments_refresh_rate ⇒ Object
162 163 164 |
# File 'lib/splitclient-rb/split_config.rb', line 162 def self.default_segments_refresh_rate 60 end |
.get_hostname ⇒ string
gets the hostname where the sdk gem is running
220 221 222 223 224 225 226 227 |
# File 'lib/splitclient-rb/split_config.rb', line 220 def self.get_hostname begin Socket.gethostname rescue #unable to get hostname 'localhost' end end |
.get_ip ⇒ string
gets the ip where the sdk gem is running
233 234 235 236 237 238 239 240 |
# File 'lib/splitclient-rb/split_config.rb', line 233 def self.get_ip begin Socket::getaddrinfo(Socket.gethostname, 'echo', Socket::AF_INET)[0][3] rescue #unable to get local ip '127.0.0.0' end end |
.transport_debug ⇒ boolean
The default transport_debug_enabled value
194 195 196 |
# File 'lib/splitclient-rb/split_config.rb', line 194 def self.transport_debug false end |
Instance Method Details
#log_found_exception(caller, exn) ⇒ void
This method returns an undefined value.
custom logger of exceptions
202 203 204 205 206 |
# File 'lib/splitclient-rb/split_config.rb', line 202 def log_found_exception(caller, exn) error_traceback = "#{exn.inspect} #{exn}\n\t#{exn.backtrace.join("\n\t")}" error = "[splitclient-rb] Unexpected exception in #{caller}: #{error_traceback}" @logger.error(error) end |
#log_loaded_cache ⇒ void
This method returns an undefined value.
log which cache class was loaded
212 213 214 |
# File 'lib/splitclient-rb/split_config.rb', line 212 def log_loaded_cache @logger.info("Loaded cache class: #{@cache_adapter.class}") end |