Class: Determinator::Control
- Inherits:
-
Object
- Object
- Determinator::Control
- Defined in:
- lib/determinator/control.rb
Defined Under Namespace
Classes: Indicators
Instance Attribute Summary collapse
-
#explainer ⇒ Object
readonly
Returns the value of attribute explainer.
-
#retrieval ⇒ Object
readonly
Returns the value of attribute retrieval.
Instance Method Summary collapse
- #explain_determination(name, id: nil, guid: nil, properties: {}) ⇒ Object
-
#feature_flag_on?(name, id: nil, guid: nil, properties: {}, feature: nil) ⇒ true, false
Determines whether a specific feature is on or off for the given actor.
-
#for_actor(id: nil, guid: nil, default_properties: {}) ⇒ ActorControl
Creates a new determinator instance which assumes the actor id, guid and properties given are always specified.
-
#initialize(retrieval:) ⇒ Control
constructor
A new instance of Control.
- #inspect ⇒ Object
-
#on_determination {|name, arguments, determination| ... } ⇒ Object
Defines code that should execute when a determination is completed.
-
#retrieve(name) ⇒ Feature, MissingResponse
Uses the retrieval (and a cache if set on the Determinator config) to fetch a feature definition.
-
#which_variant(name, id: nil, guid: nil, properties: {}, feature: nil) ⇒ false, String
Determines what an actor should see for a specific experiment.
Constructor Details
#initialize(retrieval:) ⇒ Control
10 11 12 13 |
# File 'lib/determinator/control.rb', line 10 def initialize(retrieval:) @retrieval = retrieval @explainer = Determinator::Explainer.new end |
Instance Attribute Details
#explainer ⇒ Object (readonly)
Returns the value of attribute explainer.
8 9 10 |
# File 'lib/determinator/control.rb', line 8 def explainer @explainer end |
#retrieval ⇒ Object (readonly)
Returns the value of attribute retrieval.
8 9 10 |
# File 'lib/determinator/control.rb', line 8 def retrieval @retrieval end |
Instance Method Details
#explain_determination(name, id: nil, guid: nil, properties: {}) ⇒ Object
57 58 59 60 61 |
# File 'lib/determinator/control.rb', line 57 def explain_determination(name, id: nil, guid: nil, properties: {}) explainer.explain do determinate_and_notice(name, id: id, guid: guid, properties: properties) end end |
#feature_flag_on?(name, id: nil, guid: nil, properties: {}, feature: nil) ⇒ true, false
Determines whether a specific feature is on or off for the given actor
36 37 38 39 40 |
# File 'lib/determinator/control.rb', line 36 def feature_flag_on?(name, id: nil, guid: nil, properties: {}, feature: nil) determinate_and_notice(name, id: id, guid: guid, properties: properties, feature: feature) do |feature| feature.feature_flag? end end |
#for_actor(id: nil, guid: nil, default_properties: {}) ⇒ ActorControl
Creates a new determinator instance which assumes the actor id, guid and properties given are always specified. This is useful for within a before filter in a webserver, for example, so that the determinator instance made available has the logged-in user’s credentials prefilled.
23 24 25 |
# File 'lib/determinator/control.rb', line 23 def for_actor(id: nil, guid: nil, default_properties: {}) ActorControl.new(self, id: id, guid: guid, default_properties: default_properties) end |
#inspect ⇒ Object
71 72 73 |
# File 'lib/determinator/control.rb', line 71 def inspect '#<Determinator::Control>' end |
#on_determination {|name, arguments, determination| ... } ⇒ Object
Defines code that should execute when a determination is completed. This is particularly helpful for comparing determinations made by this control with other mechanisms.
Please note that this block will be executed synchronously before delivering the determination to the callsite.
85 86 87 |
# File 'lib/determinator/control.rb', line 85 def on_determination(&block) @determination_callback = block end |
#retrieve(name) ⇒ Feature, MissingResponse
Uses the retrieval (and a cache if set on the Determinator config) to fetch a feature definition.
67 68 69 |
# File 'lib/determinator/control.rb', line 67 def retrieve(name) Determinator.with_retrieval_cache(name) { retrieval.retrieve(name) } end |
#which_variant(name, id: nil, guid: nil, properties: {}, feature: nil) ⇒ false, String
Determines what an actor should see for a specific experiment
51 52 53 54 55 |
# File 'lib/determinator/control.rb', line 51 def which_variant(name, id: nil, guid: nil, properties: {}, feature: nil) determinate_and_notice(name, id: id, guid: guid, properties: properties, feature: feature) do |feature| feature.experiment? end end |