Skip to content

Commit 720e235

Browse files
committed
Update documentation and tests
1 parent 80895e2 commit 720e235

File tree

5 files changed

+57
-12
lines changed

5 files changed

+57
-12
lines changed

README.md

Lines changed: 7 additions & 7 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

@@ -55,6 +54,8 @@ end
5554

5655
# Create a client
5756
client = OpenFeature::SDK.build_client(name: "my-app")
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(name: "Legacy", 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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,11 @@ def configure(&block)
4343
end
4444

4545
def build_client(name: nil, version: nil, domain: nil)
46-
client_options = Metadata.new(name: name, version: version).freeze
46+
client_options = Metadata.new(name: name, version: version, domain: domain).freeze
4747

48+
pp domain
4849
active_provider = provider(domain:).nil? ? Provider::NoOpProvider.new : provider(domain:)
50+
pp active_provider
4951

5052
Client.new(provider: active_provider, client_options: client_options, context: context)
5153
end

lib/open_feature/sdk/client.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class Client
88
RESULT_TYPE = %i[boolean string number object].freeze
99
SUFFIXES = %i[value details].freeze
1010

11-
attr_reader :metadata
11+
attr_reader :metadata, :provider
1212

1313
attr_accessor :hooks
1414

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: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,44 @@
7070
context "with Requirement 1.1.6" do
7171
pending
7272
end
73+
74+
context "when domain is given" do
75+
it "can generate a client both with and without that domain" do
76+
provider = OpenFeature::SDK::Provider::InMemoryProvider.new
77+
78+
api.configure do |config|
79+
config.set_provider(provider, domain: 'testing1')
80+
end
81+
82+
client = api.build_client(name: "with-domain", domain: "testing1")
83+
no_domain_client = api.build_client(name: "without-domain")
84+
85+
expect(client.provider).to be(provider)
86+
expect(no_domain_client.provider).to be_an_instance_of(OpenFeature::SDK::Provider::NoOpProvider)
87+
end
88+
end
89+
90+
context "when domain is not provided" do
91+
it "can generate a client without a domain properly" do
92+
provider = OpenFeature::SDK::Provider::InMemoryProvider.new
93+
94+
api.configure do |config|
95+
config.set_provider(provider)
96+
end
97+
98+
no_domain_client = api.build_client(name: "without-domain")
99+
100+
expect(no_domain_client.provider).to be(provider)
101+
end
102+
103+
it "can generate a client with a domain properly" do
104+
api.configure do |config|
105+
config.set_provider(OpenFeature::SDK::Provider::InMemoryProvider.new)
106+
end
107+
108+
domain_client = api.build_client(name: "with-domain", domain: "testing2")
109+
# This domain was never given a provider, so it should default to the NoOpProvider
110+
expect(domain_client.provider).to be_an_instance_of(OpenFeature::SDK::Provider::NoOpProvider)
111+
end
112+
end
73113
end

0 commit comments

Comments
 (0)