Module: Statsig
- Extended by:
- T::Sig
- Defined in:
- lib/id_list.rb,
lib/network.rb,
lib/statsig.rb,
lib/evaluator.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
Overview
typed: true
Defined Under Namespace
Modules: EvaluationReason, Interfaces Classes: ConfigResult, Diagnostics, ErrorBoundary, EvaluationDetails, Evaluator, IDList, Network, NetworkError, SpecStore, StatsigLogger, UninitializedError, ValueError
Class Method Summary collapse
-
.check_gate(user, gate_name) ⇒ Object
Gets the boolean result of a gate, evaluated against the given user.
-
.check_gate_with_exposure_logging_disabled(user, gate_name) ⇒ Object
Gets the boolean result of a gate, evaluated against the given user.
-
.get_client_initialize_response(user) ⇒ Object
Gets all evaluated values for the given user.
-
.get_config(user, dynamic_config_name) ⇒ Object
Get the values of a dynamic config, evaluated against the given user.
-
.get_config_with_exposure_logging_disabled(user, dynamic_config_name) ⇒ Object
Get the values of a dynamic config, evaluated against the given user.
-
.get_experiment(user, experiment_name) ⇒ Object
Get the values of an experiment, evaluated against the given user.
-
.get_experiment_with_exposure_logging_disabled(user, experiment_name) ⇒ Object
Get the values of an experiment, evaluated against the given user.
-
.get_layer(user, layer_name) ⇒ Object
Get the values of a layer, evaluated against the given user.
-
.get_layer_with_exposure_logging_disabled(user, layer_name) ⇒ Object
Get the values of a layer, evaluated against the given user.
-
.get_statsig_metadata ⇒ Object
Internal Statsig metadata for this SDK.
-
.initialize(secret_key, options = nil, error_callback = nil) ⇒ Object
Initializes the Statsig SDK.
-
.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.
-
.shutdown ⇒ Object
Stops all Statsig activity and flushes any pending events.
Class Method Details
.check_gate(user, gate_name) ⇒ Object
Gets the boolean result of a gate, evaluated against the given user. An exposure event will automatically be logged for the gate.
33 34 35 36 |
# File 'lib/statsig.rb', line 33 def self.check_gate(user, gate_name) ensure_initialized @shared_instance&.check_gate(user, gate_name) end |
.check_gate_with_exposure_logging_disabled(user, gate_name) ⇒ Object
Gets the boolean result of a gate, evaluated against the given user.
44 45 46 47 |
# File 'lib/statsig.rb', line 44 def self.check_gate_with_exposure_logging_disabled(user, gate_name) ensure_initialized @shared_instance&.check_gate(user, gate_name, StatsigDriver::CheckGateOptions.new(log_exposure: false)) end |
.get_client_initialize_response(user) ⇒ 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.
217 218 219 220 |
# File 'lib/statsig.rb', line 217 def self.get_client_initialize_response(user) ensure_initialized @shared_instance&.get_client_initialize_response(user) end |
.get_config(user, dynamic_config_name) ⇒ Object
Get the values of a dynamic config, evaluated against the given user. An exposure event will automatically be logged for the dynamic config.
66 67 68 69 |
# File 'lib/statsig.rb', line 66 def self.get_config(user, dynamic_config_name) ensure_initialized @shared_instance&.get_config(user, dynamic_config_name) end |
.get_config_with_exposure_logging_disabled(user, dynamic_config_name) ⇒ Object
Get the values of a dynamic config, evaluated against the given user.
77 78 79 80 |
# File 'lib/statsig.rb', line 77 def self.get_config_with_exposure_logging_disabled(user, dynamic_config_name) ensure_initialized @shared_instance&.get_config(user, dynamic_config_name, StatsigDriver::GetConfigOptions.new(log_exposure: false)) end |
.get_experiment(user, experiment_name) ⇒ Object
Get the values of an experiment, evaluated against the given user. An exposure event will automatically be logged for the experiment.
99 100 101 102 |
# File 'lib/statsig.rb', line 99 def self.get_experiment(user, experiment_name) ensure_initialized @shared_instance&.get_experiment(user, experiment_name) end |
.get_experiment_with_exposure_logging_disabled(user, experiment_name) ⇒ Object
Get the values of an experiment, evaluated against the given user.
110 111 112 113 |
# File 'lib/statsig.rb', line 110 def self.get_experiment_with_exposure_logging_disabled(user, experiment_name) ensure_initialized @shared_instance&.get_experiment(user, experiment_name, StatsigDriver::GetExperimentOptions.new(log_exposure: false)) end |
.get_layer(user, layer_name) ⇒ 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.
133 134 135 136 |
# File 'lib/statsig.rb', line 133 def self.get_layer(user, layer_name) ensure_initialized @shared_instance&.get_layer(user, layer_name) end |
.get_layer_with_exposure_logging_disabled(user, layer_name) ⇒ Object
Get the values of a layer, evaluated against the given user.
144 145 146 147 |
# File 'lib/statsig.rb', line 144 def self.get_layer_with_exposure_logging_disabled(user, layer_name) ensure_initialized @shared_instance&.get_layer(user, layer_name, StatsigDriver::GetLayerOptions.new(log_exposure: false)) end |
.get_statsig_metadata ⇒ Object
Internal Statsig metadata for this SDK
225 226 227 228 229 230 |
# File 'lib/statsig.rb', line 225 def self. { 'sdkType' => 'ruby-server', 'sdkVersion' => '1.19.1', } end |
.initialize(secret_key, options = nil, error_callback = nil) ⇒ Object
Initializes the Statsig SDK.
17 18 19 20 21 22 23 24 25 |
# File 'lib/statsig.rb', line 17 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 |
.log_event(user, event_name, value = nil, metadata = nil) ⇒ Object
Logs an event to Statsig with the provided values.
172 173 174 175 |
# File 'lib/statsig.rb', line 172 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
88 89 90 91 |
# File 'lib/statsig.rb', line 88 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
121 122 123 124 |
# File 'lib/statsig.rb', line 121 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
55 56 57 58 |
# File 'lib/statsig.rb', line 55 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
156 157 158 159 |
# File 'lib/statsig.rb', line 156 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.
204 205 206 207 |
# File 'lib/statsig.rb', line 204 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.
193 194 195 196 |
# File 'lib/statsig.rb', line 193 def self.override_gate(gate_name, gate_value) ensure_initialized @shared_instance&.override_gate(gate_name, gate_value) end |
.shutdown ⇒ Object
Stops all Statsig activity and flushes any pending events.
180 181 182 183 184 185 |
# File 'lib/statsig.rb', line 180 def self.shutdown if defined? @shared_instance and !@shared_instance.nil? @shared_instance.shutdown end @shared_instance = nil end |