Class: PostHog::FeatureFlagResult

Inherits:
Object
  • Object
show all
Defined in:
lib/posthog/feature_flag_result.rb

Overview

Represents the result of a feature flag evaluation containing both the flag value and payload

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key:, enabled:, variant: nil, payload: nil) ⇒ FeatureFlagResult

Returns a new instance of FeatureFlagResult.



11
12
13
14
15
16
# File 'lib/posthog/feature_flag_result.rb', line 11

def initialize(key:, enabled:, variant: nil, payload: nil)
  @key = key
  @enabled = enabled
  @variant = variant
  @payload = payload
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



9
10
11
# File 'lib/posthog/feature_flag_result.rb', line 9

def key
  @key
end

#payloadObject (readonly)

Returns the value of attribute payload.



9
10
11
# File 'lib/posthog/feature_flag_result.rb', line 9

def payload
  @payload
end

#variantObject (readonly)

Returns the value of attribute variant.



9
10
11
# File 'lib/posthog/feature_flag_result.rb', line 9

def variant
  @variant
end

Class Method Details

.from_value_and_payload(key, value, payload) ⇒ Object

Factory method to create from flag value and payload



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/posthog/feature_flag_result.rb', line 30

def self.from_value_and_payload(key, value, payload)
  return nil if value.nil?

  parsed_payload = parse_payload(payload)

  if value.is_a?(String)
    new(key: key, enabled: true, variant: value, payload: parsed_payload)
  else
    new(key: key, enabled: value, payload: parsed_payload)
  end
end

Instance Method Details

#enabled?Boolean

Returns whether or not the feature flag evaluated as enabled

Returns:

  • (Boolean)


25
26
27
# File 'lib/posthog/feature_flag_result.rb', line 25

def enabled?
  @enabled
end

#valueObject

Returns the effective value of the feature flag variant if present, otherwise enabled status



20
21
22
# File 'lib/posthog/feature_flag_result.rb', line 20

def value
  @variant || @enabled
end