openfeature-sdk-sorbet 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +7 -0
  2. data/.DS_Store +0 -0
  3. data/.rubocop.yml +42 -0
  4. data/.ruby-version +1 -0
  5. data/.tool-versions +1 -0
  6. data/CHANGELOG.md +15 -0
  7. data/CODE_OF_CONDUCT.md +84 -0
  8. data/Gemfile +25 -0
  9. data/Gemfile.lock +113 -0
  10. data/LICENSE.txt +21 -0
  11. data/README.md +115 -0
  12. data/Rakefile +24 -0
  13. data/lib/open_feature/client.rb +180 -0
  14. data/lib/open_feature/client_metadata.rb +9 -0
  15. data/lib/open_feature/configuration.rb +47 -0
  16. data/lib/open_feature/error_code.rb +17 -0
  17. data/lib/open_feature/evaluation_context.rb +10 -0
  18. data/lib/open_feature/evaluation_details.rb +56 -0
  19. data/lib/open_feature/evaluation_options.rb +9 -0
  20. data/lib/open_feature/flag_metadata.rb +6 -0
  21. data/lib/open_feature/hook.rb +6 -0
  22. data/lib/open_feature/no_op_provider.rb +77 -0
  23. data/lib/open_feature/provider.rb +61 -0
  24. data/lib/open_feature/provider_metadata.rb +11 -0
  25. data/lib/open_feature/resolution_details.rb +20 -0
  26. data/lib/open_feature.rb +40 -0
  27. data/sorbet/config +4 -0
  28. data/sorbet/rbi/annotations/rainbow.rbi +269 -0
  29. data/sorbet/rbi/gems/ast@2.4.2.rbi +584 -0
  30. data/sorbet/rbi/gems/diff-lcs@1.5.0.rbi +1083 -0
  31. data/sorbet/rbi/gems/io-console@0.6.0.rbi +8 -0
  32. data/sorbet/rbi/gems/irb@1.6.4.rbi +342 -0
  33. data/sorbet/rbi/gems/json@2.6.3.rbi +1533 -0
  34. data/sorbet/rbi/gems/minitest@5.18.0.rbi +2153 -0
  35. data/sorbet/rbi/gems/netrc@0.11.0.rbi +158 -0
  36. data/sorbet/rbi/gems/parallel@1.23.0.rbi +273 -0
  37. data/sorbet/rbi/gems/parser@3.2.2.1.rbi +7253 -0
  38. data/sorbet/rbi/gems/rainbow@3.1.1.rbi +402 -0
  39. data/sorbet/rbi/gems/rake@13.0.6.rbi +3024 -0
  40. data/sorbet/rbi/gems/rbi@0.0.16.rbi +3049 -0
  41. data/sorbet/rbi/gems/regexp_parser@2.8.0.rbi +3748 -0
  42. data/sorbet/rbi/gems/reline@0.3.3.rbi +8 -0
  43. data/sorbet/rbi/gems/rexml@3.2.5.rbi +4717 -0
  44. data/sorbet/rbi/gems/rubocop-ast@1.28.1.rbi +6990 -0
  45. data/sorbet/rbi/gems/rubocop-minitest@0.31.0.rbi +2528 -0
  46. data/sorbet/rbi/gems/rubocop-performance@1.17.1.rbi +3036 -0
  47. data/sorbet/rbi/gems/rubocop-rake@0.6.0.rbi +328 -0
  48. data/sorbet/rbi/gems/rubocop-sorbet@0.7.0.rbi +1043 -0
  49. data/sorbet/rbi/gems/rubocop@1.51.0.rbi +55316 -0
  50. data/sorbet/rbi/gems/ruby-progressbar@1.13.0.rbi +1317 -0
  51. data/sorbet/rbi/gems/sorbet-struct-comparable@1.3.0.rbi +34 -0
  52. data/sorbet/rbi/gems/spoom@1.2.1.rbi +2536 -0
  53. data/sorbet/rbi/gems/tapioca@0.11.6.rbi +3301 -0
  54. data/sorbet/rbi/gems/thor@1.2.2.rbi +3965 -0
  55. data/sorbet/rbi/gems/unicode-display_width@2.4.2.rbi +65 -0
  56. data/sorbet/rbi/gems/unparser@0.6.7.rbi +4524 -0
  57. data/sorbet/rbi/gems/yard-sorbet@0.8.1.rbi +428 -0
  58. data/sorbet/rbi/gems/yard@0.9.34.rbi +18219 -0
  59. data/sorbet/rbi/gems/zeitwerk@2.6.8.rbi +986 -0
  60. data/sorbet/tapioca/config.yml +4 -0
  61. data/sorbet/tapioca/require.rb +8 -0
  62. metadata +150 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e5bada3dd0c6a4687fb9c7f44768f668d809a4d12fdd11439d000ed77e10340e
