From: Andy Allan <git@gravitystorm.co.uk>
Date: Wed, 13 Mar 2019 13:05:39 +0000 (+0100)
Subject: Install config gem for settings management
X-Git-Tag: live~4223^2~8
X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/7b08270526a34723f1bb9f68a1f0878838714b15

Install config gem for settings management
---

diff --git a/.gitignore b/.gitignore
index 1a2d35c6a..17112bf8a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -13,3 +13,7 @@ doc
 .ruby-version
 .idea
 coverage
+
+config/settings.local.yml
+config/settings/*.local.yml
+config/environments/*.local.yml
diff --git a/Gemfile b/Gemfile
index 275388666..96d696561 100644
--- a/Gemfile
+++ b/Gemfile
@@ -48,6 +48,7 @@ gem "actionpack-page_caching"
 gem "active_record_union"
 gem "cancancan"
 gem "composite_primary_keys", "~> 11.1.0"
+gem "config"
 gem "delayed_job_active_record"
 gem "dynamic_form"
 gem "http_accept_language", "~> 2.0.0"
diff --git a/Gemfile.lock b/Gemfile.lock
index 0dd07a95e..702ee49a1 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -92,6 +92,10 @@ GEM
     composite_primary_keys (11.1.0)
       activerecord (~> 5.2.1)
     concurrent-ruby (1.1.4)
+    config (1.7.1)
+      activesupport (>= 3.0)
+      deep_merge (~> 1.2.1)
+      dry-validation (>= 0.12.2)
     coveralls (0.8.22)
       json (>= 1.8, < 3)
       simplecov (~> 0.16.1)
@@ -103,12 +107,41 @@ GEM
     crass (1.0.4)
     dalli (2.7.9)
     debug_inspector (0.0.3)
+    deep_merge (1.2.1)
     delayed_job (4.1.5)
       activesupport (>= 3.0, < 5.3)
     delayed_job_active_record (4.1.3)
       activerecord (>= 3.0, < 5.3)
       delayed_job (>= 3.0, < 5)
     docile (1.3.1)
+    dry-configurable (0.8.2)
+      concurrent-ruby (~> 1.0)
+      dry-core (~> 0.4, >= 0.4.7)
+    dry-container (0.7.0)
+      concurrent-ruby (~> 1.0)
+      dry-configurable (~> 0.1, >= 0.1.3)
+    dry-core (0.4.7)
+      concurrent-ruby (~> 1.0)
+    dry-equalizer (0.2.2)
+    dry-inflector (0.1.2)
+    dry-logic (0.5.0)
+      dry-container (~> 0.2, >= 0.2.6)
+      dry-core (~> 0.2)
+      dry-equalizer (~> 0.2)
+    dry-types (0.14.0)
+      concurrent-ruby (~> 1.0)
+      dry-container (~> 0.3)
+      dry-core (~> 0.4, >= 0.4.4)
+      dry-equalizer (~> 0.2)
+      dry-inflector (~> 0.1, >= 0.1.2)
+      dry-logic (~> 0.5, >= 0.5)
+    dry-validation (0.13.0)
+      concurrent-ruby (~> 1.0)
+      dry-configurable (~> 0.1, >= 0.1.3)
+      dry-core (~> 0.2, >= 0.2.1)
+      dry-equalizer (~> 0.2)
+      dry-logic (~> 0.5, >= 0.5.0)
+      dry-types (~> 0.14, >= 0.14)
     dynamic_form (1.1.4)
     erubi (1.8.0)
     execjs (2.7.0)
@@ -401,6 +434,7 @@ DEPENDENCIES
   capybara (~> 2.13)
   coffee-rails (~> 4.2)
   composite_primary_keys (~> 11.1.0)
+  config
   coveralls
   dalli
   delayed_job_active_record
diff --git a/config/initializers/config.rb b/config/initializers/config.rb
new file mode 100644
index 000000000..3d8236161
--- /dev/null
+++ b/config/initializers/config.rb
@@ -0,0 +1,49 @@
+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
+
+  # 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.
+  #
+  # 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
+end
diff --git a/config/settings.yml b/config/settings.yml
new file mode 100644
index 000000000..e69de29bb
diff --git a/config/settings/development.yml b/config/settings/development.yml
new file mode 100644
index 000000000..e69de29bb
diff --git a/config/settings/production.yml b/config/settings/production.yml
new file mode 100644
index 000000000..e69de29bb
diff --git a/config/settings/test.yml b/config/settings/test.yml
new file mode 100644
index 000000000..e69de29bb