-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1463 from samvera-labs/config-monkeypatch
Monkey-patch config gem per rubyconfig/config#180
- Loading branch information
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |