Module: Determinator
- Defined in:
- lib/determinator.rb,
lib/determinator/control.rb,
lib/determinator/feature.rb,
lib/determinator/version.rb,
lib/determinator/tracking.rb,
lib/determinator/target_group.rb,
lib/determinator/actor_control.rb,
lib/determinator/retrieve/file.rb,
lib/determinator/error_response.rb,
lib/determinator/missing_response.rb,
lib/determinator/serializers/json.rb,
lib/determinator/tracking/context.rb,
lib/determinator/tracking/request.rb,
lib/determinator/tracking/tracker.rb,
lib/determinator/retrieve/dynaconf.rb,
lib/determinator/cache/fetch_wrapper.rb,
lib/determinator/tracking/determination.rb,
lib/determinator/retrieve/http_retriever.rb,
lib/determinator/retrieve/null_retriever.rb,
lib/determinator/tracking/rack/middleware.rb,
lib/determinator/tracking/sidekiq/middleware.rb,
lib/determinator/retrieve/in_memory_retriever.rb
Defined Under Namespace
Modules: Cache, Retrieve, Serializers, Tracking Classes: ActorControl, Control, ErrorResponse, Feature, MissingResponse, TargetGroup
Constant Summary collapse
- VERSION =
'2.4.3'
Class Attribute Summary collapse
-
.feature_cache ⇒ Object
readonly
Returns the value of attribute feature_cache.
-
.retrieval ⇒ Object
readonly
Returns the value of attribute retrieval.
Class Method Summary collapse
- .configure(retrieval:, errors: nil, missing_feature: nil, feature_cache: nil) ⇒ Object
-
.feature_details(name) ⇒ Object
Returns the feature with the given name as Determinator uses it.
-
.instance ⇒ Determinator::Control
Returns the currently configured Determinator::Control instance.
- .invalidate_cache(name) ⇒ Object
- .notice_determination(id, guid, feature, determination) ⇒ Object
-
.notice_error(error) ⇒ Object
private
Allows Determinator to track that an error has happened with determination.
-
.notice_missing_feature(name) ⇒ Object
private
Allows Determinator to track that a feature was requested but was missing.
-
.on_determination {|id, guid, feature, determination| ... } ⇒ Object
Defines code that should execute when a determination is completed.
-
.on_error(&block) ⇒ Object
Defines how errors that shouldn’t break your application should be logged.
-
.on_missing_feature(&block) ⇒ Object
Defines how to record the moment when a feature which doesn’t exist is requested.
-
.with_retrieval_cache(name) ⇒ Object
private
Allows access to the chosen caching mechanism for any retrieval plugin.
Class Attribute Details
.feature_cache ⇒ Object (readonly)
Returns the value of attribute feature_cache.
14 15 16 |
# File 'lib/determinator.rb', line 14 def feature_cache @feature_cache end |
.retrieval ⇒ Object (readonly)
Returns the value of attribute retrieval.
14 15 16 |
# File 'lib/determinator.rb', line 14 def retrieval @retrieval end |
Class Method Details
.configure(retrieval:, errors: nil, missing_feature: nil, feature_cache: nil) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/determinator.rb', line 19 def configure(retrieval:, errors: nil, missing_feature: nil, feature_cache: nil) self.on_error(&errors) if errors self.on_missing_feature(&missing_feature) if missing_feature @feature_cache = feature_cache if feature_cache.respond_to?(:call) @retrieval = retrieval @instance = Control.new(retrieval: retrieval) end |
.feature_details(name) ⇒ Object
Returns the feature with the given name as Determinator uses it. This is useful for debugging issues with the retrieval mechanism which delivers features to Determinator.
65 66 67 |
# File 'lib/determinator.rb', line 65 def feature_details(name) with_retrieval_cache(name) { instance.retrieval.retrieve(name) } end |
.instance ⇒ Determinator::Control
Returns the currently configured Determinator::Control instance
31 32 33 34 |
# File 'lib/determinator.rb', line 31 def instance raise "No singleton Determinator instance defined" unless @instance @instance end |
.invalidate_cache(name) ⇒ Object
100 101 102 |
# File 'lib/determinator.rb', line 100 def invalidate_cache(name) @feature_cache.expire(name) end |
.notice_determination(id, guid, feature, determination) ⇒ Object
86 87 88 89 90 |
# File 'lib/determinator.rb', line 86 def notice_determination(id, guid, feature, determination) Determinator::Tracking.track(id, guid, feature, determination) return unless @determination_callback @determination_callback.call(id, guid, feature, determination) end |
.notice_error(error) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Allows Determinator to track that an error has happened with determination
71 72 73 74 75 76 |
# File 'lib/determinator.rb', line 71 def notice_error(error) return unless @error_logger error = RuntimeError.new(error) unless error.is_a?(StandardError) @error_logger.call(error) end |
.notice_missing_feature(name) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Allows Determinator to track that a feature was requested but was missing
80 81 82 83 84 |
# File 'lib/determinator.rb', line 80 def notice_missing_feature(name) return unless @missing_feature_logger @missing_feature_logger.call(name) end |
.on_determination {|id, guid, feature, determination| ... } ⇒ Object
Defines code that should execute when a determination is completed. This is particularly helpful for preparing or sending events to record that an actor has seen a particular experiment variant.
Please note that this block will be executed synchronously before delivering the determination to the callsite.
58 59 60 |
# File 'lib/determinator.rb', line 58 def on_determination(&block) @determination_callback = block end |
.on_error(&block) ⇒ Object
Defines how errors that shouldn’t break your application should be logged
37 38 39 |
# File 'lib/determinator.rb', line 37 def on_error(&block) @error_logger = block end |
.on_missing_feature(&block) ⇒ Object
Defines how to record the moment when a feature which doesn’t exist is requested. If this happens a lot it indicates poor set up, so can be useful for tracking.
43 44 45 |
# File 'lib/determinator.rb', line 43 def on_missing_feature(&block) @missing_feature_logger = block end |
.with_retrieval_cache(name) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Allows access to the chosen caching mechanism for any retrieval plugin.
94 95 96 97 98 |
# File 'lib/determinator.rb', line 94 def with_retrieval_cache(name) return yield unless @feature_cache.respond_to?(:call) @feature_cache.call(name) { yield } end |