Module: Gitlab::Experiment::Dsl
- Defined in:
- lib/gitlab/experiment/dsl.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#experiment(name, variant_name = nil, **context, &block) ⇒ Object
An explicit ‘request:` keyword argument always takes precedence; when present, no auto-detection runs.
Class Method Details
.include_in(klass, with_helper: false) ⇒ Object
6 7 8 |
# File 'lib/gitlab/experiment/dsl.rb', line 6 def self.include_in(klass, with_helper: false) klass.include(self).tap { |base| base.helper_method(:experiment) if with_helper } end |
Instance Method Details
#experiment(name, variant_name = nil, **context, &block) ⇒ Object
An explicit ‘request:` keyword argument always takes precedence; when present, no auto-detection runs.
Otherwise, ‘request` is auto-detected through implicit_experiment_request in this order:
1. A `request` method on `self` (the controller pattern).
2. A `@request` instance variable on `self` (the service pattern).
Callers with ‘request` as a pure local variable should pass `request: request` explicitly.
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/gitlab/experiment/dsl.rb', line 19 def experiment(name, variant_name = nil, **context, &block) raise ArgumentError, 'name is required' if name.nil? context[:request] ||= implicit_experiment_request base = Configuration.base_class.constantize klass = base.constantize(name) || base instance = klass.new(name, variant_name, **context, &block) return instance unless block instance.context.frozen? ? instance.run : instance.tap(&:run) end |