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

Add types for config #636

Merged
merged 1 commit into from
Aug 20, 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
5 changes: 5 additions & 0 deletions gems/config/5.5/_test/test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require "config"

Config.load_and_set_settings(Config.setting_files("/path/to/config_root", "your_project_environment"))

Config.load_and_set_settings("/path/to/yaml1", "/path/to/yaml2")
72 changes: 72 additions & 0 deletions gems/config/5.5/config.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
module Config
include Validation::Schema

def self.setup: () -> void
def self.load_files: (*String files) -> Options
| (Array[String] files) -> Options
def self.load_and_set_settings: (*String files) -> void
| (Array[String] files) -> void
def self.setting_files: (String config_root, String env) -> Array[String]
def self.local_setting_files: (String config_root, String env) -> Array[String]
def self.reload!: () -> Options
end

module Config
class Options
include Enumerable[untyped]
include Validation::Validate

def keys: () -> Array[String]
def empty?: () -> bool
def add_source!: (String source) -> void
def prepend_source!: (String source) -> void
def reload!: () -> self

alias load! reload!

def reload_from_files: (*String files) -> self
def to_hash: () -> Hash[String, untyped]

alias to_h to_hash

def each: (*untyped args) ?{ (untyped) -> void } -> void
def to_json: (*untyped args) -> String
def as_json: (?untyped options) -> String
def merge: (Hash[untyped, untyped] hash) -> self
def []: (String | Symbol param) -> untyped
def []=: (String | Symbol param, untyped value) -> untyped
def select: () -> untyped
def collect: () -> untyped
def test: () -> untyped
def count: () -> untyped
def zip: () -> untyped
def min: () -> untyped
def max: () -> untyped
def exit!: () -> untyped
def table: () -> untyped
def maximum: () -> untyped
def minimum: () -> untyped
def key?: (String | Symbol key) -> bool
def has_key?: (String | Symbol key) -> bool

# Methods from OpenStruct

def delete_field: (String | Symbol name) -> untyped
def dig: (*(String | Symbol) keys) -> untyped
def each_pair: () -> Enumerator[[String, untyped], untyped]
| () { ([String, untyped]) -> void } -> self
end
end

module Config
module Validation
module Schema
def schema=: (untyped value) -> untyped
def schema: () ?{ () -> untyped } -> untyped
end

module Validate
def validate!: () -> void
end
end
end