Class: Prefab::Client
- Inherits:
-
Object
- Object
- Prefab::Client
- Defined in:
- lib/prefab/client.rb
Constant Summary collapse
- LOG =
Prefab::InternalLogger.new(self)
- MAX_SLEEP_SEC =
10- BASE_SLEEP_SEC =
0.5
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#instance_hash ⇒ Object
readonly
Returns the value of attribute instance_hash.
-
#interceptor ⇒ Object
readonly
Returns the value of attribute interceptor.
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#prefab_api_url ⇒ Object
readonly
Returns the value of attribute prefab_api_url.
Instance Method Summary collapse
- #config_client(timeout: 5.0) ⇒ Object
- #context ⇒ Object
- #context_shape_aggregator ⇒ Object
- #defined?(key) ⇒ Boolean
- #enabled?(feature_name, jit_context = NO_DEFAULT_PROVIDED) ⇒ Boolean
- #evaluation_summary_aggregator ⇒ Object
- #example_contexts_aggregator ⇒ Object
- #feature_flag_client ⇒ Object
-
#fork ⇒ Object
When starting a forked process, use this to re-use the options on_worker_boot do Prefab.fork end.
- #get(key, default = NO_DEFAULT_PROVIDED, jit_context = NO_DEFAULT_PROVIDED) ⇒ Object
-
#initialize(options = Prefab::Options.new) ⇒ Client
constructor
A new instance of Client.
- #inspect ⇒ Object
- #is_ff?(key) ⇒ Boolean
- #log ⇒ Object
- #log_path_aggregator ⇒ Object
- #on_update(&block) ⇒ Object
- #post(path, body) ⇒ Object
- #resolver ⇒ Object
- #set_rails_loggers ⇒ Object
- #with_context(properties, &block) ⇒ Object
Constructor Details
#initialize(options = Prefab::Options.new) ⇒ Client
Returns a new instance of Client.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/prefab/client.rb', line 13 def initialize( = Prefab::Options.new) = .is_a?(Prefab::Options) ? : Prefab::Options.new() @namespace = .namespace @stubs = {} @instance_hash = ::UUID.new.generate if .local_only? LOG.debug 'Prefab Running in Local Mode' elsif .datafile? LOG.debug 'Prefab Running in DataFile Mode' else @api_key = .api_key raise Prefab::Errors::InvalidApiKeyError, @api_key if @api_key.nil? || @api_key.empty? || api_key.count('-') < 1 @prefab_api_url = .prefab_api_url LOG.debug "Prefab Connecting to: #{@prefab_api_url}" end context.clear Prefab::Context.global_context = .global_context # start config client config_client end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
11 12 13 |
# File 'lib/prefab/client.rb', line 11 def api_key @api_key end |
#instance_hash ⇒ Object (readonly)
Returns the value of attribute instance_hash.
11 12 13 |
# File 'lib/prefab/client.rb', line 11 def instance_hash @instance_hash end |
#interceptor ⇒ Object (readonly)
Returns the value of attribute interceptor.
11 12 13 |
# File 'lib/prefab/client.rb', line 11 def interceptor @interceptor end |
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
11 12 13 |
# File 'lib/prefab/client.rb', line 11 def namespace @namespace end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
11 12 13 |
# File 'lib/prefab/client.rb', line 11 def end |
#prefab_api_url ⇒ Object (readonly)
Returns the value of attribute prefab_api_url.
11 12 13 |
# File 'lib/prefab/client.rb', line 11 def prefab_api_url @prefab_api_url end |
Instance Method Details
#config_client(timeout: 5.0) ⇒ Object
47 48 49 |
# File 'lib/prefab/client.rb', line 47 def config_client(timeout: 5.0) @config_client ||= Prefab::ConfigClient.new(self, timeout) end |
#context ⇒ Object
43 44 45 |
# File 'lib/prefab/client.rb', line 43 def context Prefab::Context.current end |
#context_shape_aggregator ⇒ Object
66 67 68 69 70 71 |
# File 'lib/prefab/client.rb', line 66 def context_shape_aggregator return nil if .collect_max_shapes <= 0 @context_shape_aggregator ||= ContextShapeAggregator.new(client: self, max_shapes: .collect_max_shapes, sync_interval: .collect_sync_interval) end |
#defined?(key) ⇒ Boolean
133 134 135 |
# File 'lib/prefab/client.rb', line 133 def defined?(key) !!config_client.send(:raw, key) end |
#enabled?(feature_name, jit_context = NO_DEFAULT_PROVIDED) ⇒ Boolean
101 102 103 |
# File 'lib/prefab/client.rb', line 101 def enabled?(feature_name, jit_context = NO_DEFAULT_PROVIDED) feature_flag_client.feature_is_on_for?(feature_name, jit_context) end |
#evaluation_summary_aggregator ⇒ Object
83 84 85 86 87 88 89 90 91 |
# File 'lib/prefab/client.rb', line 83 def evaluation_summary_aggregator return nil if .collect_max_evaluation_summaries <= 0 @evaluation_summary_aggregator ||= EvaluationSummaryAggregator.new( client: self, max_keys: .collect_max_evaluation_summaries, sync_interval: .collect_sync_interval ) end |
#example_contexts_aggregator ⇒ Object
73 74 75 76 77 78 79 80 81 |
# File 'lib/prefab/client.rb', line 73 def example_contexts_aggregator return nil if .collect_max_example_contexts <= 0 @example_contexts_aggregator ||= ExampleContextsAggregator.new( client: self, max_contexts: .collect_max_example_contexts, sync_interval: .collect_sync_interval ) end |
#feature_flag_client ⇒ Object
51 52 53 |
# File 'lib/prefab/client.rb', line 51 def feature_flag_client @feature_flag_client ||= Prefab::FeatureFlagClient.new(self) end |
#fork ⇒ Object
When starting a forked process, use this to re-use the options on_worker_boot do
Prefab.fork
end
129 130 131 |
# File 'lib/prefab/client.rb', line 129 def fork Prefab::Client.new(.for_fork) end |
#get(key, default = NO_DEFAULT_PROVIDED, jit_context = NO_DEFAULT_PROVIDED) ⇒ Object
105 106 107 108 109 110 111 |
# File 'lib/prefab/client.rb', line 105 def get(key, default = NO_DEFAULT_PROVIDED, jit_context = NO_DEFAULT_PROVIDED) if is_ff?(key) feature_flag_client.get(key, jit_context, default: default) else config_client.get(key, default, jit_context) end end |
#inspect ⇒ Object
117 118 119 |
# File 'lib/prefab/client.rb', line 117 def inspect "#<Prefab::Client:#{object_id} namespace=#{namespace}>" end |
#is_ff?(key) ⇒ Boolean
137 138 139 140 141 |
# File 'lib/prefab/client.rb', line 137 def is_ff?(key) raw = config_client.send(:raw, key) raw && raw.allowable_values.any? end |
#log ⇒ Object
62 63 64 |
# File 'lib/prefab/client.rb', line 62 def log @log ||= Prefab::LoggerClient.new(client: self, log_path_aggregator: log_path_aggregator) end |
#log_path_aggregator ⇒ Object
55 56 57 58 59 60 |
# File 'lib/prefab/client.rb', line 55 def log_path_aggregator return nil if .collect_max_paths <= 0 @log_path_aggregator ||= LogPathAggregator.new(client: self, max_paths: .collect_max_paths, sync_interval: .collect_sync_interval) end |
#on_update(&block) ⇒ Object
97 98 99 |
# File 'lib/prefab/client.rb', line 97 def on_update(&block) resolver.on_update(&block) end |
#post(path, body) ⇒ Object
113 114 115 |
# File 'lib/prefab/client.rb', line 113 def post(path, body) Prefab::HttpConnection.new(.prefab_api_url, @api_key).post(path, body) end |
#resolver ⇒ Object
121 122 123 |
# File 'lib/prefab/client.rb', line 121 def resolver config_client.resolver end |
#set_rails_loggers ⇒ Object
93 94 95 |
# File 'lib/prefab/client.rb', line 93 def set_rails_loggers warn '[DEPRECATION] `set_rails_loggers` is deprecated since 1.6. Please use semantic_logger or `Prefab.log_filter` instead.' end |
#with_context(properties, &block) ⇒ Object
39 40 41 |
# File 'lib/prefab/client.rb', line 39 def with_context(properties, &block) Prefab::Context.with_context(properties, &block) end |