sourced_config 0.1.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 69ed9d6e744d01d64ddfda05e9cc9ed81dc1d41a96b5c91042e7e862e92956f2
|
4
|
+
data.tar.gz: 360c51a9aadbe749ba6ed43ee5a43dd9faf1ba7f6ab2fc6d9be3aee2612636b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 01b98b7c96e8bec76a2df66ec738bc8acae52f1457ae2f6634962d3c3f72f1f6708809274fe3387ce3d219e7816fbe5fbd85b1012f0cb7e1a2049a4a99d94a5b
|
7
|
+
data.tar.gz: '08e0f84976d02465067ae5084978fa942780c2db62d07b52a3256885001f8be06cb3da4a0e71e2a2d4161a40519fd5018fc32a2ae51604168f2c36d6a81b1d87'
|
data/README.md
CHANGED
@@ -23,14 +23,56 @@ If bundler is not being used to manage dependencies, install the gem by executin
|
|
23
23
|
|
24
24
|
$ gem install sourced_config
|
25
25
|
|
26
|
-
|
26
|
+
Then install the initializer by executing:
|
27
|
+
|
28
|
+
$ rails g sourced_config:install
|
27
29
|
|
28
|
-
TODO: Write usage instructions here
|
29
30
|
|
30
|
-
|
31
|
-
|
31
|
+
## Usage
|
32
|
+
|
32
33
|
|
33
|
-
|
34
|
+
### Setup:
|
35
|
+
|
36
|
+
1. Add an initializer to your app to configure the gem (eg with the generator `rails g sourced_config:install`)
|
37
|
+
- To manually install create an initializer, and add the following to your `Application` class:
|
38
|
+
```ruby
|
39
|
+
# Initialise watch of application configuration
|
40
|
+
config.after_initialize { |app| ::SourcedConfig.setup(app) }
|
41
|
+
config.before_eager_load { |app| ::SourcedConfig.setup(app) }
|
42
|
+
```
|
43
|
+
2. Add a schema class to your app to define the config schema (eg `app/config/app_contract.rb` which inherits from `SourcedConfig::ConfigContract`)
|
44
|
+
3. Configure your app for the `aws-sdk-s3` gem
|
45
|
+
- If you are using the `aws-sdk-s3` gem in your app, you can skip this step
|
46
|
+
- otherwise read `https://github.com/aws/aws-sdk-ruby#configuration`
|
47
|
+
4. Add a base config file to your app (eg `config/config.yml.erb` as per your initializer)
|
48
|
+
|
49
|
+
### Example schema:
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
class AppContract < SourcedConfig::ConfigContract
|
53
|
+
class ColorContract < SourcedConfig::ConfigContract
|
54
|
+
params do
|
55
|
+
optional(:header).maybe(:string)
|
56
|
+
optional(:footer).maybe(:string)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
params do
|
61
|
+
required(:environment).filled(:string)
|
62
|
+
required(:app_name).filled(:string)
|
63
|
+
optional(:colors).hash(ColorContract.schema)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
```
|
67
|
+
|
68
|
+
### Accessing configuration:
|
69
|
+
|
70
|
+
Access config values in your code with `SourcedConfig[key]`
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
SourcedConfig[:environment]
|
74
|
+
SourcedConfig[:colors][:footer]
|
75
|
+
```
|
34
76
|
|
35
77
|
## Development
|
36
78
|
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rails/generators/base"
|
4
|
+
|
5
|
+
module SourcedConfig
|
6
|
+
module Generators
|
7
|
+
# The Install generator `sourced_config:install`
|
8
|
+
class InstallGenerator < ::Rails::Generators::Base
|
9
|
+
source_root File.expand_path(__dir__)
|
10
|
+
|
11
|
+
desc "Creates an initializer for the gem."
|
12
|
+
def copy_tasks
|
13
|
+
template "templates/sourced_config.rb", "config/initializers/sourced_config.rb"
|
14
|
+
|
15
|
+
application do
|
16
|
+
<<RUBY
|
17
|
+
# Initialise watch of application configuration
|
18
|
+
config.after_initialize { |app| ::SourcedConfig.setup(app) }
|
19
|
+
config.before_eager_load { |app| ::SourcedConfig.setup(app) }
|
20
|
+
RUBY
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
SourcedConfig.configure do |config|
|
4
|
+
# This is the class that will be used to validate the configuration. The default is the minimum configuration
|
5
|
+
# required, `SourcedConfig::ConfigContract` but you should create your own class that inherits from it and define
|
6
|
+
# your own configuration schema as needed.
|
7
|
+
# config.config_schema_klass = SourcedConfig::ConfigContract
|
8
|
+
|
9
|
+
# The base configuration file path. This is always required and loaded first. It can be an ERB file.
|
10
|
+
# config.base_configuration_file_path = Rails.root.join("config/config.yml.erb")
|
11
|
+
|
12
|
+
# The type of configuration source to use. If not specified the configuration is loaded only from the default source
|
13
|
+
# in `base_configuration_file_path`. Can be one of:
|
14
|
+
# `SourcedConfig::ConfigManager::SOURCE_TYPE_LOCAL_FILE`
|
15
|
+
# `SourcedConfig::ConfigManager::SOURCE_TYPE_S3_CONFIG_BUCKET`
|
16
|
+
# config.config_type = SourcedConfig::ConfigManager::SOURCE_TYPE_LOCAL_FILE
|
17
|
+
|
18
|
+
# The path to the configuration file if loading a local file. It *cannot* be an ERB file.
|
19
|
+
# config.configuration_file_path = Rails.root.join("custom_config/config.yml")
|
20
|
+
|
21
|
+
# If the remote configuration source is an S3 bucket, the bucket name of said bucket.
|
22
|
+
# config.configuration_bucket = "my-bucket-name"
|
23
|
+
|
24
|
+
# If the remote configuration source is an S3 bucket, the region of said bucket.
|
25
|
+
# config.configuration_bucket_region = "us-east-1"
|
26
|
+
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.1
|
4
|
+
version: 0.2.1
|
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-
|
11
|
+
date: 2022-12-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk-s3
|
@@ -80,6 +80,9 @@ files:
|
|
80
80
|
- LICENSE.txt
|
81
81
|
- README.md
|
82
82
|
- Rakefile
|
83
|
+
- lib/generators/sourced_config/USAGE
|
84
|
+
- lib/generators/sourced_config/install_generator.rb
|
85
|
+
- lib/generators/sourced_config/templates/sourced_config.rb
|
83
86
|
- lib/sourced_config.rb
|
84
87
|
- lib/sourced_config/config_contract.rb
|
85
88
|
- lib/sourced_config/config_manager.rb
|
@@ -114,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
114
117
|
- !ruby/object:Gem::Version
|
115
118
|
version: '0'
|
116
119
|
requirements: []
|
117
|
-
rubygems_version: 3.3.
|
120
|
+
rubygems_version: 3.3.26
|
118
121
|
signing_key:
|
119
122
|
specification_version: 4
|
120
123
|
summary: Load configuration & locales for Rails apps from a remote or local non-repo
|