Skip to content

Instantly share code, notes, and snippets.

@pat
Created December 14, 2021 06:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pat/5feba9bf0c122ec5f9c2bf6de5f24c21 to your computer and use it in GitHub Desktop.
Save pat/5feba9bf0c122ec5f9c2bf6de5f24c21 to your computer and use it in GitHub Desktop.
Using dry-system for typed and verified Rails configuration settings
# frozen_string_literal: true
require "dry/system/errors"
require "dry/system/settings"
require "dry/types"
module Types
include Dry.Types()
end
SettingsSchema = Dry::System::Settings::DSL.new do
key :domain, Types::Strict::String.default("example.com")
key :calendar_url, Types::Strict::String
key :twilio_account_id, Types::Strict::String.optional.default(nil)
key :twilio_auth_token, Types::Strict::String.optional.default(nil)
key :phone_number, Types::Strict::String
key :host_phone_number, Types::Strict::String
end
Settings = SettingsSchema.call.init(Rails.root, Rails.env)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment