Class: PostHog::FeatureFlag Private
- Inherits:
-
Object
- Object
- PostHog::FeatureFlag
- Defined in:
- lib/posthog/feature_flag.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Represents a feature flag returned by /flags v2.
Instance Attribute Summary collapse
- #enabled ⇒ Object readonly private
- #failed ⇒ Object readonly private
- #key ⇒ Object readonly private
- #metadata ⇒ Object readonly private
- #reason ⇒ Object readonly private
- #variant ⇒ Object readonly private
Class Method Summary collapse
Instance Method Summary collapse
-
#get_value ⇒ String, Boolean
private
TODO: Rename to ‘value` in future version.
-
#initialize(json) ⇒ FeatureFlag
constructor
private
A new instance of FeatureFlag.
-
#payload ⇒ Object?
private
The flag payload from metadata.
Constructor Details
#initialize(json) ⇒ FeatureFlag
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of FeatureFlag.
11 12 13 14 15 16 17 18 19 |
# File 'lib/posthog/feature_flag.rb', line 11 def initialize(json) json.transform_keys!(&:to_s) @key = json['key'] @enabled = json['enabled'] @variant = json['variant'] @reason = json['reason'] ? EvaluationReason.new(json['reason']) : nil @metadata = json['metadata'] ? FeatureFlagMetadata.new(json['metadata'].transform_keys(&:to_s)) : nil @failed = json['failed'] end |
Instance Attribute Details
#enabled ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
8 9 10 |
# File 'lib/posthog/feature_flag.rb', line 8 def enabled @enabled end |
#failed ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
8 9 10 |
# File 'lib/posthog/feature_flag.rb', line 8 def failed @failed end |
#key ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
8 9 10 |
# File 'lib/posthog/feature_flag.rb', line 8 def key @key end |
#metadata ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
8 9 10 |
# File 'lib/posthog/feature_flag.rb', line 8 def @metadata end |
#reason ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
8 9 10 |
# File 'lib/posthog/feature_flag.rb', line 8 def reason @reason end |
#variant ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
8 9 10 |
# File 'lib/posthog/feature_flag.rb', line 8 def variant @variant end |
Class Method Details
.from_value_and_payload(key, value, payload) ⇒ PostHog::FeatureFlag
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/posthog/feature_flag.rb', line 36 def self.from_value_and_payload(key, value, payload) new({ 'key' => key, 'enabled' => value.is_a?(String) || value, 'variant' => value.is_a?(String) ? value : nil, 'reason' => nil, 'metadata' => { 'id' => nil, 'version' => nil, 'payload' => payload, 'description' => nil } }) end |
Instance Method Details
#get_value ⇒ String, Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
TODO: Rename to ‘value` in future version
23 24 25 |
# File 'lib/posthog/feature_flag.rb', line 23 def get_value # rubocop:disable Naming/AccessorMethodName @variant || @enabled end |
#payload ⇒ Object?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns The flag payload from metadata.
28 29 30 |
# File 'lib/posthog/feature_flag.rb', line 28 def payload @metadata&.payload end |