Class: FeatureHub::Sdk::FeatureStateHolder
- Inherits:
-
Object
- Object
- FeatureHub::Sdk::FeatureStateHolder
- Defined in:
- lib/feature_hub/sdk/feature_state_holder.rb,
sig/feature_hub/featurehub.rbs
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 ⇒ FeatureState
readonly
this is strictly the internal feature state, further down from the top level it will be nil.
-
#key ⇒ Symbol
readonly
Returns the value of attribute key.
Instance Method Summary collapse
- #_feature_state ⇒ FeatureState
- #_set_feature_state(feature_state) ⇒ void
- #boolean ⇒ Boolean?
- #enabled? ⇒ Boolean
- #exists?(top_feature = nil) ⇒ Boolean
- #feature_properties ⇒ Hash[String, String]
-
#feature_state ⇒ FeatureState
this is the feature state of the top level, it always walks up.
- #feature_type ⇒ String?
- #flag ⇒ Boolean?
- #get_value(feature_type) ⇒ [bool? | String? | Float?]
- #id ⇒ String?
-
#initialize(key, repo, feature_state = nil, parent_state = nil, ctx = nil) ⇒ FeatureStateHolder
constructor
A new instance of FeatureStateHolder.
- #locked? ⇒ Boolean
- #number ⇒ Float
- #phantom? ⇒ Boolean
- #present? ⇒ Boolean
- #raw_json ⇒ String?
- #set? ⇒ Boolean
- #string ⇒ String?
- #top_feature_state ⇒ FeatureStateHolder
- #update_feature_state(feature_state) ⇒ void
- #value ⇒ [bool? | String? | Float?]
- #version ⇒ int
- #with_context(ctx) ⇒ FeatureStateHolder
Constructor Details
#initialize(key, repo, feature_state = nil, parent_state = nil, ctx = nil) ⇒ FeatureStateHolder
Returns a new instance of FeatureStateHolder.
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/feature_hub/sdk/feature_state_holder.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_holder.rb', line 7 def encoded_strategies @encoded_strategies end |
#internal_feature_state ⇒ FeatureState (readonly)
this is strictly the internal feature state, further down from the top level it will be nil
79 80 81 |
# File 'sig/feature_hub/featurehub.rbs', line 79 def internal_feature_state @internal_feature_state end |
#key ⇒ Symbol (readonly)
Returns the value of attribute key.
7 8 9 |
# File 'lib/feature_hub/sdk/feature_state_holder.rb', line 7 def key @key end |
Instance Method Details
#_feature_state ⇒ FeatureState
114 115 116 |
# File 'lib/feature_hub/sdk/feature_state_holder.rb', line 114 def _feature_state @internal_feature_state end |
#_set_feature_state(feature_state) ⇒ void
This method returns an undefined value.
118 119 120 121 122 |
# File 'lib/feature_hub/sdk/feature_state_holder.rb', line 118 def _set_feature_state(feature_state) @internal_feature_state = feature_state || {} found_strategies = feature_state["strategies"] || [] @encoded_strategies = found_strategies.map { |s| FeatureHub::Sdk::Impl::RolloutStrategy.new(s) } end |
#boolean ⇒ Boolean?
84 85 86 |
# File 'lib/feature_hub/sdk/feature_state_holder.rb', line 84 def boolean get_value(FeatureValueType::BOOLEAN) end |
#enabled? ⇒ Boolean
92 93 94 |
# File 'lib/feature_hub/sdk/feature_state_holder.rb', line 92 def enabled? boolean == true end |
#exists?(top_feature = nil) ⇒ Boolean
28 29 30 31 |
# File 'lib/feature_hub/sdk/feature_state_holder.rb', line 28 def exists?(top_feature = nil) fs = top_feature || feature_state !(fs.empty? || fs["l"].nil?) end |
#feature_properties ⇒ Hash[String, String]
46 47 48 49 |
# File 'lib/feature_hub/sdk/feature_state_holder.rb', line 46 def feature_properties fs = feature_state (exists?(fs) ? fs["fp"] : {}) || {} end |
#feature_state ⇒ FeatureState
this is the feature state of the top level, it always walks up
76 77 78 |
# File 'sig/feature_hub/featurehub.rbs', line 76 def feature_state top_feature_state.internal_feature_state end |
#feature_type ⇒ String?
41 42 43 44 |
# File 'lib/feature_hub/sdk/feature_state_holder.rb', line 41 def feature_type fs = feature_state exists?(fs) ? fs["type"] : nil end |
#flag ⇒ Boolean?
88 89 90 |
# File 'lib/feature_hub/sdk/feature_state_holder.rb', line 88 def flag boolean end |
#get_value(feature_type) ⇒ [bool? | String? | Float?]
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/feature_hub/sdk/feature_state_holder.rb', line 124 def get_value(feature_type) unless locked? matched, intercept_value = @repo.find_interceptor(@key, top_feature_state.feature_state) return intercept_value if matched end fs = top_feature_state state = fs.internal_feature_state return nil if state.nil? return nil if fs.nil? || (!feature_type.nil? && fs.feature_type != feature_type) if @ctx matched = @repo.apply(fs.encoded_strategies, @key, fs.id, @ctx) return matched.value if matched.matched end state["value"] end |
#id ⇒ String?
37 38 39 |
# File 'lib/feature_hub/sdk/feature_state_holder.rb', line 37 def id exists? ? @internal_feature_state["id"] : nil end |
#locked? ⇒ Boolean
23 24 25 26 |
# File 'lib/feature_hub/sdk/feature_state_holder.rb', line 23 def locked? fs = feature_state exists?(fs) ? fs["l"] : false end |
#number ⇒ Float
76 77 78 |
# File 'lib/feature_hub/sdk/feature_state_holder.rb', line 76 def number get_value(FeatureValueType::NUMBER) end |
#phantom? ⇒ Boolean
100 101 102 103 104 |
# File 'lib/feature_hub/sdk/feature_state_holder.rb', line 100 def phantom? return @parent_state&.phantom? unless @parent_state.nil? @internal_feature_state.empty? end |
#present? ⇒ Boolean
33 34 35 |
# File 'lib/feature_hub/sdk/feature_state_holder.rb', line 33 def present? exists? end |
#raw_json ⇒ String?
80 81 82 |
# File 'lib/feature_hub/sdk/feature_state_holder.rb', line 80 def raw_json get_value(FeatureValueType::JSON) end |
#set? ⇒ Boolean
96 97 98 |
# File 'lib/feature_hub/sdk/feature_state_holder.rb', line 96 def set? !value.nil? end |
#string ⇒ String?
72 73 74 |
# File 'lib/feature_hub/sdk/feature_state_holder.rb', line 72 def string get_value(FeatureValueType::STRING) end |
#top_feature_state ⇒ FeatureStateHolder
106 107 108 109 110 |
# File 'lib/feature_hub/sdk/feature_state_holder.rb', line 106 def top_feature_state return @parent_state&.top_feature_state if @parent_state self end |
#update_feature_state(feature_state) ⇒ void
This method returns an undefined value.
55 56 57 |
# File 'lib/feature_hub/sdk/feature_state_holder.rb', line 55 def update_feature_state(feature_state) _set_feature_state(feature_state) end |
#value ⇒ [bool? | String? | Float?]
63 64 65 |
# File 'lib/feature_hub/sdk/feature_state_holder.rb', line 63 def value get_value(feature_type) end |
#version ⇒ int
67 68 69 70 |
# File 'lib/feature_hub/sdk/feature_state_holder.rb', line 67 def version fs = feature_state exists?(fs) ? fs["version"] : -1 end |
#with_context(ctx) ⇒ FeatureStateHolder
51 52 53 |
# File 'lib/feature_hub/sdk/feature_state_holder.rb', line 51 def with_context(ctx) FeatureStateHolder.new(@key, @repo, nil, self, ctx) end |