Module: Appydays::Configurable
- Included in:
- Loggable::SidekiqJobLogger
- Defined in:
- lib/appydays/configurable.rb
Overview
Define the configuration for a module or class.
Usage:
include Appydays::Configurable
configurable(:myapp) do
setting :log_level, 'debug', env: 'LOG_LEVEL'
setting :app_url, 'http://localhost:3000'
setting :workers, 4
end
The module or class that extends Configurable will get two singleton methods, ‘log_level` and `app_url`. The first will be be given a value of `ENV.fetch(’LOG_LEVEL’, ‘debug’)‘, because the env key is provided.
The second will be given a value of ‘ENV.fetch(’MYAPP_APP_URL’, ‘://localhost:3000’)‘, because the env key is defaulted.
The second will be given a value of ‘4.class(ENV.fetch(’MYAPP_WORKERS’, 4))‘. Note it will coerce the type of the env value to the type of the default. Empty strings will be coerced to nil.
The ‘setting` method has several other options; see its documentation for more details.
The target will also get a ‘reset_configuration` method that will restore defaults, and `run_after_configured_hooks`. See their docs for more details.
Defined Under Namespace
Modules: ClassMethods, SpecHelpers Classes: Installer
Class Method Summary collapse
Class Method Details
.included(target) ⇒ Object
35 36 37 |
# File 'lib/appydays/configurable.rb', line 35 def self.included(target) target.extend(ClassMethods) end |