-
-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathsettings.rb
More file actions
44 lines (39 loc) · 1.3 KB
/
settings.rb
File metadata and controls
44 lines (39 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# frozen_string_literal: true
module Dry
module System
module ProviderSources
module Settings
class Source < Dry::System::Provider::Source
setting :store
setting :register_as, default: :settings
setting :prefix, default: ""
def prepare
require "dry/system/provider_sources/settings/config"
end
def start
register(config.register_as,
settings.load(root: target.root, env: target.config.env,
prefix: config.prefix))
end
def settings(&block)
# Save the block and evaluate it lazily to allow a provider with this source
# to `require` any necessary files for the block to evaluate correctly (e.g.
# requiring an app-specific types module for setting constructors)
if block
@settings_block = block
elsif defined? @settings_class
@settings_class
elsif @settings_block
@settings_class = Class.new(Settings::Config, &@settings_block)
end
end
end
end
end
end
end
Dry::System.register_provider_source(
:settings,
group: :dry_system,
source: Dry::System::ProviderSources::Settings::Source
)