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 typed config #9

Merged
merged 2 commits into from
Oct 20, 2024
Merged

Add typed config #9

merged 2 commits into from
Oct 20, 2024

Conversation

bolshakov
Copy link
Owner

ConfigX allows you to define typed configuration using the ConfigX::Config class which uses the dry-struct library
under the hood.

class Config < ConfigX::Config
  attribute :api do 
    attribute :enabled, Types::Bool.default(false)
    attribute :endpoint, Types::String
    attribute :access_token, Types::String
  end
end 

You can then load the configuration using the load method:

config = ConfigX.load(config_class: Config)
config.api.enabled #=> true
config.api.endpoint #=> "https://example.com"

Using typed configuration allows you to define the structure of the configuration and automatically cast values to the
specified types.

@bolshakov bolshakov force-pushed the feature/typed-config branch from ee8feed to 2d83216 Compare October 20, 2024 14:54
@bolshakov bolshakov merged commit c044b01 into main Oct 20, 2024
2 checks passed
@bolshakov bolshakov deleted the feature/typed-config branch October 20, 2024 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant