Class: PostHog::FeatureFlag

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json) ⇒ FeatureFlag

Returns a new instance of FeatureFlag.



8
9
10
11
12
13
14
15
# File 'lib/posthog/feature_flag.rb', line 8

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
end

Instance Attribute Details

#enabledObject (readonly)

Returns the value of attribute enabled.



6
7
8
# File 'lib/posthog/feature_flag.rb', line 6

def enabled
  @enabled
end

#keyObject (readonly)

Returns the value of attribute key.



6
7
8
# File 'lib/posthog/feature_flag.rb', line 6

def key
  @key
end

#metadataObject (readonly)

Returns the value of attribute metadata.



6
7
8
# File 'lib/posthog/feature_flag.rb', line 6

def 
  @metadata
end

#reasonObject (readonly)

Returns the value of attribute reason.



6
7
8
# File 'lib/posthog/feature_flag.rb', line 6

def reason
  @reason
end

#variantObject (readonly)

Returns the value of attribute variant.



6
7
8
# File 'lib/posthog/feature_flag.rb', line 6

def variant
  @variant
end

Class Method Details

.from_value_and_payload(key, value, payload) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/posthog/feature_flag.rb', line 26

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_valueObject

TODO: Rename to ‘value` in future version



18
19
20
# File 'lib/posthog/feature_flag.rb', line 18

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

#payloadObject



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

def payload
  @metadata&.payload
end