Skip to content

Commit

Permalink
Merge pull request #1463 from samvera-labs/config-monkeypatch
Browse files Browse the repository at this point in the history
Monkey-patch config gem per rubyconfig/config#180
  • Loading branch information
mjgiarlo committed Oct 19, 2017
2 parents c371972 + 64c697d commit e2783a5
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions config/initializers/config_monkeypatch.rb
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

0 comments on commit e2783a5

Please sign in to comment.