Class: Determinator::Control

Inherits:
Object
  • Object
show all
Defined in:
lib/determinator/control.rb

Defined Under Namespace

Classes: Indicators

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(retrieval:) ⇒ Control

Returns a new instance of Control.



10
11
12
# File 'lib/determinator/control.rb', line 10

def initialize(retrieval:)
  @retrieval = retrieval
end

Instance Attribute Details

#retrievalObject (readonly)

Returns the value of attribute retrieval.



8
9
10
# File 'lib/determinator/control.rb', line 8

def retrieval
  @retrieval
end

Instance Method Details

#feature_flag_on?(name, id: nil, guid: nil, properties: {}) ⇒ true, false

Determines whether a specific feature is on or off for the given actor

Parameters:

  • name (#to_s)

    The name of the feature flag being checked

  • :id (#to_s)

    The id of the actor being determinated for

  • :guid (#to_s)

    The Anonymous id of the actor being determinated for

  • :properties (Hash<Symbol,String>)

    The properties of this actor which will be used for including this actor or not

Returns:

  • (true, false)

    Whether the feature is on (true) or off (false) for this actor

Raises:

  • (ArgumentError)

    When the arguments given to this method aren’t ever going to produce a useful response



34
35
36
37
38
# File 'lib/determinator/control.rb', line 34

def feature_flag_on?(name, id: nil, guid: nil, properties: {})
  determinate_and_notice(name, id: id, guid: guid, properties: properties) 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.

Parameters:

  • :id (#to_s)

    The ID of the actor being specified

  • :guid (#to_s)

    The Anonymous ID of the actor being specified

  • :default_properties (Hash<Symbol,String>)

    The default properties for the determinator being created

Returns:

  • (ActorControl)

    A helper object removing the need to know id and guid everywhere



22
23
24
# File 'lib/determinator/control.rb', line 22

def for_actor(id: nil, guid: nil, default_properties: {})
  ActorControl.new(self, id: id, guid: guid, default_properties: default_properties)
end

#inspectObject



54
55
56
# File 'lib/determinator/control.rb', line 54

def inspect
  '#<Determinator::Control>'
end

#which_variant(name, id: nil, guid: nil, properties: {}) ⇒ false, String

Determines what an actor should see for a specific experiment

Parameters:

  • name (#to_s)

    The name of the experiment being checked

  • :id (#to_s)

    The id of the actor being determinated for

  • :guid (#to_s)

    The Anonymous id of the actor being determinated for

  • :properties (Hash<Symbol,String>)

    The properties of this actor which will be used for including this actor or not

Returns:

  • (false, String)

    Returns false, if the actor is not in this experiment, or otherwise the variant name.

Raises:

  • (ArgumentError)

    When the arguments given to this method aren’t ever going to produce a useful response



48
49
50
51
52
# File 'lib/determinator/control.rb', line 48

def which_variant(name, id: nil, guid: nil, properties: {})
  determinate_and_notice(name, id: id, guid: guid, properties: properties) do |feature|
    feature.experiment?
  end
end