Class: OpenFeature::Rollout::Provider
- Inherits:
-
Object
- Object
- OpenFeature::Rollout::Provider
- Defined in:
- lib/openfeature/rollout/provider.rb
Overview
Provider represents the entry point for interacting with the rollout provider values. The implementation follows the details specified in openfeature.dev/docs/specification/sections/providers
Provider contains functionality to configure the redis connection via
rollout_client = OpenFeature::Rollout::Provider.build_client
rollout_client.configure do |config|
config.redis = Redis.new
end
The Provider provides the following methods and attributes:
-
metadata
- Returns the associated provider metadata with the name -
resolve_boolean_value(flag_key:, default_value:, context: nil)
manner;client.resolve_boolean(flag_key: 'boolean-flag', default_value: false)
-
resolve_integer_value(flag_key:, default_value:, context: nil)
manner;client.resolve_integer_value(flag_key: 'integer-flag', default_value: 2)
-
resolve_float_value(flag_key:, default_value:, context: nil)
manner;client.resolve_float_value(flag_key: 'float-flag', default_value: 2.0)
-
resolve_string_value(flag_key:, default_value:, context: nil)
manner;client.resolve_string_value(flag_key: 'string-flag', default_value: 'some-default-value')
-
resolve_object_value(flag_key:, default_value:, context: nil)
manner;client.resolve_object_value(flag_key: 'object-flag', default_value: { default_value: 'value'})
Constant Summary collapse
- PROVIDER_NAME =
"rollout Provider"
Instance Attribute Summary collapse
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
Class Method Summary collapse
Instance Method Summary collapse
- #error_response(default_value, error_code, error_message) ⇒ Object
- #fetch_boolean_value(flag_key:, default_value: false, evaluation_context: nil) ⇒ Object
- #fetch_float_value(flag_key:, default_value: nil, evaluation_context: nil) ⇒ Object
- #fetch_integer_value(flag_key:, default_value: nil, evaluation_context: nil) ⇒ Object
- #fetch_number_value(flag_key:, default_value: nil, evaluation_context: nil) ⇒ Object
- #fetch_object_value(flag_key:, default_value: nil, evaluation_context: nil) ⇒ Object
- #fetch_string_value(flag_key:, default_value: nil, evaluation_context: nil) ⇒ Object
-
#initialize(rollout_client: nil) ⇒ Provider
constructor
A new instance of Provider.
Constructor Details
#initialize(rollout_client: nil) ⇒ Provider
Returns a new instance of Provider.
49 50 51 52 |
# File 'lib/openfeature/rollout/provider.rb', line 49 def initialize(rollout_client: nil) @metadata = OpenFeature::SDK::Provider::ProviderMetadata.new(name: PROVIDER_NAME) @rollout_client = rollout_client end |
Instance Attribute Details
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
47 48 49 |
# File 'lib/openfeature/rollout/provider.rb', line 47 def @metadata end |
Class Method Details
.build_client(rollout_client = nil) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/openfeature/rollout/provider.rb', line 37 def self.build_client(rollout_client = nil) unless rollout_client rollout_client = ::Rollout.new(Redis.new) end new(rollout_client: rollout_client) end |
Instance Method Details
#error_response(default_value, error_code, error_message) ⇒ Object
87 88 89 90 91 92 93 94 95 96 |
# File 'lib/openfeature/rollout/provider.rb', line 87 def error_response(default_value, error_code, ) OpenFeature::SDK::Provider::ResolutionDetails.new( value: default_value, reason: "ERROR", variant: nil, error_code: error_code, error_message: , flag_metadata: nil ) end |
#fetch_boolean_value(flag_key:, default_value: false, evaluation_context: nil) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/openfeature/rollout/provider.rb', line 54 def fetch_boolean_value(flag_key:, default_value: false, evaluation_context: nil) res = @rollout_client.active?(flag_key, evaluation_context&.targeting_key) OpenFeature::SDK::Provider::ResolutionDetails.new( value: res, reason: "UNKNOWN", # "STATIC", "DEFAULT", "TARGETING_MATCH", "SPLIT", "CACHED", "DISABLED", "UNKNOWN", "STALE", "ERROR" variant: nil, error_code: nil, error_message: nil, flag_metadata: nil ) end |
#fetch_float_value(flag_key:, default_value: nil, evaluation_context: nil) ⇒ Object
75 76 77 |
# File 'lib/openfeature/rollout/provider.rb', line 75 def fetch_float_value(flag_key:, default_value: nil, evaluation_context: nil) error_response(default_value, "TYPE_MISMATCH", "Rollout does not support numeric flag values") end |
#fetch_integer_value(flag_key:, default_value: nil, evaluation_context: nil) ⇒ Object
71 72 73 |
# File 'lib/openfeature/rollout/provider.rb', line 71 def fetch_integer_value(flag_key:, default_value: nil, evaluation_context: nil) error_response(default_value, "TYPE_MISMATCH", "Rollout does not support numeric flag values") end |
#fetch_number_value(flag_key:, default_value: nil, evaluation_context: nil) ⇒ Object
67 68 69 |
# File 'lib/openfeature/rollout/provider.rb', line 67 def fetch_number_value(flag_key:, default_value: nil, evaluation_context: nil) error_response(default_value, "TYPE_MISMATCH", "Rollout does not support numeric flag values") end |
#fetch_object_value(flag_key:, default_value: nil, evaluation_context: nil) ⇒ Object
83 84 85 |
# File 'lib/openfeature/rollout/provider.rb', line 83 def fetch_object_value(flag_key:, default_value: nil, evaluation_context: nil) error_response(default_value, "TYPE_MISMATCH", "Rollout does not support object flag values") end |
#fetch_string_value(flag_key:, default_value: nil, evaluation_context: nil) ⇒ Object
79 80 81 |
# File 'lib/openfeature/rollout/provider.rb', line 79 def fetch_string_value(flag_key:, default_value: nil, evaluation_context: nil) error_response(default_value, "TYPE_MISMATCH", "Rollout does not support string flag values") end |