Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Installe et configure le gem config #2

Merged
merged 1 commit into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,7 @@
!/app/assets/builds/.keep

/config/credentials/development.key

config/settings.local.yml
config/settings/*.local.yml
config/environments/*.local.yml
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ gem "bootsnap", require: false
# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images]
# gem "image_processing", "~> 1.2"

gem "config"

group :development, :test do
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
gem "debug", platforms: %i[mri windows]
Expand Down
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,15 @@ GEM
regexp_parser (>= 1.5, < 3.0)
xpath (~> 3.2)
concurrent-ruby (1.2.3)
config (5.4.0)
deep_merge (~> 1.2, >= 1.2.1)
connection_pool (2.4.1)
crass (1.0.6)
date (3.3.4)
debug (1.9.2)
irb (~> 1.10)
reline (>= 0.3.8)
deep_merge (1.2.2)
drb (2.2.1)
erubi (1.12.0)
globalid (1.2.1)
Expand Down Expand Up @@ -308,6 +311,7 @@ PLATFORMS
DEPENDENCIES
bootsnap
capybara
config
debug
importmap-rails
jbuilder
Expand Down
6 changes: 2 additions & 4 deletions config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ default: &default
# For details on connection pooling, see Rails configuration guide
# https://guides.rubyonrails.org/configuring.html#database-pooling
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
username: <%= Rails.application.credentials.database.username %>
password: <%= Rails.application.credentials.database.password %>
username: <%= Settings.credentials.database.username %>
password: <%= Settings.credentials.database.password %>

development:
<<: *default
Expand Down Expand Up @@ -83,5 +83,3 @@ test:
production:
<<: *default
database: quotient_familial_production
username: quotient_familial
password: <%= ENV["QUOTIENT_FAMILIAL_DATABASE_PASSWORD"] %>
68 changes: 68 additions & 0 deletions config/initializers/config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
Config.setup do |config|
# Name of the constant exposing loaded settings
config.const_name = "Settings"

# Ability to remove elements of the array set in earlier loaded settings file. For example value: '--'.
#
# config.knockout_prefix = nil

# Overwrite an existing value when merging a `nil` value.
# When set to `false`, the existing value is retained after merge.
#
# config.merge_nil_values = true

# Overwrite arrays found in previously loaded settings file. When set to `false`, arrays will be merged.
#
# config.overwrite_arrays = true

# Defines current environment, affecting which settings file will be loaded.
# Default: `Rails.env`
#
# config.environment = ENV.fetch('ENVIRONMENT', :development)

# Load environment variables from the `ENV` object and override any settings defined in files.
#
config.use_env = false

# Define ENV variable prefix deciding which variables to load into config.
#
# Reading variables from ENV is case-sensitive. If you define lowercase value below, ensure your ENV variables are
# prefixed in the same way.
#
# When not set it defaults to `config.const_name`.
#
config.env_prefix = "SETTINGS"

# What string to use as level separator for settings loaded from ENV variables. Default value of '.' works well
# with Heroku, but you might want to change it for example for '__' to easy override settings from command line, where
# using dots in variable names might not be allowed (eg. Bash).
#
config.env_separator = "__"

# Ability to process variables names:
# * nil - no change
# * :downcase - convert to lower case
#
# config.env_converter = :downcase

# Parse numeric values as integers instead of strings.
#
# config.env_parse_values = true

# Validate presence and type of specific config values. Check https://github.com/dry-rb/dry-validation for details.
#
# config.schema do
# required(:name).filled
# required(:age).maybe(:int?)
# required(:email).filled(format?: EMAIL_REGEX)
# end

# Evaluate ERB in YAML config files at load time.
#
config.evaluate_erb_in_yaml = true

# Name of directory and file to store config keys
#
# config.file_name = 'settings'
# config.dir_name = 'settings'
end
2 changes: 2 additions & 0 deletions config/initializers/config_add_credentials.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Settings.add_source!(credentials: Rails.application.credentials.to_h)
Settings.reload!
1 change: 1 addition & 0 deletions config/settings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# keys from rails' credentials are added under "credentials" (cf config_add_credentials.rb)
Empty file added config/settings/development.yml
Empty file.
Empty file added config/settings/production.yml
Empty file.
Empty file added config/settings/test.yml
Empty file.