diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-01-31 17:48:37 -0200 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-01-31 17:48:37 -0200 |
commit | 2b60a6b664606b0b52851ff811231728b7c65032 (patch) | |
tree | aef9f9c6b497e512f311b702e349070fd0ff6512 /activerecord/lib | |
parent | 45883a32963734e2e6741847307340d82ed72446 (diff) | |
download | rails-2b60a6b664606b0b52851ff811231728b7c65032.tar.gz rails-2b60a6b664606b0b52851ff811231728b7c65032.tar.bz2 rails-2b60a6b664606b0b52851ff811231728b7c65032.zip |
Extract the value casting to a method
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/connection_specification.rb | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/connection_specification.rb b/activerecord/lib/active_record/connection_adapters/connection_specification.rb index d7cd34df22..1aeccf4444 100644 --- a/activerecord/lib/active_record/connection_adapters/connection_specification.rb +++ b/activerecord/lib/active_record/connection_adapters/connection_specification.rb @@ -76,30 +76,38 @@ module ActiveRecord :port => config.port, :database => config.path.sub(%r{^/},""), :host => config.host } + spec.reject!{ |_,value| value.blank? } + uri_parser = URI::Parser.new + spec.map { |key,value| spec[key] = uri_parser.unescape(value) if value.is_a?(String) } + if config.query options = Hash[config.query.split("&").map{ |pair| pair.split("=") }].symbolize_keys - # If anything looks numeric, make it numeric (e.g. pool count, timeout values, etc.) - options.map do |key,value| - options[key] = case value - when SIMPLE_INT - value.to_i - when SIMPLE_FLOAT - value.to_f - when 'true' - true - when 'false' - false - else - value - end - end + + options.each { |key, value| options[key] = type_cast_value(value) } + spec.merge!(options) end + spec end + + def type_cast_value(value) + case value + when SIMPLE_INT + value.to_i + when SIMPLE_FLOAT + value.to_f + when 'true' + true + when 'false' + false + else + value + end + end end end end |