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)
- #initialize(name = nil, variant_name = nil, **context) {|_self| ... } ⇒ Object
- #inspect ⇒ Object
- #variant_names ⇒ Object
Instance Method Details
#behaviors ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'lib/gitlab/experiment/base_interface.rb', line 60 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
52 53 54 |
# File 'lib/gitlab/experiment/base_interface.rb', line 52 def flipper_id "Experiment;#{id}" end |
#id ⇒ Object Also known as: session_id
47 48 49 |
# File 'lib/gitlab/experiment/base_interface.rb', line 47 def id "#{name}:#{key_for(context.value)}" end |
#initialize(name = nil, variant_name = nil, **context) {|_self| ... } ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/gitlab/experiment/base_interface.rb', line 31 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
43 44 45 |
# File 'lib/gitlab/experiment/base_interface.rb', line 43 def inspect "#<#{self.class.name || 'AnonymousClass'}:#{format('0x%016X', __id__)} @name=#{name} @context=#{context.value}>" end |
#variant_names ⇒ Object
56 57 58 |
# File 'lib/gitlab/experiment/base_interface.rb', line 56 def variant_names @variant_names ||= behaviors.keys.map(&:to_sym) - [:control] end |