lib/rack/app/params.rb in rack-app-2.3.1 vs lib/rack/app/params.rb in rack-app-3.0.0.alpha
- old
+ new
@@ -1,33 +1,43 @@
require 'cgi'
class Rack::App::Params
- def initialize(request_env)
- @request_env = request_env
- end
-
def to_hash
query_params.merge(request_path_params)
end
protected
+ def initialize(request_env)
+ @request_env = request_env
+ end
+
def query_params
- CGI.parse(@request_env[Rack::QUERY_STRING].to_s).freeze.reduce({}) do |params_collection, (k, v)|
+ raw_cgi_params.reduce({}) do |params_collection, (k, v)|
- if v.is_a?(Array) and v.length === 1
+ if single_paramter_value?(v)
params_collection[k]= v[0]
+
else
k = k.sub(/\[\]$/, '')
params_collection[k]= v
+
end
params_collection
end
end
+ def single_paramter_value?(v)
+ v.is_a?(Array) and v.length === 1
+ end
+
+ def raw_cgi_params
+ CGI.parse(@request_env[::Rack::QUERY_STRING].to_s)
+ end
+
def request_path_params
path_params = {}
path_params.merge!(extract_path_params) unless path_params_matcher.empty?
path_params
end
@@ -38,13 +48,13 @@
params_col
end
end
def request_path_parts
- Rack::App::Utils.normalize_path(@request_env['REQUEST_PATH']).split('/')
+ @request_env[::Rack::App::Constants::NORMALIZED_PATH_INFO].split('/')
end
def path_params_matcher
- @request_env['rack.app.path_params_matcher'] || {}
+ @request_env[::Rack::App::Constants::PATH_PARAMS_MATCHER] || {}
end
end
\ No newline at end of file