Class: Unleash::OpenFeature::Provider::UnleashFlagProvider
- Inherits:
-
Object
- Object
- Unleash::OpenFeature::Provider::UnleashFlagProvider
- Defined in:
- lib/unleash/open_feature/provider/unleash_flag_provider.rb
Constant Summary collapse
- NAME =
'Unleash OpenFeature Provider'
Instance Attribute Summary collapse
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
Instance Method Summary collapse
- #fetch_boolean_value(flag_key:, default_value:, evaluation_context: nil) ⇒ Object
- #fetch_float_value(flag_key:, default_value:, evaluation_context: nil) ⇒ Object
- #fetch_integer_value(flag_key:, default_value:, evaluation_context: nil) ⇒ Object
- #fetch_number_value(flag_key:, default_value:, evaluation_context: nil) ⇒ Object
- #fetch_object_value(flag_key:, default_value:, evaluation_context: nil) ⇒ Object
- #fetch_string_value(flag_key:, default_value:, evaluation_context: nil) ⇒ Object
- #init(_evaluation_context = nil) ⇒ Object
-
#initialize(client, logger: Logger.new($stderr)) ⇒ UnleashFlagProvider
constructor
A new instance of UnleashFlagProvider.
- #shutdown ⇒ Object
Constructor Details
#initialize(client, logger: Logger.new($stderr)) ⇒ UnleashFlagProvider
Returns a new instance of UnleashFlagProvider.
16 17 18 19 20 |
# File 'lib/unleash/open_feature/provider/unleash_flag_provider.rb', line 16 def initialize(client, logger: Logger.new($stderr)) @client = client @logger = logger @metadata = ::OpenFeature::SDK::Provider::ProviderMetadata.new(name: NAME).freeze end |
Instance Attribute Details
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
14 15 16 |
# File 'lib/unleash/open_feature/provider/unleash_flag_provider.rb', line 14 def @metadata end |
Instance Method Details
#fetch_boolean_value(flag_key:, default_value:, evaluation_context: nil) ⇒ Object
32 33 34 35 36 |
# File 'lib/unleash/open_feature/provider/unleash_flag_provider.rb', line 32 def fetch_boolean_value(flag_key:, default_value:, evaluation_context: nil) context = Context.to_unleash_context(evaluation_context, logger:) value = client.is_enabled?(flag_key, context, default_value) resolution(value:, reason: reason::UNKNOWN) end |
#fetch_float_value(flag_key:, default_value:, evaluation_context: nil) ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'lib/unleash/open_feature/provider/unleash_flag_provider.rb', line 65 def fetch_float_value(flag_key:, default_value:, evaluation_context: nil) fetch_variant_value( flag_key:, default_value:, evaluation_context:, payload_types: %w[number] ) { |value| parse_float(value) } end |
#fetch_integer_value(flag_key:, default_value:, evaluation_context: nil) ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/unleash/open_feature/provider/unleash_flag_provider.rb', line 56 def fetch_integer_value(flag_key:, default_value:, evaluation_context: nil) fetch_variant_value( flag_key:, default_value:, evaluation_context:, payload_types: %w[number] ) { |value| parse_integer(value) } end |
#fetch_number_value(flag_key:, default_value:, evaluation_context: nil) ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/unleash/open_feature/provider/unleash_flag_provider.rb', line 47 def fetch_number_value(flag_key:, default_value:, evaluation_context: nil) fetch_variant_value( flag_key:, default_value:, evaluation_context:, payload_types: %w[number] ) { |value| parse_number(value) } end |
#fetch_object_value(flag_key:, default_value:, evaluation_context: nil) ⇒ Object
74 75 76 77 78 79 80 81 82 |
# File 'lib/unleash/open_feature/provider/unleash_flag_provider.rb', line 74 def fetch_object_value(flag_key:, default_value:, evaluation_context: nil) fetch_variant_value( flag_key:, default_value:, evaluation_context:, payload_types: %w[json], parse_error_code: error_code::PARSE_ERROR ) { |value| JSON.parse(value) } end |
#fetch_string_value(flag_key:, default_value:, evaluation_context: nil) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/unleash/open_feature/provider/unleash_flag_provider.rb', line 38 def fetch_string_value(flag_key:, default_value:, evaluation_context: nil) fetch_variant_value( flag_key:, default_value:, evaluation_context:, payload_types: %w[string csv], &:to_s ) end |
#init(_evaluation_context = nil) ⇒ Object
22 23 24 25 26 |
# File 'lib/unleash/open_feature/provider/unleash_flag_provider.rb', line 22 def init(_evaluation_context = nil) # Ruby SDK currently just spins itself up and does the thing # Leaving this here because long term plan is to actually have an init method # and when that happens this method here needs to get filled in end |
#shutdown ⇒ Object
28 29 30 |
# File 'lib/unleash/open_feature/provider/unleash_flag_provider.rb', line 28 def shutdown client.shutdown end |