Module: Prefab
- Defined in:
- lib/prefab/criteria_evaluator.rb,
lib/prefab/error.rb,
lib/prefab/client.rb,
lib/prefab/prefab.rb,
lib/prefab/context.rb,
lib/prefab/options.rb,
lib/prefab/duration.rb,
lib/prefab-cloud-ruby.rb,
lib/prefab/encryption.rb,
lib/prefab/evaluation.rb,
lib/prefab/time_helpers.rb,
lib/prefab/config_client.rb,
lib/prefab/config_loader.rb,
lib/prefab/context_shape.rb,
lib/prefab/logger_client.rb,
lib/prefab/periodic_sync.rb,
lib/prefab/config_resolver.rb,
lib/prefab/http_connection.rb,
lib/prefab/internal_logger.rb,
lib/prefab/javascript_stub.rb,
lib/prefab/rate_limit_cache.rb,
lib/prefab/sse_config_client.rb,
lib/prefab/yaml_config_parser.rb,
lib/prefab/exponential_backoff.rb,
lib/prefab/feature_flag_client.rb,
lib/prefab/local_config_parser.rb,
lib/prefab/log_path_aggregator.rb,
lib/prefab/config_value_wrapper.rb,
lib/prefab/config_value_unwrapper.rb,
lib/prefab/config_client_presenter.rb,
lib/prefab/weighted_value_resolver.rb,
lib/prefab/context_shape_aggregator.rb,
lib/prefab/resolved_config_presenter.rb,
lib/prefab/errors/env_var_parse_error.rb,
lib/prefab/errors/uninitialized_error.rb,
lib/prefab/example_contexts_aggregator.rb,
lib/prefab/errors/invalid_api_key_error.rb,
lib/prefab/errors/missing_default_error.rb,
lib/prefab/errors/missing_env_var_error.rb,
lib/prefab/evaluation_summary_aggregator.rb,
lib/prefab/errors/initialization_timeout_error.rb
Overview
rubocop:disable Naming/MethodName
We're intentionally keeping the UPCASED method names to match the protobuf
and avoid wasting CPU cycles lowercasing things
Defined Under Namespace
Modules: Errors, PeriodicSync, TimeHelpers
Classes: Client, ConfigClient, ConfigClientPresenter, ConfigLoader, ConfigResolver, ConfigValueUnwrapper, ConfigValueWrapper, Context, ContextShape, ContextShapeAggregator, CriteriaEvaluator, Duration, Encryption, Error, Evaluation, EvaluationSummaryAggregator, ExampleContextsAggregator, ExponentialBackoff, FeatureFlagClient, HttpConnection, InternalLogger, JavaScriptStub, LocalConfigParser, LogPathAggregator, LoggerClient, Options, RateLimitCache, ResolvedConfigPresenter, SSEConfigClient, WeightedValueResolver, YAMLConfigParser
Constant Summary
collapse
- LOG =
Prefab::InternalLogger.new(self)
- NO_DEFAULT_PROVIDED =
:no_default_provided
- VERSION =
File.read(File.dirname(__FILE__) + '/../VERSION').strip
- @@lock =
Concurrent::ReadWriteLock.new
Class Method Summary
collapse
Class Method Details
.bootstrap_javascript(context) ⇒ Object
Generate the JavaScript snippet to bootstrap the client SDK. This will
include the configuration values that are permitted to be sent to the
client SDK.
If the context provided to the client SDK is not the same as the context
used to generate the configuration values, the client SDK will still
generate a fetch to get the correct values for the context.
Any keys that could not be resolved will be logged as a warning to the
console.
91
92
93
94
|
# File 'lib/prefab/prefab.rb', line 91
def self.bootstrap_javascript(context)
ensure_initialized
Prefab::JavaScriptStub.new(@singleton).bootstrap(context)
end
|
.bootstrap_log_level(log) ⇒ Object
66
67
68
69
|
# File 'lib/prefab/prefab.rb', line 66
def self.bootstrap_log_level(log)
level = ENV['PREFAB_LOG_CLIENT_BOOTSTRAP_LOG_LEVEL'] ? ENV['PREFAB_LOG_CLIENT_BOOTSTRAP_LOG_LEVEL'].downcase.to_sym : :warn
SemanticLogger::Levels.index(level) <= SemanticLogger::Levels.index(log.level)
end
|
.defined?(key) ⇒ Boolean
71
72
73
74
|
# File 'lib/prefab/prefab.rb', line 71
def self.defined?(key)
ensure_initialized key
@singleton.defined?(key)
end
|
.enabled?(feature_name, jit_context = NO_DEFAULT_PROVIDED) ⇒ Boolean
36
37
38
39
|
# File 'lib/prefab/prefab.rb', line 36
def self.enabled?(feature_name, jit_context = NO_DEFAULT_PROVIDED)
ensure_initialized feature_name
@singleton.enabled?(feature_name, jit_context)
end
|
.finish_init! ⇒ Object
62
63
64
|
# File 'lib/prefab/prefab.rb', line 62
def self.finish_init!
@config_has_loaded = true
end
|
.fork ⇒ Object
19
20
21
22
23
24
|
# File 'lib/prefab/prefab.rb', line 19
def self.fork
ensure_initialized
@@lock.with_write_lock {
@singleton = @singleton.fork
}
end
|
.generate_javascript_stub(context, callback = nil) ⇒ Object
Generate the JavaScript snippet to replace the client SDK. Use this to
get prefab.get and prefab.isEnabled functions on the window object.
Only use this if you are not using the client SDK and do not need
client-side context.
Any keys that could not be resolved will be logged as a warning to the
console.
You can pass an optional callback function to be called with the key and
value of each configuration value. This can be useful for logging,
tracking experiment exposure, etc.
e.g.
Prefab.generate_javascript_stub(context, "reportExperimentExposure")
Prefab.generate_javascript_stub(context, "(key,value)=>{console.log({eval: 'eval', key,value})}")
112
113
114
115
|
# File 'lib/prefab/prefab.rb', line 112
def self.generate_javascript_stub(context, callback = nil)
ensure_initialized
Prefab::JavaScriptStub.new(@singleton).generate_stub(context, callback)
end
|
.get(key, default = NO_DEFAULT_PROVIDED, jit_context = NO_DEFAULT_PROVIDED) ⇒ Object
31
32
33
34
|
# File 'lib/prefab/prefab.rb', line 31
def self.get(key, default = NO_DEFAULT_PROVIDED, jit_context = NO_DEFAULT_PROVIDED)
ensure_initialized key
@singleton.get(key, default, jit_context)
end
|
.init(options = Prefab::Options.new) ⇒ Object
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/prefab/prefab.rb', line 8
def self.init(options = Prefab::Options.new)
unless @singleton.nil?
LOG.warn 'Prefab already initialized.'
return @singleton
end
@@lock.with_write_lock {
@singleton = Prefab::Client.new(options)
}
end
|
.instance ⇒ Object
46
47
48
49
|
# File 'lib/prefab/prefab.rb', line 46
def self.instance
ensure_initialized
@singleton
end
|
.is_ff?(key) ⇒ Boolean
76
77
78
79
|
# File 'lib/prefab/prefab.rb', line 76
def self.is_ff?(key)
ensure_initialized key
@singleton.is_ff?(key)
end
|
.log_filter ⇒ Object
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/prefab/prefab.rb', line 51
def self.log_filter
InternalLogger.using_prefab_log_filter!
return Proc.new do |log|
if defined?(@singleton) && !@singleton.nil? && @singleton.config_client.initialized?
@singleton.log.semantic_filter(log)
else
bootstrap_log_level(log)
end
end
end
|
.set_rails_loggers ⇒ Object
26
27
28
29
|
# File 'lib/prefab/prefab.rb', line 26
def self.set_rails_loggers
ensure_initialized
@singleton.set_rails_loggers
end
|
.with_context(properties, &block) ⇒ Object
41
42
43
44
|
# File 'lib/prefab/prefab.rb', line 41
def self.with_context(properties, &block)
ensure_initialized
@singleton.with_context(properties, &block)
end
|