Last active
November 28, 2023 22:50
-
-
Save pat/336b679079fd9b1e469e8051a5c6edfc to your computer and use it in GitHub Desktop.
Revisions
-
pat revised this gist
Nov 28, 2023 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,8 @@ To ensure it's available for all initialisers, you can require the file within `config/application.rb` by adding `require_relative "settings"` as the last line within the Application class definition. The defined settings will be available via the Settings constant: e.g. `Settings.default_host` - Does not pay attention to `Rails.configuration` / `Rails.application.credentials` - it's expecting all secrets as ENV variables. - Requires dry-types and dry-system gems. - Allows for typed values (even if the above examples are all strings 😅). -
pat revised this gist
Nov 28, 2023 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,3 +5,4 @@ by adding `require_relative "settings"` as the last line within the Application - Requires dry-types and dry-system gems. - Allows for typed values (even if the above examples are all strings 😅). - Allows for optional values and defaults. - Inspired by [Hanami's approach](https://guides.hanamirb.org/v2.0/app/settings/) to such things. -
pat revised this gist
Nov 28, 2023 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,7 @@ To ensure it's available for all initialisers, you can require the file within `config/application.rb` by adding `require_relative "settings"` as the last line within the Application class definition. - Does not pay attention to `Rails.configuration` / `Rails.application.credentials` - it's expecting all secrets as ENV variables. - Requires dry-types and dry-system gems. - Allows for typed values (even if the above examples are all strings 😅). - Allows for optional values and defaults. -
pat created this gist
Nov 28, 2023 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,6 @@ To ensure it's available for all initialisers, you can require the file within `config/application.rb` by adding `require_relative "settings"` as the last line within the Application class definition. - Requires dry-types and dry-system gems. - Allows for typed values (even if the above examples are all strings 😅). - Allows for optional values and defaults. This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,31 @@ # config/settings.rb # frozen_string_literal: true require "dry/system/provider_sources/settings/config" require "dry/types" class SettingsSchema < Dry::System::ProviderSources::Settings::Config include Dry.Types() setting :bugsnag_api_key, constructor: Strict::String, default: "placeholder" setting :bugsnag_release_stage, constructor: Strict::String, default: "production" setting :default_host, constructor: Strict::String, default: "calmcalendar.com" setting :postmark_api_token, constructor: Strict::String, default: "placeholder" setting :sidekiq_username, constructor: Strict::String.optional, default: nil setting :sidekiq_password, constructor: Strict::String.optional, default: nil def verify! config._settings.each do |setting| self[setting.name] rescue Dry::Types::ConstraintError raise ArgumentError, "Missing environment variable #{setting.name.upcase}" end finalize! end end Settings = SettingsSchema.load(root: Rails.root, env: Rails.env).tap(&:verify!)