Skip to content

Commit

Permalink
feat: add experimental RBS support,
Browse files Browse the repository at this point in the history
TODO:
- add rbs to gemspec
- add rbs tests to gha
- add rbs tests
- consider checking using steep / Steepfile
  • Loading branch information
rarruda committed Jan 8, 2023
1 parent 470a14f commit 89bc0c3
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 0 deletions.
28 changes: 28 additions & 0 deletions Steepfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# D = Steep::Diagnostic
#
target :lib do
signature "sig"

# check "lib/unleash/client.rbs" # Directory name
check "lib" # Directory name
# check "Gemfile" # File name
# check "app/models/**/*.rb" # Glob
# ignore "lib/templates/*.rb"

# library "pathname", "set" # Standard libraries
# library "strong_json" # Gems

# configure_code_diagnostics(D::Ruby.strict) # `strict` diagnostics setting
# configure_code_diagnostics(D::Ruby.lenient) # `lenient` diagnostics setting
# configure_code_diagnostics do |hash| # You can setup everything yourself
# hash[D::Ruby::NoMethod] = :information
# end
end

# target :test do
# # signature "sig", "sig-private"
# #
# check "spec"
# #
# # # library "pathname", "set" # Standard libraries
# end
39 changes: 39 additions & 0 deletions lib/unleash/client.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
module Unleash
class Client
attr_accessor fetcher_scheduled_executor: ScheduledExecutor

attr_accessor metrics_scheduled_executor: ScheduledExecutor

def initialize: (*untyped opts) -> void

def is_enabled?: (untyped feature, ?Context? context, ?bool default_value_param) ?{ () -> bool } -> bool

# enabled? is a more ruby idiomatic method name than is_enabled?
alias enabled? is_enabled?

# execute a code block (passed as a parameter), if is_enabled? is true.
def if_enabled: (untyped feature, ?Context context, ?bool default_value) { (untyped) -> bool } -> (untyped | nil)

def get_variant: (untyped feature, ?Context context, ?Variant fallback_variant) -> Variant

# safe shutdown: also flush metrics to server and toggles to disk
def shutdown: () -> nil

# quick shutdown: just kill running threads
def shutdown!: () -> nil

private

def info: () -> { appName: String, instanceId: String, sdkVersion: String, strategies: Array[String], started: String, interval: Integer }

def start_toggle_fetcher: () -> nil

def start_metrics: () -> nil

def register: () -> nil

def disabled_variant: () -> Variant

def first_fetch_is_eager: () -> bool
end
end
21 changes: 21 additions & 0 deletions lib/unleash/context.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module Unleash
class Context
ATTRS: ::Array[:app_name | :environment | :user_id | :session_id | :remote_address | :current_time]

def initialize: (?::Hash[String, any] params) -> Context

def to_s: () -> ::String

def get_by_name: ((String | Symbol) name) -> any

def include?: ((String | Symbol) name) -> bool

private

# Method to fetch values from hash for two types of keys: string in camelCase and symbol in snake_case
def value_for: ((String | Symbol) key, Hash[String, any] params, ?any? default_value) -> any

# converts CamelCase to snake_case
def underscore: ((String | Symbol) camel_cased_word) -> String
end
end
29 changes: 29 additions & 0 deletions lib/unleash/scheduled_executor.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module Unleash
class ScheduledExecutor
attr_accessor name: String

attr_accessor interval: Numeric

attr_accessor max_exceptions: ::Integer

attr_accessor retry_count: ::Integer

attr_accessor thread: (Thread | nil)

attr_accessor immediate_execution: bool

def initialize: (String name, untyped interval, ?::Integer max_exceptions, ?bool immediate_execution) -> void

def run: () ?{ () -> nil } -> nil

def running?: () -> bool

def exit: () -> nil

private

def run_blk: () { () -> nil } -> nil

def exceeded_max_exceptions?: () -> bool
end
end
15 changes: 15 additions & 0 deletions lib/unleash/variant.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module Unleash
class Variant
attr_accessor name: String

attr_accessor enabled: bool

attr_accessor payload: String

def initialize: (?::Hash[String, String] params) -> void

def to_s: () -> ::String

def ==: (Variant other) -> bool
end
end

0 comments on commit 89bc0c3

Please sign in to comment.