Skip to content

Commit 351d382

Browse files
authored
Merge pull request #2 from etalab/install-config
Installe et configure le gem config
2 parents 991fd90 + 1247605 commit 351d382

File tree

10 files changed

+83
-4
lines changed

10 files changed

+83
-4
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,7 @@
3838
!/app/assets/builds/.keep
3939

4040
/config/credentials/development.key
41+
42+
config/settings.local.yml
43+
config/settings/*.local.yml
44+
config/environments/*.local.yml

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ gem "bootsnap", require: false
4444
# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images]
4545
# gem "image_processing", "~> 1.2"
4646

47+
gem "config"
48+
4749
group :development, :test do
4850
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
4951
gem "debug", platforms: %i[mri windows]

Gemfile.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,15 @@ GEM
9494
regexp_parser (>= 1.5, < 3.0)
9595
xpath (~> 3.2)
9696
concurrent-ruby (1.2.3)
97+
config (5.4.0)
98+
deep_merge (~> 1.2, >= 1.2.1)
9799
connection_pool (2.4.1)
98100
crass (1.0.6)
99101
date (3.3.4)
100102
debug (1.9.2)
101103
irb (~> 1.10)
102104
reline (>= 0.3.8)
105+
deep_merge (1.2.2)
103106
drb (2.2.1)
104107
erubi (1.12.0)
105108
globalid (1.2.1)
@@ -308,6 +311,7 @@ PLATFORMS
308311
DEPENDENCIES
309312
bootsnap
310313
capybara
314+
config
311315
debug
312316
importmap-rails
313317
jbuilder

config/database.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ default: &default
1919
# For details on connection pooling, see Rails configuration guide
2020
# https://guides.rubyonrails.org/configuring.html#database-pooling
2121
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
22-
username: <%= Rails.application.credentials.database.username %>
23-
password: <%= Rails.application.credentials.database.password %>
22+
username: <%= Settings.credentials.database.username %>
23+
password: <%= Settings.credentials.database.password %>
2424

2525
development:
2626
<<: *default
@@ -83,5 +83,3 @@ test:
8383
production:
8484
<<: *default
8585
database: quotient_familial_production
86-
username: quotient_familial
87-
password: <%= ENV["QUOTIENT_FAMILIAL_DATABASE_PASSWORD"] %>

config/initializers/config.rb

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
Config.setup do |config|
2+
# Name of the constant exposing loaded settings
3+
config.const_name = "Settings"
4+
5+
# Ability to remove elements of the array set in earlier loaded settings file. For example value: '--'.
6+
#
7+
# config.knockout_prefix = nil
8+
9+
# Overwrite an existing value when merging a `nil` value.
10+
# When set to `false`, the existing value is retained after merge.
11+
#
12+
# config.merge_nil_values = true
13+
14+
# Overwrite arrays found in previously loaded settings file. When set to `false`, arrays will be merged.
15+
#
16+
# config.overwrite_arrays = true
17+
18+
# Defines current environment, affecting which settings file will be loaded.
19+
# Default: `Rails.env`
20+
#
21+
# config.environment = ENV.fetch('ENVIRONMENT', :development)
22+
23+
# Load environment variables from the `ENV` object and override any settings defined in files.
24+
#
25+
config.use_env = false
26+
27+
# Define ENV variable prefix deciding which variables to load into config.
28+
#
29+
# Reading variables from ENV is case-sensitive. If you define lowercase value below, ensure your ENV variables are
30+
# prefixed in the same way.
31+
#
32+
# When not set it defaults to `config.const_name`.
33+
#
34+
config.env_prefix = "SETTINGS"
35+
36+
# What string to use as level separator for settings loaded from ENV variables. Default value of '.' works well
37+
# with Heroku, but you might want to change it for example for '__' to easy override settings from command line, where
38+
# using dots in variable names might not be allowed (eg. Bash).
39+
#
40+
config.env_separator = "__"
41+
42+
# Ability to process variables names:
43+
# * nil - no change
44+
# * :downcase - convert to lower case
45+
#
46+
# config.env_converter = :downcase
47+
48+
# Parse numeric values as integers instead of strings.
49+
#
50+
# config.env_parse_values = true
51+
52+
# Validate presence and type of specific config values. Check https://github.com/dry-rb/dry-validation for details.
53+
#
54+
# config.schema do
55+
# required(:name).filled
56+
# required(:age).maybe(:int?)
57+
# required(:email).filled(format?: EMAIL_REGEX)
58+
# end
59+
60+
# Evaluate ERB in YAML config files at load time.
61+
#
62+
config.evaluate_erb_in_yaml = true
63+
64+
# Name of directory and file to store config keys
65+
#
66+
# config.file_name = 'settings'
67+
# config.dir_name = 'settings'
68+
end
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Settings.add_source!(credentials: Rails.application.credentials.to_h)
2+
Settings.reload!

config/settings.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# keys from rails' credentials are added under "credentials" (cf config_add_credentials.rb)

config/settings/development.yml

Whitespace-only changes.

config/settings/production.yml

Whitespace-only changes.

config/settings/test.yml

Whitespace-only changes.

0 commit comments

Comments
 (0)