Class: FeatureHub::Sdk::FeatureState
- Inherits:
-
Object
- Object
- FeatureHub::Sdk::FeatureState
- Defined in:
- lib/feature_hub/sdk/feature_state.rb
Overview
represents internal state of a feature
Instance Attribute Summary collapse
-
#encoded_strategies ⇒ Object
readonly
Returns the value of attribute encoded_strategies.
-
#internal_feature_state ⇒ Object
readonly
Returns the value of attribute internal_feature_state.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Instance Method Summary collapse
- #boolean ⇒ Object
- #enabled? ⇒ Boolean
- #exists?(top_feature = nil) ⇒ Boolean
- #feature_state ⇒ Object
- #feature_type ⇒ Object
- #flag ⇒ Object
- #id ⇒ Object
-
#initialize(key, repo, feature_state = nil, parent_state = nil, ctx = nil) ⇒ FeatureState
constructor
A new instance of FeatureState.
- #locked? ⇒ Boolean
- #number ⇒ Object
- #raw_json ⇒ Object
- #set? ⇒ Boolean
- #string ⇒ Object
- #top_feature_state ⇒ Object
- #update_feature_state(feature_state) ⇒ Object
- #value ⇒ Object
- #version ⇒ Object
- #with_context(ctx) ⇒ Object
Constructor Details
#initialize(key, repo, feature_state = nil, parent_state = nil, ctx = nil) ⇒ FeatureState
Returns a new instance of FeatureState.
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/feature_hub/sdk/feature_state.rb', line 9 def initialize(key, repo, feature_state = nil, parent_state = nil, ctx = nil) @key = key.to_sym @parent_state = parent_state @ctx = ctx @repo = repo @encoded_strategies = [] if feature_state _set_feature_state(feature_state) else @internal_feature_state = {} end end |
Instance Attribute Details
#encoded_strategies ⇒ Object (readonly)
Returns the value of attribute encoded_strategies.
7 8 9 |
# File 'lib/feature_hub/sdk/feature_state.rb', line 7 def encoded_strategies @encoded_strategies end |
#internal_feature_state ⇒ Object (readonly)
Returns the value of attribute internal_feature_state.
7 8 9 |
# File 'lib/feature_hub/sdk/feature_state.rb', line 7 def internal_feature_state @internal_feature_state end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
7 8 9 |
# File 'lib/feature_hub/sdk/feature_state.rb', line 7 def key @key end |
Instance Method Details
#boolean ⇒ Object
75 76 77 |
# File 'lib/feature_hub/sdk/feature_state.rb', line 75 def boolean get_value("BOOLEAN") end |
#enabled? ⇒ Boolean
83 84 85 |
# File 'lib/feature_hub/sdk/feature_state.rb', line 83 def enabled? boolean == true end |
#exists?(top_feature = nil) ⇒ Boolean
28 29 30 31 |
# File 'lib/feature_hub/sdk/feature_state.rb', line 28 def exists?(top_feature = nil) fs = top_feature || feature_state !(fs.empty? || fs["l"].nil?) end |
#feature_state ⇒ Object
50 51 52 |
# File 'lib/feature_hub/sdk/feature_state.rb', line 50 def feature_state top_feature_state.internal_feature_state end |
#feature_type ⇒ Object
37 38 39 40 |
# File 'lib/feature_hub/sdk/feature_state.rb', line 37 def feature_type fs = feature_state exists?(fs) ? fs["type"] : nil end |
#flag ⇒ Object
79 80 81 |
# File 'lib/feature_hub/sdk/feature_state.rb', line 79 def flag boolean end |
#id ⇒ Object
33 34 35 |
# File 'lib/feature_hub/sdk/feature_state.rb', line 33 def id exists? ? @internal_feature_state["id"] : nil end |
#locked? ⇒ Boolean
23 24 25 26 |
# File 'lib/feature_hub/sdk/feature_state.rb', line 23 def locked? fs = feature_state exists?(fs) ? fs["l"] : false end |
#number ⇒ Object
67 68 69 |
# File 'lib/feature_hub/sdk/feature_state.rb', line 67 def number get_value("NUMBER") end |
#raw_json ⇒ Object
71 72 73 |
# File 'lib/feature_hub/sdk/feature_state.rb', line 71 def raw_json get_value("JSON") end |
#set? ⇒ Boolean
87 88 89 |
# File 'lib/feature_hub/sdk/feature_state.rb', line 87 def set? !value.nil? end |
#string ⇒ Object
63 64 65 |
# File 'lib/feature_hub/sdk/feature_state.rb', line 63 def string get_value("STRING") end |
#top_feature_state ⇒ Object
91 92 93 94 95 |
# File 'lib/feature_hub/sdk/feature_state.rb', line 91 def top_feature_state return @parent_state&.top_feature_state if @parent_state self end |
#update_feature_state(feature_state) ⇒ Object
46 47 48 |
# File 'lib/feature_hub/sdk/feature_state.rb', line 46 def update_feature_state(feature_state) _set_feature_state(feature_state) end |
#value ⇒ Object
54 55 56 |
# File 'lib/feature_hub/sdk/feature_state.rb', line 54 def value get_value(feature_type) end |
#version ⇒ Object
58 59 60 61 |
# File 'lib/feature_hub/sdk/feature_state.rb', line 58 def version fs = feature_state exists?(fs) ? fs["version"] : -1 end |
#with_context(ctx) ⇒ Object
42 43 44 |
# File 'lib/feature_hub/sdk/feature_state.rb', line 42 def with_context(ctx) FeatureState.new(@key, @repo, nil, self, ctx) end |