Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Updates to Provider module in preparation for InMemoryProvider #99

Merged
merged 7 commits into from
Feb 21, 2024
Merged
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
2 changes: 1 addition & 1 deletion bin/console
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# frozen_string_literal: true

require "bundler/setup"
require "openfeature/sdk"
require "open_feature/sdk"

# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.
Expand Down
7 changes: 3 additions & 4 deletions lib/open_feature/sdk/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
require "singleton"

require_relative "configuration"
require_relative "evaluation_details"
require_relative "client"
require_relative "metadata"
require_relative "provider/no_op_provider"
require_relative "provider"

module OpenFeature
module SDK
Expand All @@ -29,9 +30,7 @@ class API
include Singleton
extend Forwardable

def_delegator :@configuration, :provider
def_delegator :@configuration, :hooks
def_delegator :@configuration, :context
def_delegators :configuration, :provider, :hooks, :context

def configuration
@configuration ||= Configuration.new
Expand Down
5 changes: 3 additions & 2 deletions lib/open_feature/sdk/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ def initialize(provider:, client_options: nil, context: nil)
# result = @provider.fetch_boolean_value(flag_key: flag_key, default_value: default_value, evaluation_context: evaluation_context)
# end
def fetch_#{result_type}_#{suffix}(flag_key:, default_value:, evaluation_context: nil)
result = @provider.fetch_#{result_type}_value(flag_key: flag_key, default_value: default_value, evaluation_context: evaluation_context)
#{"result.value" if suffix == :value}
resolution_details = @provider.fetch_#{result_type}_value(flag_key:, default_value:, evaluation_context:)
evaluation_details = EvaluationDetails.new(flag_key:, resolution_details:)
#{"evaluation_details.value" if suffix == :value}
end
RUBY
end
Expand Down
9 changes: 9 additions & 0 deletions lib/open_feature/sdk/evaluation_details.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module OpenFeature
module SDK
EvaluationDetails = Struct.new(:flag_key, :resolution_details, keyword_init: true) do
extend Forwardable

def_delegators :resolution_details, :value, :reason, :variant, :error_code, :error_message, :flag_metadata
end
end
end
11 changes: 11 additions & 0 deletions lib/open_feature/sdk/provider.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require_relative "provider/error_code"
require_relative "provider/reason"
require_relative "provider/resolution_details"
require_relative "provider/no_op_provider"

module OpenFeature
module SDK
module Provider
end
end
end
15 changes: 15 additions & 0 deletions lib/open_feature/sdk/provider/error_code.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module OpenFeature
module SDK
module Provider
module ErrorCode
PROVIDER_NOT_READY = "Provider Not Ready"
FLAG_NOT_FOUND = "Flag Not Found"
PARSE_ERROR = "Parse Error"
TYPE_MISMATCH = "Type Mismatch"
TARGETING_KEY_MISSING = "Targeting Key Missing"
INVALID_CONTEXT = "Invalid Context"
GENERAL = "General"
end
end
end
end
2 changes: 0 additions & 2 deletions lib/open_feature/sdk/provider/no_op_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ class NoOpProvider

attr_reader :metadata

ResolutionDetails = Struct.new(:value, :reason, :variant, :error_code, :error_message)

def initialize
@metadata = Metadata.new(name: NAME).freeze
end
Expand Down
17 changes: 17 additions & 0 deletions lib/open_feature/sdk/provider/reason.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module OpenFeature
module SDK
module Provider
module Reason
STATIC = "Static"
DEFAULT = "Default"
TARGETING_MATCH = "Targeting Match"
SPLIT = "Split"
CACHED = "Cached"
DISABLED = "Disabled"
UNKNOWN = "Unknown"
STALE = "Stale"
ERROR = "Error"
end
end
end
end
7 changes: 7 additions & 0 deletions lib/open_feature/sdk/provider/resolution_details.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module OpenFeature
module SDK
module Provider
ResolutionDetails = Struct.new(:value, :reason, :variant, :error_code, :error_message, :flag_metadata, keyword_init: true)
end
end
end
10 changes: 5 additions & 5 deletions spec/open_feature/sdk/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
end

it do
expect(client.fetch_boolean_details(flag_key: flag_key, default_value: false)).is_a?(OpenFeature::SDK::Provider::NoOpProvider::ResolutionDetails)
expect(client.fetch_boolean_details(flag_key: flag_key, default_value: false)).is_a?(OpenFeature::SDK::Provider::ResolutionDetails)
end
end

Expand Down Expand Up @@ -136,8 +136,8 @@
end

it do
expect(client.fetch_number_details(flag_key: flag_key, default_value: 1.2)).is_a?(OpenFeature::SDK::Provider::NoOpProvider::ResolutionDetails)
expect(client.fetch_number_details(flag_key: flag_key, default_value: 1)).is_a?(OpenFeature::SDK::Provider::NoOpProvider::ResolutionDetails)
expect(client.fetch_number_details(flag_key: flag_key, default_value: 1.2)).is_a?(OpenFeature::SDK::Provider::ResolutionDetails)
expect(client.fetch_number_details(flag_key: flag_key, default_value: 1)).is_a?(OpenFeature::SDK::Provider::ResolutionDetails)
end
end

Expand Down Expand Up @@ -166,7 +166,7 @@
end

it do
expect(client.fetch_string_details(flag_key: flag_key, default_value: "some-string")).is_a?(OpenFeature::SDK::Provider::NoOpProvider::ResolutionDetails)
expect(client.fetch_string_details(flag_key: flag_key, default_value: "some-string")).is_a?(OpenFeature::SDK::Provider::ResolutionDetails)
end
end

Expand Down Expand Up @@ -195,7 +195,7 @@

it do
expect(client.fetch_object_details(flag_key: flag_key,
default_value: {name: "some-name"})).is_a?(OpenFeature::SDK::Provider::NoOpProvider::ResolutionDetails)
default_value: {name: "some-name"})).is_a?(OpenFeature::SDK::Provider::ResolutionDetails)
end
end

Expand Down