Class: Mixpanel::Flags::FallbackReason

Inherits:
Object
  • Object
show all
Defined in:
lib/mixpanel-ruby/flags/types.rb

Overview

Why the SDK returned the developer fallback. Only meaningful when SelectedVariant#variant_source == VariantSource::FALLBACK.

kind is the discriminator (matches the PHP constant set). message is set on the reasons that carry useful detail (BACKEND_ERROR with the backend's response, MISSING_CONTEXT_KEY with the missing attribute); nil otherwise. The OpenFeature wrapper dispatches on kind and forwards message into ResolutionDetails#error_message.

Constant Summary collapse

KINDS =
%i[flag_not_found missing_context_key no_rollout_match backend_error].freeze
FLAG_NOT_FOUND =
new(:flag_not_found)
NO_ROLLOUT_MATCH =
new(:no_rollout_match)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(kind, message: nil) ⇒ FallbackReason

Returns a new instance of FallbackReason.

Raises:

  • (ArgumentError)


25
26
27
28
29
30
31
# File 'lib/mixpanel-ruby/flags/types.rb', line 25

def initialize(kind, message: nil)
  raise ArgumentError, "Unknown FallbackReason kind: #{kind.inspect}" unless KINDS.include?(kind)

  @kind = kind
  @message = message
  freeze
end

Instance Attribute Details

#kindObject (readonly)

Returns the value of attribute kind.



23
24
25
# File 'lib/mixpanel-ruby/flags/types.rb', line 23

def kind
  @kind
end

#messageObject (readonly)

Returns the value of attribute message.



23
24
25
# File 'lib/mixpanel-ruby/flags/types.rb', line 23

def message
  @message
end

Class Method Details

.backend_error(message) ⇒ Object



51
# File 'lib/mixpanel-ruby/flags/types.rb', line 51

def self.backend_error(message); new(:backend_error, message: message); end

.flag_not_foundObject

Factory methods. Reasons without meaningful detail return a frozen singleton; reasons with detail allocate per call.



48
# File 'lib/mixpanel-ruby/flags/types.rb', line 48

def self.flag_not_found;      FLAG_NOT_FOUND;   end

.missing_context_key(key = nil) ⇒ Object



50
# File 'lib/mixpanel-ruby/flags/types.rb', line 50

def self.missing_context_key(key = nil); new(:missing_context_key, message: key); end

.no_rollout_matchObject



49
# File 'lib/mixpanel-ruby/flags/types.rb', line 49

def self.no_rollout_match;    NO_ROLLOUT_MATCH; end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



33
34
35
# File 'lib/mixpanel-ruby/flags/types.rb', line 33

def ==(other)
  other.is_a?(FallbackReason) && other.kind == @kind && other.message == @message
end

#hashObject



38
39
40
# File 'lib/mixpanel-ruby/flags/types.rb', line 38

def hash
  [self.class, @kind, @message].hash
end

#to_hObject



42
43
44
# File 'lib/mixpanel-ruby/flags/types.rb', line 42

def to_h
  { kind: @kind, message: @message }.compact
end