Class: OpenFeature::SDK::API

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Singleton
Defined in:
lib/open_feature/sdk/api.rb

Overview

API Initialization and Configuration

Represents the entry point to the API, including configuration of Provider,Hook, and building the Client

To use the SDK, you can optionally configure a Provider, with Hook

OpenFeature::SDK::API.instance.configure do |config|
  config.set_provider NoOpProvider.new
end

If no provider is specified, the NoOpProvider is set as the default Provider. Once the SDK has been configured, a client can be built

client = OpenFeature::SDK::API.instance.build_client(name: 'my-open-feature-client')

Instance Method Summary collapse

Instance Method Details

#build_client(domain: nil, evaluation_context: nil) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/open_feature/sdk/api.rb', line 47

def build_client(domain: nil, evaluation_context: nil)
  active_provider = provider(domain:).nil? ? Provider::NoOpProvider.new : provider(domain:)

  Client.new(provider: active_provider, domain:, evaluation_context:)
rescue
  Client.new(provider: Provider::NoOpProvider.new, evaluation_context:)
end

#configurationObject



37
38
39
# File 'lib/open_feature/sdk/api.rb', line 37

def configuration
  @configuration ||= Configuration.new
end

#configure(&block) ⇒ Object



41
42
43
44
45
# File 'lib/open_feature/sdk/api.rb', line 41

def configure(&block)
  return unless block

  block.call(configuration)
end