sourced_config 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b1805418799b3ae9c8b027496139bc2bbb47c4d50ee454bbc10f3fe675bf8677
4
- data.tar.gz: 8be3d42e01f8c5c8e7297eacb60b79f6f8742d9db3b013e60c62809515c2e1ef
3
+ metadata.gz: 8310a14aa124b78a0ab2edcbe7cbe64c61892581b444fb52629286a66429c7ab
4
+ data.tar.gz: a8998e0fc74c18f3a270d4034a0a7e60bcffa391c1cdfb267e00c79ec899d158
5
5
  SHA512:
6
- metadata.gz: 6d7aca269439664f6ceccbad924095e3244ed8f2a5bcc7d1c11608a0e0159a3851b51a3b00bc8c6de900121e65032073b7b8a52c5e1f84eda9ef93e332694494
7
- data.tar.gz: da4e2f05d692e8453b9b6dd69defc24f0e9e0ff29ed9211d13a951d61056f12080a5acd441bea782f4bb611f18441a66650d9e5c1189dae53d174ea377116495
6
+ metadata.gz: 7dd45f4b83c0f8e171ec6f231defa09d3633cce8100ac289ffa5a6e087eab86c2a59776f9997b12afec3a7c9b768a647480fa2fd7fb160439ccfd9bea66191bb
7
+ data.tar.gz: 967df093e6fbe881c3128b5cf55df599eecb959c0bacc327365ffbb1c255cd820fc75371db8f824fe3b9a187d2e2a7b8f1af609d477d08e0dcde4d45828ffd06
@@ -12,14 +12,7 @@ module SourcedConfig
12
12
  def copy_tasks
13
13
  template "templates/sourced_config.rb", "config/initializers/sourced_config.rb"
14
14
  template "templates/config.yml.erb", "config/config.yml.erb"
15
-
16
- application do
17
- <<RUBY
18
- # Initialise watch of application configuration
19
- config.after_initialize { |app| ::SourcedConfig.setup(app) }
20
- config.before_eager_load { |app| ::SourcedConfig.setup(app) }
21
- RUBY
22
- end
15
+ template "templates/app_config_schema.rb", "app/config/app_config_schema.rb"
23
16
  end
24
17
  end
25
18
  end
@@ -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
@@ -1,5 +1,5 @@
1
1
  locales:
2
2
  supported:
3
3
  - en
4
- # load_from_type: local-directory
4
+ load_from_type: default
5
5
  # load_from_source: customer_app/locales/
@@ -1,15 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Configure after autoloading of constants so schema class can be specified
3
+ # Configure after autoloading of constants so schema class can be specified. But we use `to_prepare` so that configuration
4
+ # is loaded before `before_eager_load` and `after_initialize` callbacks where configuration maybe needed.
4
5
  Rails.application.config.to_prepare do
5
6
  SourcedConfig.configure do |config|
6
7
  # This is the class that will be used to validate the configuration. The default is the minimum configuration
7
8
  # required, `SourcedConfig::ConfigContract` but you should create your own class that inherits from it and define
8
9
  # your own configuration schema as needed.
9
- # config.config_schema_klass = AppConfig
10
+ config.config_schema_klass = AppConfigSchema
10
11
 
11
12
  # The base configuration file path. This is always required and loaded first. It can be an ERB file.
12
- # config.base_configuration_file_path = Rails.root.join("config/config.yml.erb")
13
+ config.base_configuration_file_path = Rails.root.join("config/config.yml.erb")
13
14
 
14
15
  # The type of configuration source to use. If not specified the configuration is loaded only from the default source
15
16
  # in `base_configuration_file_path`. Can be one of:
@@ -26,4 +27,7 @@ Rails.application.config.to_prepare do
26
27
  # If the remote configuration source is an S3 bucket, the region of said bucket.
27
28
  # config.configuration_bucket_region = "us-east-1"
28
29
  end
30
+
31
+ # `to_prepare` is called on each app reload in development mode but setup only sets up file watchers once.
32
+ SourcedConfig.setup(Rails.application)
29
33
  end
@@ -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)
@@ -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
@@ -30,7 +30,7 @@ module SourcedConfig
30
30
  Rails.logger.warn "[locale - #{locale}] Using only default app copy"
31
31
  HashWithIndifferentAccess.new(locale => {})
32
32
  else
33
- raise StandardError, "When loading the Copy and Content the type was unrecognised! #{type}"
33
+ raise StandardError, "When loading the locales the type was unrecognised! #{type}"
34
34
  end
35
35
  end
36
36
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SourcedConfig
4
- VERSION = "0.3.0"
4
+ VERSION = "0.4.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sourced_config
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Ierodiaconou
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-12-16 00:00:00.000000000 Z
11
+ date: 2022-12-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-s3
@@ -82,6 +82,7 @@ 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
85
86
  - lib/generators/sourced_config/templates/config.yml.erb
86
87
  - lib/generators/sourced_config/templates/sourced_config.rb
87
88
  - lib/sourced_config.rb