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.
-
#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.
-
#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.
Class Method Summary collapse
-
.default ⇒ Config
The default split client configuration.
-
.default_base_uri ⇒ string
The default base uri for api calls.
-
.default_connection_timeout ⇒ int
The default connection timeout value.
-
.default_debug ⇒ boolean
The default debug value.
- .default_features_refresh_rate ⇒ Object
- .default_impressions_refresh_rate ⇒ Object
-
.default_local_store ⇒ LocalStore
Configuration value for local cache store.
-
.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.
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.
Constructor Details
#initialize(opts = {}) ⇒ type
Constructor for creating custom split client config
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/splitclient-rb/split_config.rb', line 26 def initialize(opts = {}) @base_uri = (opts[:base_uri] || SplitConfig.default_base_uri).chomp('/') @local_store = opts[:local_store] || SplitConfig.default_local_store @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 @machine_name = SplitConfig.get_hostname @machine_ip = SplitConfig.get_ip end |
Instance Attribute Details
#base_uri ⇒ String (readonly)
The base URL for split API end points
45 46 47 |
# File 'lib/splitclient-rb/split_config.rb', line 45 def base_uri @base_uri end |
#connection_timeout ⇒ Int (readonly)
The connection timeout for network connections in seconds.
64 65 66 |
# File 'lib/splitclient-rb/split_config.rb', line 64 def connection_timeout @connection_timeout end |
#debug_enabled ⇒ Boolean (readonly)
The boolean that represents the state of the debug log level
77 78 79 |
# File 'lib/splitclient-rb/split_config.rb', line 77 def debug_enabled @debug_enabled end |
#features_refresh_rate ⇒ Object (readonly)
Returns the value of attribute features_refresh_rate.
82 83 84 |
# File 'lib/splitclient-rb/split_config.rb', line 82 def features_refresh_rate @features_refresh_rate end |
#impressions_refresh_rate ⇒ Object (readonly)
Returns the value of attribute impressions_refresh_rate.
85 86 87 |
# File 'lib/splitclient-rb/split_config.rb', line 85 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.
52 53 54 |
# File 'lib/splitclient-rb/split_config.rb', line 52 def local_store @local_store end |
#logger ⇒ Logger (readonly)
The configured logger. The client library uses the log to print warning and error messages.
71 72 73 |
# File 'lib/splitclient-rb/split_config.rb', line 71 def logger @logger end |
#machine_ip ⇒ Object (readonly)
Returns the value of attribute machine_ip.
79 80 81 |
# File 'lib/splitclient-rb/split_config.rb', line 79 def machine_ip @machine_ip end |
#machine_name ⇒ Object (readonly)
Returns the value of attribute machine_name.
80 81 82 |
# File 'lib/splitclient-rb/split_config.rb', line 80 def machine_name @machine_name end |
#metrics_refresh_rate ⇒ Object (readonly)
Returns the value of attribute metrics_refresh_rate.
84 85 86 |
# File 'lib/splitclient-rb/split_config.rb', line 84 def metrics_refresh_rate @metrics_refresh_rate end |
#read_timeout ⇒ Int (readonly)
The read timeout for network connections in seconds.
58 59 60 |
# File 'lib/splitclient-rb/split_config.rb', line 58 def read_timeout @read_timeout end |
#segments_refresh_rate ⇒ Object (readonly)
Returns the value of attribute segments_refresh_rate.
83 84 85 |
# File 'lib/splitclient-rb/split_config.rb', line 83 def segments_refresh_rate @segments_refresh_rate end |
Class Method Details
.default ⇒ Config
The default split client configuration
91 92 93 |
# File 'lib/splitclient-rb/split_config.rb', line 91 def self.default SplitConfig.new end |
.default_base_uri ⇒ string
The default base uri for api calls
99 100 101 |
# File 'lib/splitclient-rb/split_config.rb', line 99 def self.default_base_uri 'https://sdk.split.io/api/' end |
.default_connection_timeout ⇒ int
The default connection timeout value
120 121 122 |
# File 'lib/splitclient-rb/split_config.rb', line 120 def self.default_connection_timeout 5 end |
.default_debug ⇒ boolean
The default debug value
152 153 154 |
# File 'lib/splitclient-rb/split_config.rb', line 152 def self.default_debug false end |
.default_features_refresh_rate ⇒ Object
124 125 126 |
# File 'lib/splitclient-rb/split_config.rb', line 124 def self.default_features_refresh_rate 30 end |
.default_impressions_refresh_rate ⇒ Object
136 137 138 |
# File 'lib/splitclient-rb/split_config.rb', line 136 def self.default_impressions_refresh_rate 60 end |
.default_local_store ⇒ LocalStore
Returns configuration value for local cache store.
104 105 106 |
# File 'lib/splitclient-rb/split_config.rb', line 104 def self.default_local_store defined?(Rails) && Rails.respond_to?(:cache) ? Rails.cache : LocalStore.new end |
.default_logger ⇒ object
The default logger object
144 145 146 |
# File 'lib/splitclient-rb/split_config.rb', line 144 def self.default_logger Logger.new($stdout) end |
.default_metrics_refresh_rate ⇒ Object
132 133 134 |
# File 'lib/splitclient-rb/split_config.rb', line 132 def self.default_metrics_refresh_rate 60 end |
.default_read_timeout ⇒ int
The default read timeout value
112 113 114 |
# File 'lib/splitclient-rb/split_config.rb', line 112 def self.default_read_timeout 5 end |
.default_segments_refresh_rate ⇒ Object
128 129 130 |
# File 'lib/splitclient-rb/split_config.rb', line 128 def self.default_segments_refresh_rate 60 end |
.get_hostname ⇒ string
gets the hostname where the sdk gem is running
170 171 172 173 174 175 176 177 |
# File 'lib/splitclient-rb/split_config.rb', line 170 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
183 184 185 186 187 188 189 190 |
# File 'lib/splitclient-rb/split_config.rb', line 183 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 |
Instance Method Details
#log_found_exception(caller, exn) ⇒ void
This method returns an undefined value.
custom logger of exceptions
160 161 162 163 164 |
# File 'lib/splitclient-rb/split_config.rb', line 160 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 |