sourced_config 0.2.2 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/generators/sourced_config/install_generator.rb +3 -1
- data/lib/generators/sourced_config/templates/app_config_schema.rb +18 -0
- data/lib/generators/sourced_config/templates/config.yml.erb +5 -0
- data/lib/generators/sourced_config/templates/sourced_config.rb +5 -5
- data/lib/sourced_config/config_contract.rb +0 -12
- data/lib/sourced_config/config_manager.rb +2 -2
- data/lib/sourced_config/locale/i18n_backend.rb +1 -1
- data/lib/sourced_config/version.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 99b9388005849ac1568ac1694edd62c06c1bdc6b94b0533393f4b753720d8447
|
4
|
+
data.tar.gz: a614d545a272b2367834ae0c45abe2a6b1a11530653090e2778ddf6baecb327e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b231f3234f177b62fff9fd6357cbc51a5ec0f8d403115f2d60f9ba30a4fe522cc388e17ebb59c5889e9aeec74211017d2d9a95a53db294f58f19711b52ed9a61
|
7
|
+
data.tar.gz: 3cd8e908f7a4012ea301aa54b618c3be41c3e681b3da831134abc679dfb5385fd8ab6e3441410db6fa4d27cfb5aae90fff6d122bd47deeed3bd1342000163091
|
@@ -11,9 +11,11 @@ module SourcedConfig
|
|
11
11
|
desc "Creates an initializer for the gem."
|
12
12
|
def copy_tasks
|
13
13
|
template "templates/sourced_config.rb", "config/initializers/sourced_config.rb"
|
14
|
+
template "templates/config.yml.erb", "config/config.yml.erb"
|
15
|
+
template "templates/app_config_schema.rb", "app/config/app_config_schema.rb"
|
14
16
|
|
15
17
|
application do
|
16
|
-
<<RUBY
|
18
|
+
<<RUBY
|
17
19
|
# Initialise watch of application configuration
|
18
20
|
config.after_initialize { |app| ::SourcedConfig.setup(app) }
|
19
21
|
config.before_eager_load { |app| ::SourcedConfig.setup(app) }
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen-string-literal: true
|
2
|
+
|
3
|
+
class AppConfigSchema < SourcedConfig::ConfigContract
|
4
|
+
class LocalesConfig < SourcedConfig::ConfigContract
|
5
|
+
params do
|
6
|
+
required(:supported).filled(array[:string])
|
7
|
+
optional(:load_from_type).filled(:string)
|
8
|
+
optional(:load_from_source).maybe(:string)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
schema do
|
13
|
+
required(:locales).hash(LocalesConfig.schema)
|
14
|
+
|
15
|
+
# TODO: Add your own config keys here...
|
16
|
+
# ...
|
17
|
+
end
|
18
|
+
end
|
@@ -2,14 +2,14 @@
|
|
2
2
|
|
3
3
|
# Configure after autoloading of constants so schema class can be specified
|
4
4
|
Rails.application.config.to_prepare do
|
5
|
-
|
5
|
+
SourcedConfig.configure do |config|
|
6
6
|
# This is the class that will be used to validate the configuration. The default is the minimum configuration
|
7
7
|
# required, `SourcedConfig::ConfigContract` but you should create your own class that inherits from it and define
|
8
8
|
# your own configuration schema as needed.
|
9
|
-
|
9
|
+
config.config_schema_klass = AppConfigSchema
|
10
10
|
|
11
11
|
# The base configuration file path. This is always required and loaded first. It can be an ERB file.
|
12
|
-
|
12
|
+
config.base_configuration_file_path = Rails.root.join("config/config.yml.erb")
|
13
13
|
|
14
14
|
# The type of configuration source to use. If not specified the configuration is loaded only from the default source
|
15
15
|
# in `base_configuration_file_path`. Can be one of:
|
@@ -17,8 +17,8 @@ Rails.application.config.to_prepare do
|
|
17
17
|
# `SourcedConfig::ConfigManager::SOURCE_TYPE_S3_CONFIG_BUCKET`
|
18
18
|
# config.config_type = SourcedConfig::ConfigManager::SOURCE_TYPE_LOCAL_FILE
|
19
19
|
|
20
|
-
# The path to the configuration file
|
21
|
-
# config.configuration_file_path =
|
20
|
+
# The path to the configuration file either locally or in S3. It *cannot* be an ERB file.
|
21
|
+
# config.configuration_file_path = "custom_config/config.yml"
|
22
22
|
|
23
23
|
# If the remote configuration source is an S3 bucket, the bucket name of said bucket.
|
24
24
|
# config.configuration_bucket = "my-bucket-name"
|
@@ -7,18 +7,6 @@ module SourcedConfig
|
|
7
7
|
class ConfigContract < ::Dry::Validation::Contract
|
8
8
|
::Dry::Validation.load_extensions(:monads)
|
9
9
|
|
10
|
-
class LocalesConfig < ConfigContract
|
11
|
-
params do
|
12
|
-
required(:supported).filled(array[:string])
|
13
|
-
optional(:load_from_type).filled(:string)
|
14
|
-
optional(:load_from_source).maybe(:string)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
params do
|
19
|
-
required(:locales).hash(LocalesConfig.schema)
|
20
|
-
end
|
21
|
-
|
22
10
|
class << self
|
23
11
|
def key_names
|
24
12
|
schema.key_map.map(&:name)
|
@@ -11,7 +11,7 @@ module SourcedConfig
|
|
11
11
|
configuration[key]
|
12
12
|
end
|
13
13
|
|
14
|
-
def load!(external_type, external_source_path)
|
14
|
+
def load!(external_type, external_source_path, schema_klass: nil)
|
15
15
|
Rails.logger.info "Load configuration data from #{external_type} - #{external_source_path}" if external_type
|
16
16
|
if loaded?
|
17
17
|
Rails.logger.warn "An attempt to load configuration happened when it is already loaded"
|
@@ -20,7 +20,7 @@ module SourcedConfig
|
|
20
20
|
primary_config = load_yaml_and_parse_erb(SourcedConfig.configuration.base_configuration_file_path).deep_symbolize_keys
|
21
21
|
external = external_type.present? && load_external_config(external_type, external_source_path).deep_symbolize_keys
|
22
22
|
|
23
|
-
schema = SourcedConfig.configuration.config_schema_klass.new
|
23
|
+
schema = (schema_klass || SourcedConfig.configuration.config_schema_klass).new
|
24
24
|
config_contract = schema.call(external ? primary_config.deep_merge(external) : primary_config)
|
25
25
|
if config_contract.failure?
|
26
26
|
messages = config_contract.errors(full: true).to_h
|
@@ -7,7 +7,7 @@ module SourcedConfig
|
|
7
7
|
module Locale
|
8
8
|
class I18nBackend < ::I18n::Backend::Simple
|
9
9
|
def load_translations
|
10
|
-
return unless ::SourcedConfig.loaded?
|
10
|
+
return unless ::SourcedConfig.loaded? && ::SourcedConfig[:locales].present?
|
11
11
|
type = ::SourcedConfig[:locales][:load_from_type]
|
12
12
|
source = ::SourcedConfig[:locales][:load_from_source]
|
13
13
|
null_client = Rails.env.test? ? NullClient.new : nil
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sourced_config
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephen Ierodiaconou
|
@@ -82,6 +82,8 @@ files:
|
|
82
82
|
- Rakefile
|
83
83
|
- lib/generators/sourced_config/USAGE
|
84
84
|
- lib/generators/sourced_config/install_generator.rb
|
85
|
+
- lib/generators/sourced_config/templates/app_config_schema.rb
|
86
|
+
- lib/generators/sourced_config/templates/config.yml.erb
|
85
87
|
- lib/generators/sourced_config/templates/sourced_config.rb
|
86
88
|
- lib/sourced_config.rb
|
87
89
|
- lib/sourced_config/config_contract.rb
|