Permalink
Browse files

Extract the value casting to a method

  • Loading branch information...
1 parent 45883a3 commit 2b60a6b664606b0b52851ff811231728b7c65032 @rafaelfranca rafaelfranca committed Jan 31, 2013
Showing with 23 additions and 15 deletions.
  1. +23 −15 activerecord/lib/active_record/connection_adapters/connection_specification.rb
@@ -76,30 +76,38 @@ def connection_url_to_hash(url) # :nodoc:
: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

0 comments on commit 2b60a6b

Please sign in to comment.