Class: Gitlab::Experimentation::Experiment

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

Constant Summary collapse

FEATURE_FLAG_SUFFIX =
"_experiment_percentage"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, **params) ⇒ Experiment

Returns a new instance of Experiment.


10
11
12
13
14
# File 'lib/gitlab/experimentation/experiment.rb', line 10

def initialize(key, **params)
  @key = key
  @tracking_category = params[:tracking_category]
  @rollout_strategy = params[:rollout_strategy] || :cookie
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.


8
9
10
# File 'lib/gitlab/experimentation/experiment.rb', line 8

def key
  @key
end

#rollout_strategyObject (readonly)

Returns the value of attribute rollout_strategy.


8
9
10
# File 'lib/gitlab/experimentation/experiment.rb', line 8

def rollout_strategy
  @rollout_strategy
end

#tracking_categoryObject (readonly)

Returns the value of attribute tracking_category.


8
9
10
# File 'lib/gitlab/experimentation/experiment.rb', line 8

def tracking_category
  @tracking_category
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)

16
17
18
19
20
21
22
# File 'lib/gitlab/experimentation/experiment.rb', line 16

def active?
  # TODO: just touch a feature flag
  # Temporary change, we will change `experiment_percentage` in future to `Feature.enabled?
  Feature.enabled?(feature_flag_name, type: :experiment)

  ::Gitlab.com? && experiment_percentage > 0
end

#enabled_for_index?(index) ⇒ Boolean

Returns:

  • (Boolean)

24
25
26
27
28
# File 'lib/gitlab/experimentation/experiment.rb', line 24

def enabled_for_index?(index)
  return false if index.blank?

  index <= experiment_percentage
end