Class: Gitlab::Experiment::Rollout::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/experiment/rollout.rb

Direct Known Subclasses

Percent, Random, RoundRobin

Constant Summary collapse

DEFAULT_OPTIONS =
{
  include_control: false
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Base

Returns a new instance of Base.



25
26
27
# File 'lib/gitlab/experiment/rollout.rb', line 25

def initialize(options = {})
  @options = DEFAULT_OPTIONS.merge(options)
end

Instance Attribute Details

#experimentObject (readonly)

Returns the value of attribute experiment.



21
22
23
# File 'lib/gitlab/experiment/rollout.rb', line 21

def experiment
  @experiment
end

#optionsObject (readonly)

Returns the value of attribute options.



21
22
23
# File 'lib/gitlab/experiment/rollout.rb', line 21

def options
  @options
end

Instance Method Details

#enabled?Boolean

Returns:

  • (Boolean)


37
38
39
40
41
# File 'lib/gitlab/experiment/rollout.rb', line 37

def enabled?
  require_experiment(__method__)

  true
end

#for(experiment) ⇒ Object

Raises:

  • (ArgumentError)


29
30
31
32
33
34
35
# File 'lib/gitlab/experiment/rollout.rb', line 29

def for(experiment)
  raise ArgumentError, 'you must provide an experiment instance' unless experiment.class <= Gitlab::Experiment

  @experiment = experiment

  self
end

#resolveObject



43
44
45
46
47
48
49
50
51
52
# File 'lib/gitlab/experiment/rollout.rb', line 43

def resolve
  require_experiment(__method__)

  return nil if @experiment.respond_to?(:experiment_group?) && !@experiment.experiment_group?

  validate! # allow the rollout strategy to validate itself

  assignment = execute_assigment
  assignment == :control ? nil : assignment # avoid caching control
end