sourced_config 0.1.0 → 0.2.0

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: 67bcae6215d95ddc63e2dd5522805c69b73c4357756160d765a9f5581404152d
4
- data.tar.gz: e6d714e45c36234238ff22c7c1390273de3df7b4c9d6ea1f52ee9829946f8ff4
3
+ metadata.gz: 7dfe40bcfa6018fed56ca0031fc925a621f7efefac5c840fd403a0b87a0fb546
4
+ data.tar.gz: b1ab2ef0c2d10068aedefd39c236c9c5012952896333977180775b7953f5d0ab
5
5
  SHA512:
6
- metadata.gz: 8d786b59013736cceb1435f5e88351cff813658f88ba88a0a1a927f32c2ad5baf5668b7ed7565179b880f21de5c206cb8b89454798c6545dbc52f8c7578d74ba
7
- data.tar.gz: 977b760623e3e29f545de365193b83c2f1555274ed53c68dcb6941b13d56beec8b3b7c976703998a57a8ad04ad1c58c198b6eab451336a37748a0804e408f92d
6
+ metadata.gz: 5315cacb05c9f4fd5e4d937820fa5b3cc7eb35e2a457fd39df08cba91eb06ea0a306095f6f9bc188eb98d81a0ef95b72053a23d2fe5fae8992af2d0c8706b338
7
+ data.tar.gz: 36e2f37091f40b74adb0173a89012a35e7a126bafa7caeee37a74b44b0fccf6d68acca9b9ea753645ca64d4421979f85b0a937d5433011f250fba96dc9ad9df7
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
- ## Usage
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
- - Add an initializer to your app to configure the gem
31
- - Add a base config file to your app
31
+ ## Usage
32
+
32
33
 
33
- Access config with `SourcedConfig[key]`
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,3 @@
1
+ Creates an initialiser:
2
+
3
+ rails generate sourced_config:install
@@ -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
+ append_to_file 'config/application.rb' 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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SourcedConfig
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.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.1.0
4
+ version: 0.2.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-11-22 00:00:00.000000000 Z
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.7
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