Class: SplitIoClient::SplitConfig

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ type

Constructor for creating custom split client config

Parameters:

  • opts (Hash) (defaults to: {})

    optional hash with configuration options

Options Hash (opts):

  • :base_uri (String) — default: "https://sdk.split.io/api/"

    The base URL for split API end points

  • :events_uri (String) — default: "https://events.split.io/api/"

    The events URL for events end points

  • :read_timeout (Int) — default: 10

    The read timeout for network connections in seconds.

  • :connection_timeout (Int) — default: 2

    The connect timeout for network connections in seconds.

  • :local_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.

  • :features_refresh_rate (Int)

    The SDK polls Split servers for changes to feature roll-out plans. This parameter controls this polling period in seconds.

  • :segments_refresh_rate (Int)
  • :metrics_refresh_rate (Int)
  • :impressions_refresh_rate (Int)
  • :logger (Object)

    a logger to user for messages from the client. Defaults to stdout

  • :debug_enabled (Boolean) — default: false

    The value for the debug flag



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_uriString (readonly)

The base URL for split API end points

Returns:

  • (String)

    The configured base URL for the split API end points



51
52
53
# File 'lib/splitclient-rb/split_config.rb', line 51

def base_uri
  @base_uri
end

#block_until_readyInteger (readonly)

The number of seconds to wait for SDK readiness or false to disable waiting

Returns:

  • (Integer)

    /[FalseClass]



107
108
109
# File 'lib/splitclient-rb/split_config.rb', line 107

def block_until_ready
  @block_until_ready
end

#cache_adapterObject (readonly)

The cache adapter to store splits/segments in

Returns:

  • (Object)

    Cache adapter instance



76
77
78
# File 'lib/splitclient-rb/split_config.rb', line 76

def cache_adapter
  @cache_adapter
end

#connection_timeoutInt (readonly)

The connection timeout for network connections in seconds.

Returns:

  • (Int)

    The connect timeout in seconds.



82
83
84
# File 'lib/splitclient-rb/split_config.rb', line 82

def connection_timeout
  @connection_timeout
end

#debug_enabledBoolean (readonly)

The boolean that represents the state of the debug log level

Returns:

  • (Boolean)

    The value for the debug flag



95
96
97
# File 'lib/splitclient-rb/split_config.rb', line 95

def debug_enabled
  @debug_enabled
end

#events_uriString (readonly)

The base URL for split events API end points

Returns:

  • (String)

    The configured URL for the events API end points



57
58
59
# File 'lib/splitclient-rb/split_config.rb', line 57

def events_uri
  @events_uri
end

#features_refresh_rateObject (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_rateObject (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_storeObject (readonly)

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

Returns:

  • (Object)

    The configured store for the Faraday HTTP caching library.



64
65
66
# File 'lib/splitclient-rb/split_config.rb', line 64

def local_store
  @local_store
end

#loggerLogger (readonly)

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

Returns:

  • (Logger)

    The configured logger



89
90
91
# File 'lib/splitclient-rb/split_config.rb', line 89

def logger
  @logger
end

#machine_ipObject (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_nameObject (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_rateObject (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_timeoutInt (readonly)

The read timeout for network connections in seconds.

Returns:

  • (Int)

    The timeout in seconds.



70
71
72
# File 'lib/splitclient-rb/split_config.rb', line 70

def read_timeout
  @read_timeout
end

#segments_refresh_rateObject (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_enabledBoolean (readonly)

Enable to log the content retrieved from endpoints

Returns:

  • (Boolean)

    The value for the debug flag



101
102
103
# File 'lib/splitclient-rb/split_config.rb', line 101

def transport_debug_enabled
  @transport_debug_enabled
end

Class Method Details

.defaultConfig

The default split client configuration

Returns:

  • (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_uristring

The default base uri for api calls

Returns:

  • (string)

    The default base uri



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_adapterLocalStore

Returns configuration value for local cache store.

Returns:

  • (LocalStore)

    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_timeoutint

The default connection timeout value

Returns:

  • (int)


154
155
156
# File 'lib/splitclient-rb/split_config.rb', line 154

def self.default_connection_timeout
  5
end

.default_debugboolean

The default debug value

Returns:

  • (boolean)


186
187
188
# File 'lib/splitclient-rb/split_config.rb', line 186

def self.default_debug
  false
end

.default_events_uriObject



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_rateObject



158
159
160
# File 'lib/splitclient-rb/split_config.rb', line 158

def self.default_features_refresh_rate
  30
end

.default_impressions_refresh_rateObject



170
171
172
# File 'lib/splitclient-rb/split_config.rb', line 170

def self.default_impressions_refresh_rate
  60
end

.default_loggerobject

The default logger object

Returns:

  • (object)


178
179
180
# File 'lib/splitclient-rb/split_config.rb', line 178

def self.default_logger
  Logger.new($stdout)
end

.default_metrics_refresh_rateObject



166
167
168
# File 'lib/splitclient-rb/split_config.rb', line 166

def self.default_metrics_refresh_rate
  60
end

.default_read_timeoutint

The default read timeout value

Returns:

  • (int)


146
147
148
# File 'lib/splitclient-rb/split_config.rb', line 146

def self.default_read_timeout
  5
end

.default_segments_refresh_rateObject



162
163
164
# File 'lib/splitclient-rb/split_config.rb', line 162

def self.default_segments_refresh_rate
  60
end

.get_hostnamestring

gets the hostname where the sdk gem is running

Returns:

  • (string)


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_ipstring

gets the ip where the sdk gem is running

Returns:

  • (string)


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_debugboolean

The default transport_debug_enabled value

Returns:

  • (boolean)


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_cachevoid

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