Class: PostHog::FeatureFlag
- Inherits:
-
Object
- Object
- PostHog::FeatureFlag
- Defined in:
- lib/posthog/feature_flag.rb
Instance Attribute Summary collapse
-
#enabled ⇒ Object
readonly
Returns the value of attribute enabled.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#reason ⇒ Object
readonly
Returns the value of attribute reason.
-
#variant ⇒ Object
readonly
Returns the value of attribute variant.
Class Method Summary collapse
Instance Method Summary collapse
-
#get_value ⇒ Object
TODO: Rename to ‘value` in future version.
-
#initialize(json) ⇒ FeatureFlag
constructor
A new instance of FeatureFlag.
- #payload ⇒ Object
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
#enabled ⇒ Object (readonly)
Returns the value of attribute enabled.
6 7 8 |
# File 'lib/posthog/feature_flag.rb', line 6 def enabled @enabled end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
6 7 8 |
# File 'lib/posthog/feature_flag.rb', line 6 def key @key end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
6 7 8 |
# File 'lib/posthog/feature_flag.rb', line 6 def @metadata end |
#reason ⇒ Object (readonly)
Returns the value of attribute reason.
6 7 8 |
# File 'lib/posthog/feature_flag.rb', line 6 def reason @reason end |
#variant ⇒ Object (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_value ⇒ Object
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 |
#payload ⇒ Object
22 23 24 |
# File 'lib/posthog/feature_flag.rb', line 22 def payload @metadata&.payload end |