Skip to content

Commit

Permalink
chore: add type signatures and type checker for CI
Browse files Browse the repository at this point in the history
Signed-off-by: Manuel Schönlaub <[email protected]>
  • Loading branch information
mschoenlaub committed Sep 5, 2023
1 parent c149a45 commit ffc59f8
Show file tree
Hide file tree
Showing 11 changed files with 148 additions and 71 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@ jobs:
- run: bundle install
- name: Rubocop
run: bundle exec rubocop --color
steep:
runs-on: ubuntu-latest
name: Steep
steps:
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: 3.2
- run: bundle install
- name: Steep
run: bundle exec steep check
# check the status of other jobs, so we can have a single job dependency for branch protection
# https://github.com/community/community/discussions/4324#discussioncomment-3477871
status:
Expand Down
68 changes: 0 additions & 68 deletions Gemfile.lock

This file was deleted.

2 changes: 1 addition & 1 deletion lib/openfeature/sdk/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def initialize(name:, version: nil)
end

def ==(other)
raise ArgumentError("Expected comparison to be between Metadata object") unless other.is_a?(Metadata)
raise ArgumentError, "Expected comparison to be between Metadata object" unless other.is_a?(Metadata)

@name == other.name && @version == other.version
end
Expand Down
1 change: 1 addition & 0 deletions openfeature-sdk.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "rake", "~> 13.0"
spec.add_development_dependency "rspec", "~> 3.12.0"
spec.add_development_dependency "rubocop", "~> 1.37.1"
spec.add_development_dependency "steep", "~> 1.5.0"
end
4 changes: 2 additions & 2 deletions sig/openfeature/sdk.rbs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Openfeature
module Sdk
module OpenFeature
module SDK
VERSION: String
# See the writing guide of rbs: https://github.com/ruby/rbs#guides
end
Expand Down
31 changes: 31 additions & 0 deletions sig/openfeature/sdk/_hook.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
type flagValue = bool | Numeric | String | Hash[String, untyped]
type flagValueType = :bool | :integer | :float | :string | :object
type evaluationContext = { targeting_key: String? }
type evaluationDetails = { flag_key: String, flag_value?: flagValue }

type hookContext[T] = {
flag_key: String,
flag_value_type: flagValueType,
evaluation_context: evaluationContext,
default_value: T,
}

type hookHints = Hash[String, flagValue]

interface _BeforeHook
def before: (evaluationContext, ?hookHints) -> (evaluationContext | void)
end

interface _AfterHook[T]
def after: (hookContext[T], evaluationDetails, ?hookHints) -> void
end

interface _ErrorHook[T]
def error: (hookContext[T], Exception, ?hookHints) -> void
end

interface _FinallyHook[T]
def finally: (hookContext[T], ?hookHints) -> void
end

type hook = _BeforeHook | _AfterHook[flagValue] | _ErrorHook[flagValue] | _FinallyHook[flagValue]
22 changes: 22 additions & 0 deletions sig/openfeature/sdk/api.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module OpenFeature
module SDK

interface _Configuration
def context: () -> void
end

class API
include _Configuration
extend Forwardable

attr_reader configuration: Configuration

def build_client: -> Client

def configure: () { (Configuration) -> void } -> void

# Singleton's RBS doesn't quite work
def self.instance: () -> instance
end
end
end
17 changes: 17 additions & 0 deletions sig/openfeature/sdk/client.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module OpenFeature
module SDK
class Client
RESULT_TYPE: Array[Symbol]
SUFFIXES: Array[Symbol]

@context: evaluationContext
@hooks: Array[hook]

attr_accessor hooks: Array[hook]
attr_reader metadata: Metadata?
attr_reader provider: untyped

def initialize: (provider: untyped , client_options: untyped, context: untyped) -> void
end
end
end
19 changes: 19 additions & 0 deletions sig/openfeature/sdk/configuration.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

module Concurrent
class Array[T] < ::Array[T]
def initialize: (?::Array[T]) -> void
end
end

module OpenFeature
module SDK
class Configuration
extend Forwardable

attr_accessor context: evaluationContext
attr_accessor hooks: [hook]
attr_accessor metadata: Metadata
attr_accessor provider: untyped
end
end
end
12 changes: 12 additions & 0 deletions sig/openfeature/sdk/metadata.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module OpenFeature
module SDK
class Metadata
attr_reader name: String
attr_reader version: String?

def initialize: (name: String, ?version: String?) -> void

def ==: (untyped other) -> untyped
end
end
end
32 changes: 32 additions & 0 deletions sig/openfeature/sdk/provider/no_op_provider.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module OpenFeature
module SDK
module Provider
class NoOpProvider
REASON_NO_OP: String
NAME: String

class ResolutionDetails[T] < ::Struct[T]
attr_reader value(): T
attr_reader reason(): untyped
attr_reader variant(): untyped
attr_reader error_code(): untyped
attr_reader error_message(): untyped
end

attr_reader metadata: Metadata

def fetch_boolean_value: (flag_key: String, default_value: bool?, ?evaluation_context: evaluationContext?) -> ResolutionDetails[bool]

def fetch_string_value: (flag_key: String, default_value: String?, ?evaluation_context: evaluationContext?) -> ResolutionDetails[String]

def fetch_number_value: (flag_key: String, default_value: Numeric?, ?evaluation_context: evaluationContext?) -> ResolutionDetails[Numeric]

def fetch_object_value: (flag_key: String, default_value: Hash[untyped, untyped]?, ?evaluation_context: evaluationContext?) -> ResolutionDetails[Hash[untyped, untyped]]

private

def no_op:(default_value: flagValue) -> ResolutionDetails[flagValue]
end
end
end
end

0 comments on commit ffc59f8

Please sign in to comment.