Class: PostHog::FeatureFlagResult
- Inherits:
-
Object
- Object
- PostHog::FeatureFlagResult
- 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
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
-
#variant ⇒ Object
readonly
Returns the value of attribute variant.
Class Method Summary collapse
-
.from_value_and_payload(key, value, payload) ⇒ Object
Factory method to create from flag value and payload.
Instance Method Summary collapse
-
#enabled? ⇒ Boolean
Returns whether or not the feature flag evaluated as enabled.
-
#initialize(key:, enabled:, variant: nil, payload: nil) ⇒ FeatureFlagResult
constructor
A new instance of FeatureFlagResult.
-
#value ⇒ Object
Returns the effective value of the feature flag variant if present, otherwise enabled status.
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
#key ⇒ Object (readonly)
Returns the value of attribute key.
9 10 11 |
# File 'lib/posthog/feature_flag_result.rb', line 9 def key @key end |
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
9 10 11 |
# File 'lib/posthog/feature_flag_result.rb', line 9 def payload @payload end |
#variant ⇒ Object (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
25 26 27 |
# File 'lib/posthog/feature_flag_result.rb', line 25 def enabled? @enabled end |
#value ⇒ Object
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 |