4
+ data.tar.gz: 952ebbe9649d88fd4a76cbb29af2709514d863c1be6106e73f132092a2d9d9c7
5
+ SHA512:
6
+ metadata.gz: 26655c2337a276815db33affb69d3c53c2b48dd7176c6acf6e365caa0e7b84f8899a96a786376f1a316f5aa1618cc540f8e4ac8bb6d05c38dd1011f6e94641fb
7
+ data.tar.gz: b0e88fc7f6f91e85294126fc23c9a58a45165bc4b7f3394c158413955fdd428c250edb82a915d2a78491e7a2c2141b86fda0ef5b1ba96552166c22fd17ba2c51
data/.DS_Store ADDED
Binary file
data/.rubocop.yml ADDED
@@ -0,0 +1,42 @@
1
+ inherit_mode:
2
+ merge:
3
+ - Exclude
4
+
5
+ require:
6
+ - rubocop-minitest
7
+ - rubocop-performance
8
+ - rubocop-rake
9
+ - rubocop-sorbet
10
+
11
+ AllCops:
12
+ NewCops: enable
13
+ TargetRubyVersion: 2.7
14
+ Exclude:
15
+ - sorbet/**/*.rbi
16
+
17
+ Layout/LineLength:
18
+ Max: 120
19
+
20
+ Lint/UnusedMethodArgument:
21
+ Exclude:
22
+ - lib/open_feature/no_op_provider.rb
23
+
24
+ Metrics/ClassLength:
25
+ Exclude:
26
+ - lib/open_feature/client.rb
27
+ - test/open_feature/client_test.rb
28
+
29
+ Metrics/MethodLength:
30
+ Exclude:
31
+ - test/open_feature/evaluation_details_test.rb
32
+
33
+ Style/AccessorGrouping:
34
+ Enabled: false
35
+
36
+ Style/StringLiterals:
37
+ Enabled: true
38
+ EnforcedStyle: double_quotes
39
+
40
+ Style/StringLiteralsInInterpolation:
41
+ Enabled: true
42
+ EnforcedStyle: double_quotes
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.2.2
data/.tool-versions ADDED
@@ -0,0 +1 @@
1
+ ruby 3.2.2
data/CHANGELOG.md ADDED
@@ -0,0 +1,15 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [Unreleased]
8
+
9
+ ## [0.1.0] - 2023-05-15
10
+
11
+ ### Added
12
+
13
+ - Provider interface and `NoOpProvider` implementation
14
+ - Global API configuration for provider and hooks
15
+ - Client initialization with basic support for fetching values and details
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at maxveldink@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in activerecord-ejection_seat.gemspec
6
+ gemspec
7
+
8
+ group :development do
9
+ gem "rake"
10
+ gem "rubocop"
11
+ gem "rubocop-minitest"
12
+ gem "rubocop-performance"
13
+ gem "rubocop-rake"
14
+ gem "rubocop-sorbet"
15
+ gem "sorbet"
16
+ gem "spoom"
17
+ gem "tapioca", require: false
18
+ end
19
+
20
+ group :development, :test do
21
+ gem "minitest"
22
+ gem "sorbet-runtime"
23
+
24
+ gem "debug"
25
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,113 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ openfeature-sdk-sorbet (0.1.0)
5
+ sorbet-runtime (~> 0.5)
6
+ sorbet-struct-comparable (~> 1.3)
7
+ zeitwerk (~> 2.6)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ ast (2.4.2)
13
+ debug (1.8.0)
14
+ irb (>= 1.5.0)
15
+ reline (>= 0.3.1)
16
+ diff-lcs (1.5.0)
17
+ io-console (0.6.0)
18
+ irb (1.6.4)
19
+ reline (>= 0.3.0)
20
+ json (2.6.3)
21
+ minitest (5.18.0)
22
+ netrc (0.11.0)
23
+ parallel (1.23.0)
24
+ parser (3.2.2.1)
25
+ ast (~> 2.4.1)
26
+ rainbow (3.1.1)
27
+ rake (13.0.6)
28
+ rbi (0.0.16)
29
+ ast
30
+ parser (>= 2.6.4.0)
31
+ sorbet-runtime (>= 0.5.9204)
32
+ unparser
33
+ regexp_parser (2.8.0)
34
+ reline (0.3.3)
35
+ io-console (~> 0.5)
36
+ rexml (3.2.5)
37
+ rubocop (1.51.0)
38
+ json (~> 2.3)
39
+ parallel (~> 1.10)
40
+ parser (>= 3.2.0.0)
41
+ rainbow (>= 2.2.2, < 4.0)
42
+ regexp_parser (>= 1.8, < 3.0)
43
+ rexml (>= 3.2.5, < 4.0)
44
+ rubocop-ast (>= 1.28.0, < 2.0)
45
+ ruby-progressbar (~> 1.7)
46
+ unicode-display_width (>= 2.4.0, < 3.0)
47
+ rubocop-ast (1.28.1)
48
+ parser (>= 3.2.1.0)
49
+ rubocop-minitest (0.31.0)
50
+ rubocop (>= 1.39, < 2.0)
51
+ rubocop-performance (1.17.1)
52
+ rubocop (>= 1.7.0, < 2.0)
53
+ rubocop-ast (>= 0.4.0)
54
+ rubocop-rake (0.6.0)
55
+ rubocop (~> 1.0)
56
+ rubocop-sorbet (0.7.0)
57
+ rubocop (>= 0.90.0)
58
+ ruby-progressbar (1.13.0)
59
+ sorbet (0.5.10826)
60
+ sorbet-static (= 0.5.10826)
61
+ sorbet-runtime (0.5.10826)
62
+ sorbet-static (0.5.10826-universal-darwin-22)
63
+ sorbet-static (0.5.10826-x86_64-linux)
64
+ sorbet-static-and-runtime (0.5.10826)
65
+ sorbet (= 0.5.10826)
66
+ sorbet-runtime (= 0.5.10826)
67
+ sorbet-struct-comparable (1.3.0)
68
+ sorbet-runtime (>= 0.5)
69
+ spoom (1.2.1)
70
+ sorbet (>= 0.5.10187)
71
+ sorbet-runtime (>= 0.5.9204)
72
+ thor (>= 0.19.2)
73
+ tapioca (0.11.6)
74
+ bundler (>= 2.2.25)
75
+ netrc (>= 0.11.0)
76
+ parallel (>= 1.21.0)
77
+ rbi (~> 0.0.0, >= 0.0.16)
78
+ sorbet-static-and-runtime (>= 0.5.10187)
79
+ spoom (~> 1.2.0, >= 1.2.0)
80
+ thor (>= 1.2.0)
81
+ yard-sorbet
82
+ thor (1.2.2)
83
+ unicode-display_width (2.4.2)
84
+ unparser (0.6.7)
85
+ diff-lcs (~> 1.3)
86
+ parser (>= 3.2.0)
87
+ yard (0.9.34)
88
+ yard-sorbet (0.8.1)
89
+ sorbet-runtime (>= 0.5)
90
+ yard (>= 0.9)
91
+ zeitwerk (2.6.8)
92
+
93
+ PLATFORMS
94
+ arm64-darwin-22
95
+ x86_64-linux
96
+
97
+ DEPENDENCIES
98
+ debug
99
+ minitest
100
+ openfeature-sdk-sorbet!
101
+ rake
102
+ rubocop
103
+ rubocop-minitest
104
+ rubocop-performance
105
+ rubocop-rake
106
+ rubocop-sorbet
107
+ sorbet
108
+ sorbet-runtime
109
+ spoom
110
+ tapioca
111
+
112
+ BUNDLED WITH
113
+ 2.4.12
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Max VelDink
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,115 @@
1
+ # Sorbet-aware OpenFeature Ruby Implementation
2
+
3
+ [OpenFeature](https://openfeature.dev) is an open standard for vendor-agnostic feature flagging. [Sorbet](https://sorbet.org) is a type-checker for Ruby, built by Stripe. Sorbet provides powerful runtime utilities to achieve things traditionally not possible with Ruby, such as interfaces, immutable structures and enums. This makes it a very good option when defining specifications.
4
+
5
+ If an organization is not already using Sorbet, you probably don't want to introduce a dependency on `sorbet-runtime`, which this gem does. As such, this will always be a distinct implementation, separate from the official [Ruby SDK](https://github.com/open-feature/ruby-sdk).
6
+
7
+ Current OpenFeature specification target version: `0.5.2`
8
+ Current supported Ruby versions: `2.7.X`, `3.0.X`, `3.1.X`, `3.2.X`
9
+ Support for Evaluation Context and Hooks is not complete.
10
+
11
+ ## Installation
12
+
13
+ Install the gem and add to the application's Gemfile by executing:
14
+
15
+ $ bundle add openfeature-sdk-sorbet
16
+
17
+ If bundler is not being used to manage dependencies, install the gem by executing:
18
+
19
+ $ gem install openfeature-sdk-sorbet
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ require "open_feature"
25
+
26
+ # Configure global API properties
27
+
28
+ OpenFeature.set_provider(OpenFeature::NoOpProvider.new)
29
+ OpenFeature.add_hooks([OpenFeature::Hook.new]) # experimental, not fully supported
30
+
31
+ client = OpenFeature.create_client
32
+
33
+ # Fetch boolean value
34
+ # Also methods available for String, Number, Integer, Float and Structure (Hash)
35
+ bool_value = client.fetch_boolean_value(flag_key: "my_toggle", default_value: false) # => (true or false)
36
+
37
+ # Sorbet sprinkles in type safety
38
+ bool_value = client.fetch_boolean_value(flag_key: "my_toggle", default_value: "bad!") # => raises TypeError from Sorbet, invalid default value
39
+
40
+ # Fetch structure evaluation details
41
+ structure_evaluation_details = client.fetch_structure_details(flag_key: "my_structure", default_value: { "a" => "fallback" }) # => EvaluationDetails(value: Hash, flag_key: "my_structure", ...)
42
+ ```
43
+
44
+ ### Note on `Structure`
45
+
46
+ The OpenFeature specification defines [Structure as a potential return type](https://openfeature.dev/specification/types#structure). This is somewhat ambiguous in Ruby, further complicated by `T::Struct` that we get from Sorbet. For now, the type I've elected here is `T::Hash[T.untyped, T.untyped]` for flexibility but with a little more structure than a YML or JSON parsable string. This decision might change in the future upon further interpretation or new versions of the specification.
47
+
48
+ ### Provider Interface
49
+
50
+ By default, this implementation sets the provider to the `OpenFeature::NoOpProvider` which always returns the default value. It's up to the individual teams to define their own providers based on their flag source (in the future, I'll release open-source providers based on various, common vendors).
51
+
52
+ Thanks to Sorbet interfaces, it's fairly straightforward to implement a new provider. Here is an example for a JSON-based flag format on disk:
53
+
54
+ ```ruby
55
+ class JsonFileFlagProvider
56
+ extend T::Sig
57
+
58
+ include OpenFeature::Provider
59
+
60
+ sig { override.returns(OpenFeature::ProviderMetadata) }
61
+ def metadata
62
+ OpenFeature::ProviderMetadata.new(name: "Json File Flag Provider")
63
+ end
64
+
65
+ sig { override.returns(T::Array[Hook]) }
66
+ def hooks
67
+ []
68
+ end
69
+
70
+ sig do
71
+ override
72
+ .params(
73
+ flag_key: String,
74
+ default_value: T::Boolean,
75
+ context: T.nilable(EvaluationContext)
76
+ )
77
+ .returns(OpenFeature::ResolutionDetails[T::Boolean])
78
+ end
79
+ def resolve_boolean_value(flag_key:, default_value:, context: nil)
80
+ file_input = JSON.parse(File.read("flags.rb"))
81
+ value = file_input.fetch("flag_key", default_value)
82
+
83
+ OpenFeature::ResolutionDetails.new(
84
+ value: value,
85
+ # ... other optional fields
86
+ )
87
+ end
88
+
89
+ # ... other resolver methods
90
+ end
91
+ ```
92
+
93
+ By including the `OpenFeature::Provider` module, Sorbet will indicate what methods it's expecting and what their type signatures should be.
94
+
95
+ ## Development
96
+
97
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake` to run Rubocop and the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
98
+
99
+ To install this gem onto your local machine, run `bundle exec rake install`.
100
+
101
+ ## Contributing
102
+
103
+ Bug reports and pull requests are welcome on GitHub at https://github.com/maxveldink/openfeature-sdk-sorbet. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/maxveldink/openfeature-sdk-sorbet/blob/master/CODE_OF_CONDUCT.md).
104
+
105
+ ## License
106
+
107
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
108
+
109
+ ## Code of Conduct
110
+
111
+ Everyone interacting in this project's codebase, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/maxveldink/openfeature-sdk-sorbet/blob/master/CODE_OF_CONDUCT.md).
112
+
113
+ ## Sponsorships
114
+
115
+ I love creating in the open. If you find this or any other [maxveld.ink](https://maxveld.ink) content useful, please consider sponsoring me on [GitHub](https://github.com/sponsors/maxveldink).
data/Rakefile ADDED
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "minitest/test_task"
5
+
6
+ Minitest::TestTask.create do |t|
7
+ t.test_globs = ["test/**/*_test.rb"]
8
+ end
9
+
10
+ require "rubocop/rake_task"
11
+
12
+ RuboCop::RakeTask.new
13
+
14
+ desc "Run tapioca compilers"
15
+ task :tapioca do
16
+ sh "bin/tapioca gem"
17
+ end
18
+
19
+ desc "Run Sorbet typechecker"
20
+ task :sorbet do
21
+ sh "bundle exec srb tc"
22
+ end
23
+
24
+ task default: %i[rubocop:autocorrect_all sorbet test]
@@ -0,0 +1,180 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module OpenFeature
5
+ # Used during runtime for evaluating features.
6
+ class Client
7
+ extend T::Sig
8
+
9
+ sig { returns(ClientMetadata) }
10
+ attr_reader :client_metadata
11
+
12
+ sig { returns(T::Array[Hook]) }
13
+ attr_reader :hooks
14
+
15
+ sig { params(provider: Provider, name: T.nilable(String)).void }
16
+ def initialize(provider:, name: nil)
17
+ @provider = provider
18
+ @client_metadata = T.let(ClientMetadata.new(name: name), ClientMetadata)
19
+ @hooks = T.let([], T::Array[Hook])
20
+ end
21
+
22
+ sig { params(hooks: T.any(Hook, T::Array[Hook])).void }
23
+ def add_hooks(hooks)
24
+ @hooks.concat(Array(hooks))
25
+ end
26
+
27
+ sig do
28
+ params(
29
+ flag_key: String,
30
+ default_value: T::Boolean,
31
+ context: T.nilable(EvaluationContext),
32
+ options: T.nilable(EvaluationOptions)
33
+ ).returns(T::Boolean)
34
+ end
35
+ def fetch_boolean_value(flag_key:, default_value:, context: nil, options: nil) # rubocop:disable Lint/UnusedMethodArgument
36
+ provider.resolve_boolean_value(flag_key: flag_key, default_value: default_value, context: context).value
37
+ rescue StandardError
38
+ default_value
39
+ end
40
+
41
+ sig do
42
+ params(
43
+ flag_key: String,
44
+ default_value: T::Boolean,
45
+ context: T.nilable(EvaluationContext),
46
+ options: T.nilable(EvaluationOptions)
47
+ ).returns(EvaluationDetails[T::Boolean])
48
+ end
49
+ def fetch_boolean_details(flag_key:, default_value:, context: nil, options: nil) # rubocop:disable Lint/UnusedMethodArgument
50
+ details = provider.resolve_boolean_value(flag_key: flag_key, default_value: default_value, context: context)
51
+
52
+ EvaluationDetails.from_resolution_details(details, flag_key: flag_key)
53
+ rescue StandardError => e
54
+ EvaluationDetails.from_error(e.message, flag_key: flag_key, default_value: default_value)
55
+ end
56
+
57
+ sig do
58
+ params(
59
+ flag_key: String,
60
+ default_value: String,
61
+ context: T.nilable(EvaluationContext),
62
+ options: T.nilable(EvaluationOptions)
63
+ ).returns(String)
64
+ end
65
+ def fetch_string_value(flag_key:, default_value:, context: nil, options: nil) # rubocop:disable Lint/UnusedMethodArgument
66
+ provider.resolve_string_value(flag_key: flag_key, default_value: default_value, context: context).value
67
+ rescue StandardError
68
+ default_value
69
+ end
70
+
71
+ sig do
72
+ params(
73
+ flag_key: String,
74
+ default_value: String,
75
+ context: T.nilable(EvaluationContext),
76
+ options: T.nilable(EvaluationOptions)
77
+ ).returns(EvaluationDetails[String])
78
+ end
79
+ def fetch_string_details(flag_key:, default_value:, context: nil, options: nil) # rubocop:disable Lint/UnusedMethodArgument
80
+ details = provider.resolve_string_value(flag_key: flag_key, default_value: default_value, context: context)
81
+
82
+ EvaluationDetails.from_resolution_details(details, flag_key: flag_key)
83
+ rescue StandardError => e
84
+ EvaluationDetails.from_error(e.message, flag_key: flag_key, default_value: default_value)
85
+ end
86
+
87
+ sig do
88
+ params(
89
+ flag_key: String,
90
+ default_value: Numeric,
91
+ context: T.nilable(EvaluationContext),
92
+ options: T.nilable(EvaluationOptions)
93
+ ).returns(Numeric)
94
+ end
95
+ def fetch_number_value(flag_key:, default_value:, context: nil, options: nil) # rubocop:disable Lint/UnusedMethodArgument
96
+ provider.resolve_number_value(flag_key: flag_key, default_value: default_value, context: context).value
97
+ rescue StandardError
98
+ default_value
99
+ end
100
+
101
+ sig do
102
+ params(
103
+ flag_key: String,
104
+ default_value: Numeric,
105
+ context: T.nilable(EvaluationContext),
106
+ options: T.nilable(EvaluationOptions)
107
+ ).returns(EvaluationDetails[Numeric])
108
+ end
109
+ def fetch_number_details(flag_key:, default_value:, context: nil, options: nil) # rubocop:disable Lint/UnusedMethodArgument
110
+ details = provider.resolve_number_value(flag_key: flag_key, default_value: default_value, context: context)
111
+
112
+ EvaluationDetails.from_resolution_details(details, flag_key: flag_key)
113
+ rescue StandardError => e
114
+ EvaluationDetails.from_error(e.message, flag_key: flag_key, default_value: default_value)
115
+ end
116
+
117
+ sig do
118
+ params(
119
+ flag_key: String,
120
+ default_value: Integer,
121
+ context: T.nilable(EvaluationContext),
122
+ options: T.nilable(EvaluationOptions)
123
+ ).returns(Integer)
124
+ end
125
+ def fetch_integer_value(flag_key:, default_value:, context: nil, options: nil) # rubocop:disable Lint/UnusedMethodArgument
126
+ provider.resolve_number_value(flag_key: flag_key, default_value: default_value, context: context).value.to_i
127
+ rescue StandardError
128
+ default_value
129
+ end
130
+
131
+ sig do
132
+ params(
133
+ flag_key: String,
134
+ default_value: Float,
135
+ context: T.nilable(EvaluationContext),
136
+ options: T.nilable(EvaluationOptions)
137
+ ).returns(Float)
138
+ end
139
+ def fetch_float_value(flag_key:, default_value:, context: nil, options: nil) # rubocop:disable Lint/UnusedMethodArgument
140
+ provider.resolve_number_value(flag_key: flag_key, default_value: default_value, context: context).value.to_f
141
+ rescue StandardError
142
+ default_value
143
+ end
144
+
145
+ sig do
146
+ params(
147
+ flag_key: String,
148
+ default_value: T::Hash[T.untyped, T.untyped],
149
+ context: T.nilable(EvaluationContext),
150
+ options: T.nilable(EvaluationOptions)
151
+ ).returns(T::Hash[T.untyped, T.untyped])
152
+ end
153
+ def fetch_structure_value(flag_key:, default_value:, context: nil, options: nil) # rubocop:disable Lint/UnusedMethodArgument
154
+ provider.resolve_structure_value(flag_key: flag_key, default_value: default_value, context: context).value
155
+ rescue StandardError
156
+ default_value
157
+ end
158
+
159
+ sig do
160
+ params(
161
+ flag_key: String,
162
+ default_value: T::Hash[T.untyped, T.untyped],
163
+ context: T.nilable(EvaluationContext),
164
+ options: T.nilable(EvaluationOptions)
165
+ ).returns(EvaluationDetails[T::Hash[T.untyped, T.untyped]])
166
+ end
167
+ def fetch_structure_details(flag_key:, default_value:, context: nil, options: nil) # rubocop:disable Lint/UnusedMethodArgument
168
+ details = provider.resolve_structure_value(flag_key: flag_key, default_value: default_value, context: context)
169
+
170
+ EvaluationDetails.from_resolution_details(details, flag_key: flag_key)
171
+ rescue StandardError => e
172
+ EvaluationDetails.from_error(e.message, flag_key: flag_key, default_value: default_value)
173
+ end
174
+
175
+ private
176
+
177
+ sig { returns(Provider) }
178
+ attr_reader :provider
179
+ end
180
+ end
@@ -0,0 +1,9 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module OpenFeature
5
+ # Defines information about a Client.
6
+ class ClientMetadata < T::Struct
7
+ const :name, T.nilable(String)
8
+ end
9
+ end