Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions lib/ldclient-rb/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,27 @@ def diagnostic_opt_out?
#
attr_reader :wrapper_version

#
# Returns a copy of this configuration with different wrapper information.
#
# This is intended for use by wrapper libraries, such as the LaunchDarkly OpenFeature provider, which need to
# identify themselves rather than the application which created the configuration.
#
# @param wrapper_name [String, nil] see {#wrapper_name}
# @param wrapper_version [String, nil] see {#wrapper_version}
#
# @return [LaunchDarkly::Config]
#
def with_wrapper_information(wrapper_name, wrapper_version = nil)
updated = dup
updated.wrapper_name = wrapper_name
updated.wrapper_version = wrapper_version

updated
end

protected attr_writer :wrapper_name, :wrapper_version

#
# The factory used to construct sockets for HTTP operations. The factory must
# provide the method `open(uri, timeout)`. The `open` method must return a
Expand Down
28 changes: 28 additions & 0 deletions spec/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,34 @@ module LaunchDarkly
end
end
end
describe "with_wrapper_information" do
it "returns a copy with the provided wrapper information" do
config = subject.new(wrapper_name: "original", wrapper_version: "1.0.0", offline: true)

wrapped = config.with_wrapper_information("wrapper", "2.0.0")

expect(wrapped.wrapper_name).to eq "wrapper"
expect(wrapped.wrapper_version).to eq "2.0.0"
expect(wrapped.offline?).to eq true
end

it "does not modify the original configuration" do
config = subject.new(wrapper_name: "original", wrapper_version: "1.0.0")

config.with_wrapper_information("wrapper", "2.0.0")

expect(config.wrapper_name).to eq "original"
expect(config.wrapper_version).to eq "1.0.0"
end

it "defaults the wrapper version to nil" do
config = subject.new(wrapper_name: "original", wrapper_version: "1.0.0")

wrapped = config.with_wrapper_information("wrapper")

expect(wrapped.wrapper_version).to be_nil
end
end
describe ".omit_anonymous_contexts" do
it "defaults to false" do
expect(subject.new.omit_anonymous_contexts).to eq false
Expand Down
Loading