Class: PostHog::FeatureFlag Private

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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.

Parameters:

  • json (Hash)

    Raw feature flag data returned by /flags.



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

#enabledObject (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

#failedObject (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

#keyObject (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

#metadataObject (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

#reasonObject (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

#variantObject (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.

Parameters:

  • key (String, Symbol)

    The feature flag key.

  • value (String, Boolean)

    The feature flag value.

  • payload (Object, nil)

    The feature flag payload.

Returns:



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_valueString, 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

Returns:

  • (String, Boolean)

    The variant value when present, otherwise the enabled status.



23
24
25
# File 'lib/posthog/feature_flag.rb', line 23

def get_value # rubocop:disable Naming/AccessorMethodName
  @variant || @enabled
end

#payloadObject?

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.

Returns:

  • (Object, nil)

    The flag payload from metadata.



28
29
30
# File 'lib/posthog/feature_flag.rb', line 28

def payload
  @metadata&.payload
end