From ffd49bffa765ebfbd174c606e0b3a7b7b168f19a Mon Sep 17 00:00:00 2001 From: Tim Donohue Date: Thu, 19 Oct 2017 21:17:41 +0000 Subject: [PATCH] Monkeypatch config gem per railsconfig/config#180 --- config/initializers/config_monkeypatch.rb | 26 +++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 config/initializers/config_monkeypatch.rb diff --git a/config/initializers/config_monkeypatch.rb b/config/initializers/config_monkeypatch.rb new file mode 100644 index 00000000..682af8ea --- /dev/null +++ b/config/initializers/config_monkeypatch.rb @@ -0,0 +1,26 @@ +# Monkey-patch config gem to support Boolean values in environment variable overrides +# This monkey-patch can be removed once this ticket is fixed & a new version of 'config' +# gem is released: https://github.com/railsconfig/config/issues/178 +Config::Options.class_eval do + protected + + # Try to convert string to a correct type + # monkey-patch this method to support boolean conversion: + # https://github.com/railsconfig/config/blob/master/lib/config/options.rb#L190 + def __value(v) + # rubocop:disable Style/RescueModifier + __boolean(v) rescue Integer(v) rescue Float(v) rescue v + # rubocop:enable Style/RescueModifier + end + + def __boolean(value) + case value + when 'false' + false + when 'true' + true + else + raise ArgumentError, "invalid value for Boolean(): #{v.inspect}" + end + end +end