Class: LaunchDarkly::OpenFeature::Provider
- Inherits:
-
Object
- Object
- LaunchDarkly::OpenFeature::Provider
- Includes:
- OpenFeature::SDK::Provider::EventEmitter
- Defined in:
- lib/ldclient-openfeature/provider.rb
Instance Attribute Summary collapse
-
#client ⇒ LaunchDarkly::LDClient
readonly
Access the underlying LaunchDarky client instance backing this provider.
-
#metadata ⇒ ::OpenFeature::SDK::Provider::ProviderMetadata
readonly
Retrieve metadata information describing this provider.
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) ⇒ void
Called by the OpenFeature SDK when this provider is set.
-
#initialize(sdk_key, config = LaunchDarkly::Config.default, wait_for_seconds = 5) ⇒ Provider
constructor
A new instance of Provider.
-
#shutdown ⇒ void
Called by the OpenFeature SDK when this provider is replaced or the SDK is shut down.
-
#track(tracking_event_name, evaluation_context: nil, tracking_event_details: nil) ⇒ void
Track a custom event, which can be used as a metric for an experiment.
Constructor Details
#initialize(sdk_key, config = LaunchDarkly::Config.default, wait_for_seconds = 5) ⇒ Provider
Returns a new instance of Provider.
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/ldclient-openfeature/provider.rb', line 38 def initialize(sdk_key, config = LaunchDarkly::Config.default, wait_for_seconds = 5) @client = LaunchDarkly::LDClient.new(sdk_key, config.with_wrapper_information(WRAPPER_NAME, VERSION), wait_for_seconds) @logger = config.logger @context_converter = Impl::EvaluationContextConverter.new(config.logger) @details_converter = Impl::ResolutionDetailsConverter.new @metadata = ::OpenFeature::SDK::Provider::ProviderMetadata.new(name: "launchdarkly-openfeature-server").freeze @client.data_source_status_provider.add_listener(Impl::DataSourceStatusListener.new(self)) @client.flag_tracker.add_listener(Impl::FlagChangeListener.new(self)) end |
Instance Attribute Details
#client ⇒ LaunchDarkly::LDClient (readonly)
Access the underlying LaunchDarky client instance backing this provider.
This is useful for accessing additional functionality not exposed by the provider.
25 26 27 |
# File 'lib/ldclient-openfeature/provider.rb', line 25 def client @client end |
#metadata ⇒ ::OpenFeature::SDK::Provider::ProviderMetadata (readonly)
Retrieve metadata information describing this provider.
16 17 18 |
# File 'lib/ldclient-openfeature/provider.rb', line 16 def @metadata end |
Instance Method Details
#fetch_boolean_value(flag_key:, default_value:, evaluation_context: nil) ⇒ Object
76 77 78 |
# File 'lib/ldclient-openfeature/provider.rb', line 76 def fetch_boolean_value(flag_key:, default_value:, evaluation_context: nil) resolve_value(:boolean, flag_key, default_value, evaluation_context) end |
#fetch_float_value(flag_key:, default_value:, evaluation_context: nil) ⇒ Object
92 93 94 |
# File 'lib/ldclient-openfeature/provider.rb', line 92 def fetch_float_value(flag_key:, default_value:, evaluation_context: nil) resolve_value(:float, flag_key, default_value, evaluation_context) end |
#fetch_integer_value(flag_key:, default_value:, evaluation_context: nil) ⇒ Object
88 89 90 |
# File 'lib/ldclient-openfeature/provider.rb', line 88 def fetch_integer_value(flag_key:, default_value:, evaluation_context: nil) resolve_value(:integer, flag_key, default_value, evaluation_context) end |
#fetch_number_value(flag_key:, default_value:, evaluation_context: nil) ⇒ Object
84 85 86 |
# File 'lib/ldclient-openfeature/provider.rb', line 84 def fetch_number_value(flag_key:, default_value:, evaluation_context: nil) resolve_value(:number, flag_key, default_value, evaluation_context) end |
#fetch_object_value(flag_key:, default_value:, evaluation_context: nil) ⇒ Object
96 97 98 |
# File 'lib/ldclient-openfeature/provider.rb', line 96 def fetch_object_value(flag_key:, default_value:, evaluation_context: nil) resolve_value(:object, flag_key, default_value, evaluation_context) end |
#fetch_string_value(flag_key:, default_value:, evaluation_context: nil) ⇒ Object
80 81 82 |
# File 'lib/ldclient-openfeature/provider.rb', line 80 def fetch_string_value(flag_key:, default_value:, evaluation_context: nil) resolve_value(:string, flag_key, default_value, evaluation_context) end |
#init(_evaluation_context = nil) ⇒ void
This method returns an undefined value.
Called by the OpenFeature SDK when this provider is set. The LaunchDarkly client has already been given the opportunity to initialize, so this only reports whether that succeeded.
59 60 61 62 63 64 |
# File 'lib/ldclient-openfeature/provider.rb', line 59 def init(_evaluation_context = nil) return if @client.initialized? state = @client.data_source_status_provider.status.state raise "the LaunchDarkly client was unable to initialize; the data source state is #{state}" end |
#shutdown ⇒ void
This method returns an undefined value.
Called by the OpenFeature SDK when this provider is replaced or the SDK is shut down. The LaunchDarkly client cannot be restarted, so a new provider instance is required afterward.
72 73 74 |
# File 'lib/ldclient-openfeature/provider.rb', line 72 def shutdown @client.close end |
#track(tracking_event_name, evaluation_context: nil, tracking_event_details: nil) ⇒ void
This method returns an undefined value.
Track a custom event, which can be used as a metric for an experiment.
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/ldclient-openfeature/provider.rb', line 109 def track(tracking_event_name, evaluation_context: nil, tracking_event_details: nil) if evaluation_context.nil? @logger.warn( "The track method was called without an evaluation context. No event will be sent to LaunchDarkly, " \ "because a context is required to associate the event with." ) return end ld_context = @context_converter.to_ld_context(evaluation_context) data = tracking_event_details&.fields data = nil if data.nil? || data.empty? @client.track(tracking_event_name, ld_context, data, tracking_event_details&.value) end |