Skip to content

Commit 56ccf17

Browse files
authored
fix: Add domain to build_client (#109)
Signed-off-by: William Kim <[email protected]>
1 parent e8fb8cc commit 56ccf17

File tree

5 files changed

+69
-17
lines changed

5 files changed

+69
-17
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@ We support multiple data types for flags (numbers, strings, booleans, objects) a
1212

1313
## Support Matrix
1414

15-
| Ruby Version | OS |
16-
| ----------- | ----------- |
17-
| Ruby 3.1.4 | Windows, MacOS, Linux |
18-
| Ruby 3.2.3 | Windows, MacOS, Linux |
19-
| Ruby 3.3.0 | Windows, MacOS, Linux |
20-
15+
| Ruby Version | OS |
16+
| ------------ | --------------------- |
17+
| Ruby 3.1.4 | Windows, MacOS, Linux |
18+
| Ruby 3.2.3 | Windows, MacOS, Linux |
19+
| Ruby 3.3.0 | Windows, MacOS, Linux |
2120

2221
## Installation
2322

@@ -54,7 +53,9 @@ OpenFeature::SDK.configure do |config|
5453
end
5554

5655
# Create a client
57-
client = OpenFeature::SDK.build_client(name: "my-app")
56+
client = OpenFeature::SDK.build_client
57+
# Create a client for a different domain, this will use the provider assigned to that domain
58+
legacy_flag_client = OpenFeature::SDK.build_client(domain: "legacy_flags")
5859

5960
# fetching boolean value feature flag
6061
bool_value = client.fetch_boolean_value(flag_key: 'boolean_flag', default_value: false)
@@ -102,7 +103,6 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to contribute to the O
102103

103104
Our community meetings are held regularly and open to everyone. Check the [OpenFeature community calendar](https://calendar.google.com/calendar/u/0?cid=MHVhN2kxaGl2NWRoMThiMjd0b2FoNjM2NDRAZ3JvdXAuY2FsZW5kYXIuZ29vZ2xlLmNvbQ) for specific dates and for the Zoom meeting links.
104105

105-
106106
## License
107107

108108
[Apache License 2.0](LICENSE)

lib/open_feature/sdk/api.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,12 @@ def configure(&block)
4242
block.call(configuration)
4343
end
4444

45-
def build_client(name: nil, version: nil)
46-
client_options = Metadata.new(name: name, version: version).freeze
47-
provider = Provider::NoOpProvider.new if provider.nil?
48-
Client.new(provider: provider, client_options: client_options, context: context)
45+
def build_client(name: nil, version: nil, domain: nil)
46+
client_options = Metadata.new(name: name, version: version, domain: domain).freeze
47+
48+
active_provider = provider(domain:).nil? ? Provider::NoOpProvider.new : provider(domain:)
49+
50+
Client.new(provider: active_provider, client_options:, context:)
4951
end
5052
end
5153
end

lib/open_feature/sdk/metadata.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,22 @@ module SDK
1010
#
1111
# * <tt>version</tt> - Allows you to specify version of the Metadata structure
1212
#
13+
# * <tt>domain</tt> - Allows you to specify the domain of the Metadata structure
14+
#
1315
# Usage:
1416
#
15-
# metadata = Metadata.new(name: 'name-for-metadata', version: 'v1.1.3')
17+
# metadata = Metadata.new(name: 'name-for-metadata', version: 'v1.1.3', domain: 'test')
1618
# metadata.name # 'name-for-metadata'
1719
# metadata.version # version
1820
# metadata_two = Metadata.new(name: 'name-for-metadata')
1921
# metadata_two == metadata # true - equality based on values
2022
class Metadata
21-
attr_reader :name, :version
23+
attr_reader :name, :version, :domain
2224

23-
def initialize(name:, version: nil)
25+
def initialize(name:, version: nil, domain: nil)
2426
@name = name
2527
@version = version
28+
@domain = domain
2629
end
2730

2831
def ==(other)

spec/open_feature/sdk/api_spec.rb

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
config.set_provider(OpenFeature::SDK::Provider::NoOpProvider.new)
5656
end
5757

58-
api.build_client(name: "requirement-1.1.5")
58+
api.build_client
5959
end
6060

6161
it "provide a function for creating a client which accepts the following options: * name (optional): A logical string identifier for the client." do
@@ -70,4 +70,49 @@
7070
context "with Requirement 1.1.6" do
7171
pending
7272
end
73+
74+
# TODO: These tests should be re-enabled when the client's provider is exposed via the metadata
75+
# See this PR for context: https://github.com/open-feature/ruby-sdk/pull/109
76+
77+
# context "when domain is given" do
78+
# it "can generate a client both with and without that domain" do
79+
# provider = OpenFeature::SDK::Provider::InMemoryProvider.new
80+
81+
# api.configure do |config|
82+
# config.set_provider(provider, domain: "testing1")
83+
# end
84+
85+
# client = api.build_client(domain: "testing1")
86+
# no_domain_client = api.build_client
87+
88+
# expect(client.provider).to be(provider)
89+
# expect(no_domain_client.provider).to be_an_instance_of(OpenFeature::SDK::Provider::NoOpProvider)
90+
# end
91+
# end
92+
93+
# context "when domain is not provided" do
94+
# it "can generate a client without a domain properly" do
95+
# provider = OpenFeature::SDK::Provider::InMemoryProvider.new
96+
97+
# api.configure do |config|
98+
# config.set_provider(provider)
99+
# end
100+
101+
# no_domain_client = api.build_client
102+
103+
# expect(no_domain_client.provider).to be(provider)
104+
# end
105+
106+
# it "can generate a client with a domain properly" do
107+
# api.configure do |config|
108+
# config.set_provider(OpenFeature::SDK::Provider::InMemoryProvider.new)
109+
# end
110+
111+
# domain_client = api.build_client(domain: "testing2")
112+
# # This domain was never given a provider, so it should default to the NoOpProvider
113+
# expect(domain_client.provider).to be_an_instance_of(OpenFeature::SDK::Provider::NoOpProvider)
114+
# end
115+
# end
116+
117+
# End Client provider metadata tests
73118
end

spec/open_feature/sdk/client_spec.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
RSpec.describe OpenFeature::SDK::Client do
88
subject(:client) { described_class.new(provider: provider, client_options: client_metadata) }
99
let(:provider) { OpenFeature::SDK::Provider::NoOpProvider.new }
10-
let(:client_metadata) { OpenFeature::SDK::Metadata.new(name: name) }
10+
let(:client_metadata) { OpenFeature::SDK::Metadata.new(name: name, domain: domain) }
11+
let(:domain) { "testing" }
1112
let(:name) { "my-openfeature-client" }
1213

1314
context "Requirement 1.2.1" do
@@ -28,6 +29,7 @@
2829
expect(client).to respond_to(:metadata)
2930
expect(client.metadata).to respond_to(:name)
3031
expect(client.metadata.name).to eq(name)
32+
expect(client.metadata.domain).to eq(domain)
3133
end
3234
end
3335

0 commit comments

Comments
 (0)