-
Notifications
You must be signed in to change notification settings - Fork 15
feat(spec): Add API implementation #32
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
9ed20b1
build: Update Gemfile to 0.0.3
josecolella 89a3e6f
build: Add concurrent-ruby as dependencies
josecolella e61bc7e
feat: Add API and corresponding tests
josecolella 6e2f4fc
feat: Add Configuration class
josecolella a577c57
feat: Add Client, Metadata, and NoOpProvider
josecolella fdee1cc
feat: Add library to .rspec
josecolella c16bbd3
test: Configure .rubocop.yml and rubocop entire repository
josecolella e15711e
build: Clean up main.yml
josecolella a62ebf8
docs: Update documentation for API class
josecolella File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| -I lib | ||
| --format documentation | ||
| --color | ||
| --require spec_helper |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,11 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require_relative "sdk/version" | ||
| require_relative "sdk/api" | ||
|
|
||
| module OpenFeature | ||
| # TODO: Add documentation | ||
| # | ||
| module SDK | ||
| class Error < StandardError; end | ||
| # Your code goes here... | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require "forwardable" | ||
| require "singleton" | ||
|
|
||
| require_relative "configuration" | ||
| require_relative "client" | ||
| require_relative "metadata" | ||
| require_relative "provider/no_op_provider" | ||
|
|
||
| module OpenFeature | ||
| module SDK | ||
| # API Initialization and Configuration | ||
| # | ||
| # Represents the entry point to the API, including configuration of <tt>Provider</tt>,<tt>Hook</tt>, | ||
| # and building the <tt>Client</tt> | ||
| # | ||
| # To use the SDK, you can optionally configure a <tt>Provider</tt>, with <tt>Hook</tt> | ||
| # | ||
| # OpenFeature::SDK::API.instance.configure do |config| | ||
| # config.provider = NoOpProvider.new | ||
| # end | ||
| # | ||
| # If no provider is specified, the <tt>NoOpProvider</tt> is set as the default <tt>Provider</tt>. | ||
| # Once the SDK has been configured, a client can be built | ||
| # | ||
| # client = OpenFeature::SDK::API.instance.build_client(name: 'my-open-feature-client') | ||
| class API | ||
| include Singleton | ||
| extend Forwardable | ||
|
|
||
| def_delegator :@configuration, :provider | ||
| def_delegator :@configuration, :hooks | ||
| def_delegator :@configuration, :context | ||
|
|
||
| def configuration | ||
| @configuration ||= Configuration.new | ||
| end | ||
|
|
||
| def configure(&block) | ||
| return unless block_given? | ||
|
|
||
| block.call(configuration) | ||
| end | ||
|
|
||
| def build_client(name: nil, version: nil) | ||
| client_options = Metadata.new(name: name, version: version).freeze | ||
| provider = Provider::NoOpProvider.new if provider.nil? | ||
| Client.new(provider, client_options, context) | ||
| end | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module OpenFeature | ||
| module SDK | ||
| # TODO: Write documentation | ||
| # | ||
| class Client | ||
| attr_reader :metadata | ||
|
|
||
| attr_accessor :hooks | ||
|
|
||
| def initialize(provider, client_options, context) | ||
| @provider = provider | ||
| @client_options = client_options | ||
| @context = context | ||
| end | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require "concurrent" | ||
|
|
||
| require_relative "api" | ||
|
|
||
| module OpenFeature | ||
| module SDK | ||
| # Represents the configuration object for the global API where <tt>Provider</tt>, <tt>Hook</tt>, | ||
| # and <tt>Context</tt> are configured. | ||
| # This class is not meant to be interacted with directly but instead through the <tt>OpenFeature::SDK.configure</tt> | ||
| # method | ||
| class Configuration | ||
| extend Forwardable | ||
|
|
||
| attr_accessor :context, :provider, :hooks | ||
|
|
||
| def_delegator :@provider, :metadata | ||
|
|
||
| def initialize | ||
| @hooks = Concurrent::Array.new([]) | ||
| end | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module OpenFeature | ||
| module SDK | ||
| # Metadata structure that defines general metadata relating to a <tt>Provider</tt> or <tt>Client</tt> | ||
| # | ||
| # Within the Metadata structure, the following attribute readers are available: | ||
| # | ||
| # * <tt>name</tt> - Defines the name of the structure | ||
| # | ||
| # * <tt>version</tt> - Allows you to specify version of the Metadata structure | ||
| # | ||
| # Usage: | ||
| # | ||
| # metadata = Metadata.new(name: 'name-for-metadata', version: 'v1.1.3') | ||
| # metadata.name # 'name-for-metadata' | ||
| # metadata.version # version | ||
| # metadata_two = Metadata.new(name: 'name-for-metadata') | ||
| # metadata_two == metadata # true - equality based on values | ||
| class Metadata | ||
| attr_reader :name, :version | ||
|
|
||
| def initialize(name:, version: nil) | ||
| @name = name | ||
| @version = version | ||
| end | ||
|
|
||
| def ==(other) | ||
| raise ArgumentError("Expected comparison to be between Metadata object") unless other.is_a?(Metadata) | ||
|
|
||
| @name == other.name && @version == other.version | ||
| end | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require_relative "../metadata" | ||
|
|
||
| # rubocop:disable Lint/UnusedMethodArgument | ||
| module OpenFeature | ||
| module SDK | ||
| module Provider | ||
| # Defines the default provider that is set if no provider is specified. | ||
| # | ||
| # To use <tt>NoOpProvider</tt>, it can be set during the configuration of the SDK | ||
| # | ||
| # OpenFeature::SDK.configure do |config| | ||
| # config.provider = NoOpProvider.new | ||
| # end | ||
| # | ||
| # Within the <tt>NoOpProvider</tt>, the following methods exist | ||
| # | ||
| # * <tt>fetch_boolean_value</tt> - Retrieve feature flag boolean value | ||
| # | ||
| # * <tt>fetch_string_value</tt> - Retrieve feature flag string value | ||
| # | ||
| # * <tt>fetch_number_value</tt> - Retrieve feature flag number value | ||
| # | ||
| # * <tt>fetch_object_value</tt> - Retrieve feature flag object value | ||
| # | ||
| class NoOpProvider | ||
| REASON_NO_OP = "No-op" | ||
| NAME = "No-op Provider" | ||
|
|
||
| attr_reader :metadata | ||
|
|
||
| def initialize | ||
| @metadata = Metadata.new(name: NAME).freeze | ||
| end | ||
|
|
||
| def fetch_boolean_value(flag_key:, default_value:, evaluation_context: nil) | ||
| no_op(default_value) | ||
| end | ||
|
|
||
| def fetch_string_value(flag_key:, default_value:, evaluation_context: nil) | ||
| no_op(default_value) | ||
| end | ||
|
|
||
| def fetch_number_value(flag_key:, default_value:, evaluation_context: nil) | ||
| no_op(default_value) | ||
| end | ||
|
|
||
| def fetch_object_value(flag_key:, default_value:, evaluation_context: nil) | ||
| no_op(default_value) | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def no_op(default_value) | ||
| Struct.new("ResolutionDetails", :value, :reason) | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
| # rubocop:enable Lint/UnusedMethodArgument |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.