Module: Gitlab::Experiment::BaseInterface
- Extended by:
- ActiveSupport::Concern
- Includes:
- Scientist::Experiment
- Included in:
- Gitlab::Experiment
- Defined in:
- lib/gitlab/experiment/base_interface.rb
Instance Method Summary collapse
- #behaviors ⇒ Object
- #flipper_id ⇒ Object
- #id ⇒ Object (also: #session_id, #to_param)
- #initialize(name = nil, variant_name = nil, **context) {|_self| ... } ⇒ Object
- #inspect ⇒ Object
- #variant_names ⇒ Object
Instance Method Details
#behaviors ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'lib/gitlab/experiment/base_interface.rb', line 66 def behaviors @behaviors ||= public_methods.each_with_object(super) do |name, behaviors| next unless name.end_with?('_behavior') behavior_name = name.to_s.sub(/_behavior$/, '') behaviors[behavior_name] ||= -> { send(name) } # rubocop:disable GitlabSecurity/PublicSend end end |
#flipper_id ⇒ Object
58 59 60 |
# File 'lib/gitlab/experiment/base_interface.rb', line 58 def flipper_id "Experiment;#{id}" end |
#id ⇒ Object Also known as: session_id, to_param
52 53 54 |
# File 'lib/gitlab/experiment/base_interface.rb', line 52 def id "#{name}:#{context.key}" end |
#initialize(name = nil, variant_name = nil, **context) {|_self| ... } ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/gitlab/experiment/base_interface.rb', line 36 def initialize(name = nil, variant_name = nil, **context) raise ArgumentError, 'name is required' if name.blank? && self.class.base? @name = self.class.experiment_name(name, suffix: false) @context = Context.new(self, **context) @variant_name = cache_variant(variant_name) { nil } if variant_name.present? compare { false } yield self if block_given? end |
#inspect ⇒ Object
48 49 50 |
# File 'lib/gitlab/experiment/base_interface.rb', line 48 def inspect "#<#{self.class.name || 'AnonymousClass'}:#{format('0x%016X', __id__)} @name=#{name} @context=#{context.value}>" end |
#variant_names ⇒ Object
62 63 64 |
# File 'lib/gitlab/experiment/base_interface.rb', line 62 def variant_names @variant_names ||= behaviors.keys.map(&:to_sym) - [:control] end |