Module: Statsig
- Defined in:
- lib/memo.rb,
lib/id_list.rb,
lib/network.rb,
lib/statsig.rb,
lib/constants.rb,
lib/evaluator.rb,
lib/hash_utils.rb,
lib/spec_store.rb,
lib/diagnostics.rb,
lib/config_result.rb,
lib/error_boundary.rb,
lib/statsig_errors.rb,
lib/statsig_logger.rb,
lib/evaluation_details.rb,
lib/interfaces/data_store.rb,
lib/client_initialize_helpers.rb,
lib/user_persistent_storage_utils.rb,
lib/interfaces/user_persistent_storage.rb
Defined Under Namespace
Modules: Const, EvaluationReason, Interfaces Classes: CheckGateOptions, ConfigResult, Diagnostics, ErrorBoundary, EvaluationDetails, Evaluator, GetConfigOptions, GetExperimentOptions, GetGateOptions, GetLayerOptions, HashUtils, IDList, InvalidSDKKeyResponse, Memo, Network, NetworkError, ResponseFormatter, SpecStore, StatsigLogger, UninitializedError, UserPersistentStorageUtils, ValueError
Class Method Summary collapse
-
.check_gate(user, gate_name, options = nil) ⇒ Boolean
Gets the boolean result of a gate, evaluated against the given user.
-
.check_gate_with_exposure_logging_disabled(user, gate_name) ⇒ Object
deprecated
Deprecated.
-
use check_gate(user, gate, options) with CheckGateOptions.new(disable_log_exposure: true) as options
-
- .clear_config_overrides ⇒ Object
- .clear_gate_overrides ⇒ Object
-
.get_client_initialize_response(user, hash: 'sha256', client_sdk_key: nil, include_local_overrides: false) ⇒ Object
Gets all evaluated values for the given user.
-
.get_config(user, dynamic_config_name, options = nil) ⇒ DynamicConfig
Get the values of a dynamic config, evaluated against the given user.
-
.get_config_with_exposure_logging_disabled(user, dynamic_config_name) ⇒ DynamicConfig
deprecated
Deprecated.
-
use get_config(user, config, options) with GetConfigOptions.new(disable_log_exposure: true) as options
-
-
.get_experiment(user, experiment_name, options = nil) ⇒ Object
Get the values of an experiment, evaluated against the given user.
-
.get_experiment_with_exposure_logging_disabled(user, experiment_name) ⇒ Object
deprecated
Deprecated.
-
use get_experiment(user, experiment, options) with GetExperimentOptions.new(disable_log_exposure: true) as options
-
-
.get_gate(user, gate_name, options) ⇒ FeatureGate
Gets the gate, evaluated against the given user.
- .get_initialization_details ⇒ Object
-
.get_layer(user, layer_name, options = nil) ⇒ Object
Get the values of a layer, evaluated against the given user.
-
.get_layer_with_exposure_logging_disabled(user, layer_name) ⇒ Object
deprecated
Deprecated.
-
use get_layer(user, gate, options) with GetLayerOptions.new(disable_log_exposure: true) as options
-
-
.get_statsig_metadata ⇒ Object
Internal Statsig metadata for this SDK.
- .get_user_persisted_values(user, id_type) ⇒ Object
-
.initialize(secret_key, options = nil, error_callback = nil) ⇒ Object
Initializes the Statsig SDK.
-
.list_autotunes ⇒ Object
Returns a list of all autotune names.
-
.list_configs ⇒ Object
Returns a list of all config names.
-
.list_experiments ⇒ Object
Returns a list of all experiment names.
-
.list_gates ⇒ Object
Returns a list of all gate names.
-
.list_layers ⇒ Object
Returns a list of all layer names.
-
.log_event(user, event_name, value = nil, metadata = nil) ⇒ Object
Logs an event to Statsig with the provided values.
-
.manually_log_config_exposure(user, dynamic_config) ⇒ Object
Logs an exposure event for the dynamic config.
-
.manually_log_experiment_exposure(user, experiment_name) ⇒ Object
Logs an exposure event for the experiment.
-
.manually_log_gate_exposure(user, gate_name) ⇒ Object
Logs an exposure event for the gate.
-
.manually_log_layer_parameter_exposure(user, layer_name, parameter_name) ⇒ Object
Logs an exposure event for the parameter in the given layer.
-
.override_config(config_name, config_value) ⇒ Object
Sets a value to be returned for the given dynamic config/experiment instead of the actual evaluated value.
-
.override_gate(gate_name, gate_value) ⇒ Object
Sets a value to be returned for the given gate instead of the actual evaluated value.
- .remove_config_override(config_name) ⇒ Object
- .remove_gate_override(gate_name) ⇒ Object
- .set_debug_info(debug_info) ⇒ Object
-
.shutdown ⇒ Object
Stops all Statsig activity and flushes any pending events.
- .sync_idlists ⇒ Object
- .sync_rulesets ⇒ Object
Class Method Details
.check_gate(user, gate_name, options = nil) ⇒ Boolean
Gets the boolean result of a gate, evaluated against the given user. An exposure event will automatically be logged for the gate.
69 70 71 72 |
# File 'lib/statsig.rb', line 69 def self.check_gate(user, gate_name, = nil) ensure_initialized @shared_instance&.check_gate(user, gate_name, ) end |
.check_gate_with_exposure_logging_disabled(user, gate_name) ⇒ Object
-
use check_gate(user, gate, options) with CheckGateOptions.new(disable_log_exposure: true) as options
Gets the boolean result of a gate, evaluated against the given user.
80 81 82 83 |
# File 'lib/statsig.rb', line 80 def self.check_gate_with_exposure_logging_disabled(user, gate_name) ensure_initialized @shared_instance&.check_gate(user, gate_name, CheckGateOptions.new(disable_log_exposure: true)) end |
.clear_config_overrides ⇒ Object
336 337 338 339 |
# File 'lib/statsig.rb', line 336 def self.clear_config_overrides ensure_initialized @shared_instance&.clear_config_overrides end |
.clear_gate_overrides ⇒ Object
316 317 318 319 |
# File 'lib/statsig.rb', line 316 def self.clear_gate_overrides ensure_initialized @shared_instance&.clear_gate_overrides end |
.get_client_initialize_response(user, hash: 'sha256', client_sdk_key: nil, include_local_overrides: false) ⇒ Object
See Ruby Documentation: docs.statsig.com/server/rubySDK)
Gets all evaluated values for the given user. These values can then be given to a Statsig Client SDK via bootstrapping.
358 359 360 361 362 363 364 365 366 |
# File 'lib/statsig.rb', line 358 def self.get_client_initialize_response( user, hash: 'sha256', client_sdk_key: nil, include_local_overrides: false ) ensure_initialized @shared_instance&.get_client_initialize_response(user, hash, client_sdk_key, include_local_overrides) end |
.get_config(user, dynamic_config_name, options = nil) ⇒ DynamicConfig
Get the values of a dynamic config, evaluated against the given user. An exposure event will automatically be logged for the dynamic config.
112 113 114 115 |
# File 'lib/statsig.rb', line 112 def self.get_config(user, dynamic_config_name, = nil) ensure_initialized @shared_instance&.get_config(user, dynamic_config_name, ) end |
.get_config_with_exposure_logging_disabled(user, dynamic_config_name) ⇒ DynamicConfig
-
use get_config(user, config, options) with GetConfigOptions.new(disable_log_exposure: true) as options
Get the values of a dynamic config, evaluated against the given user.
124 125 126 127 |
# File 'lib/statsig.rb', line 124 def self.get_config_with_exposure_logging_disabled(user, dynamic_config_name) ensure_initialized @shared_instance&.get_config(user, dynamic_config_name, GetConfigOptions.new(disable_log_exposure: true)) end |
.get_experiment(user, experiment_name, options = nil) ⇒ Object
Get the values of an experiment, evaluated against the given user. An exposure event will automatically be logged for the experiment.
156 157 158 159 |
# File 'lib/statsig.rb', line 156 def self.get_experiment(user, experiment_name, = nil) ensure_initialized @shared_instance&.get_experiment(user, experiment_name, ) end |
.get_experiment_with_exposure_logging_disabled(user, experiment_name) ⇒ Object
-
use get_experiment(user, experiment, options) with GetExperimentOptions.new(disable_log_exposure: true) as options
Get the values of an experiment, evaluated against the given user.
167 168 169 170 |
# File 'lib/statsig.rb', line 167 def self.get_experiment_with_exposure_logging_disabled(user, experiment_name) ensure_initialized @shared_instance&.get_experiment(user, experiment_name, GetExperimentOptions.new(disable_log_exposure: true)) end |
.get_gate(user, gate_name, options) ⇒ FeatureGate
Gets the gate, evaluated against the given user. An exposure event will automatically be logged for the gate.
47 48 49 50 |
# File 'lib/statsig.rb', line 47 def self.get_gate(user, gate_name, ) ensure_initialized @shared_instance&.get_gate(user, gate_name, ) end |
.get_initialization_details ⇒ Object
23 24 25 26 27 28 |
# File 'lib/statsig.rb', line 23 def self.get_initialization_details if not defined? @shared_instance or @shared_instance.nil? return {duration: 0, isSDKReady: false, configSpecReady: false, failure_details: {exception: Statsig::UninitializedError.new, reason: 'INTERNAL_ERROR'}} end @shared_instance.get_initialization_details end |
.get_layer(user, layer_name, options = nil) ⇒ Object
Get the values of a layer, evaluated against the given user. Exposure events will be fired when get or get_typed is called on the resulting Layer class.
203 204 205 206 |
# File 'lib/statsig.rb', line 203 def self.get_layer(user, layer_name, = nil) ensure_initialized @shared_instance&.get_layer(user, layer_name, ) end |
.get_layer_with_exposure_logging_disabled(user, layer_name) ⇒ Object
-
use get_layer(user, gate, options) with GetLayerOptions.new(disable_log_exposure: true) as options
Get the values of a layer, evaluated against the given user.
214 215 216 217 |
# File 'lib/statsig.rb', line 214 def self.get_layer_with_exposure_logging_disabled(user, layer_name) ensure_initialized @shared_instance&.get_layer(user, layer_name, GetLayerOptions.new(disable_log_exposure: true)) end |
.get_statsig_metadata ⇒ Object
Internal Statsig metadata for this SDK
370 371 372 373 374 375 376 |
# File 'lib/statsig.rb', line 370 def self. { 'sdkType' => 'ruby-server', 'sdkVersion' => '2.2.1', 'languageVersion' => RUBY_VERSION } end |
.get_user_persisted_values(user, id_type) ⇒ Object
182 183 184 185 |
# File 'lib/statsig.rb', line 182 def self.get_user_persisted_values(user, id_type) ensure_initialized @shared_instance&.get_user_persisted_values(user, id_type) end |
.initialize(secret_key, options = nil, error_callback = nil) ⇒ Object
Initializes the Statsig SDK.
13 14 15 16 17 18 19 20 21 |
# File 'lib/statsig.rb', line 13 def self.initialize(secret_key, = nil, error_callback = nil) unless @shared_instance.nil? puts 'Statsig already initialized.' @shared_instance.maybe_restart_background_threads return @shared_instance end @shared_instance = StatsigDriver.new(secret_key, , error_callback) end |
.list_autotunes ⇒ Object
Returns a list of all autotune names
279 280 281 282 |
# File 'lib/statsig.rb', line 279 def self.list_autotunes ensure_initialized @shared_instance&.list_autotunes end |
.list_configs ⇒ Object
Returns a list of all config names
263 264 265 266 |
# File 'lib/statsig.rb', line 263 def self.list_configs ensure_initialized @shared_instance&.list_configs end |
.list_experiments ⇒ Object
Returns a list of all experiment names
271 272 273 274 |
# File 'lib/statsig.rb', line 271 def self.list_experiments ensure_initialized @shared_instance&.list_experiments end |
.list_gates ⇒ Object
Returns a list of all gate names
255 256 257 258 |
# File 'lib/statsig.rb', line 255 def self.list_gates ensure_initialized @shared_instance&.list_gates end |
.list_layers ⇒ Object
Returns a list of all layer names
287 288 289 290 |
# File 'lib/statsig.rb', line 287 def self.list_layers ensure_initialized @shared_instance&.list_layers end |
.log_event(user, event_name, value = nil, metadata = nil) ⇒ Object
Logs an event to Statsig with the provided values.
237 238 239 240 |
# File 'lib/statsig.rb', line 237 def self.log_event(user, event_name, value = nil, = nil) ensure_initialized @shared_instance&.log_event(user, event_name, value, ) end |
.manually_log_config_exposure(user, dynamic_config) ⇒ Object
Logs an exposure event for the dynamic config
134 135 136 137 |
# File 'lib/statsig.rb', line 134 def self.manually_log_config_exposure(user, dynamic_config) ensure_initialized @shared_instance&.manually_log_config_exposure(user, dynamic_config) end |
.manually_log_experiment_exposure(user, experiment_name) ⇒ Object
Logs an exposure event for the experiment
177 178 179 180 |
# File 'lib/statsig.rb', line 177 def self.manually_log_experiment_exposure(user, experiment_name) ensure_initialized @shared_instance&.manually_log_config_exposure(user, experiment_name) end |
.manually_log_gate_exposure(user, gate_name) ⇒ Object
Logs an exposure event for the gate
90 91 92 93 |
# File 'lib/statsig.rb', line 90 def self.manually_log_gate_exposure(user, gate_name) ensure_initialized @shared_instance&.manually_log_gate_exposure(user, gate_name) end |
.manually_log_layer_parameter_exposure(user, layer_name, parameter_name) ⇒ Object
Logs an exposure event for the parameter in the given layer
225 226 227 228 |
# File 'lib/statsig.rb', line 225 def self.manually_log_layer_parameter_exposure(user, layer_name, parameter_name) ensure_initialized @shared_instance&.manually_log_layer_parameter_exposure(user, layer_name, parameter_name) end |
.override_config(config_name, config_value) ⇒ Object
Sets a value to be returned for the given dynamic config/experiment instead of the actual evaluated value.
326 327 328 329 |
# File 'lib/statsig.rb', line 326 def self.override_config(config_name, config_value) ensure_initialized @shared_instance&.override_config(config_name, config_value) end |
.override_gate(gate_name, gate_value) ⇒ Object
Sets a value to be returned for the given gate instead of the actual evaluated value.
306 307 308 309 |
# File 'lib/statsig.rb', line 306 def self.override_gate(gate_name, gate_value) ensure_initialized @shared_instance&.override_gate(gate_name, gate_value) end |
.remove_config_override(config_name) ⇒ Object
331 332 333 334 |
# File 'lib/statsig.rb', line 331 def self.remove_config_override(config_name) ensure_initialized @shared_instance&.remove_config_override(config_name) end |
.remove_gate_override(gate_name) ⇒ Object
311 312 313 314 |
# File 'lib/statsig.rb', line 311 def self.remove_gate_override(gate_name) ensure_initialized @shared_instance&.remove_gate_override(gate_name) end |
.set_debug_info(debug_info) ⇒ Object
343 344 345 346 |
# File 'lib/statsig.rb', line 343 def self.set_debug_info(debug_info) ensure_initialized @shared_instance&.set_debug_info(debug_info) end |
.shutdown ⇒ Object
Stops all Statsig activity and flushes any pending events.
294 295 296 297 298 299 |
# File 'lib/statsig.rb', line 294 def self.shutdown if defined? @shared_instance and !@shared_instance.nil? @shared_instance.shutdown end @shared_instance = nil end |
.sync_idlists ⇒ Object
247 248 249 250 |
# File 'lib/statsig.rb', line 247 def self.sync_idlists ensure_initialized @shared_instance&.manually_sync_idlists end |
.sync_rulesets ⇒ Object
242 243 244 245 |
# File 'lib/statsig.rb', line 242 def self.sync_rulesets ensure_initialized @shared_instance&.manually_sync_rulesets end |