Sha256: 62359e490309cd6ac9c62c53e38adb678ee19034b24b8f17424f5440bade1ebc
Contents?: true
Size: 1.18 KB
Versions: 1
Compression:
Stored size: 1.18 KB
Contents
require 'cgi' class Rack::App::Params def to_hash query_params.merge(request_path_params) end protected def initialize(request_env) @request_env = request_env end def query_params raw_cgi_params.reduce({}) do |params_collection, (k, v)| 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 def extract_path_params request_path_parts.each.with_index.reduce({}) do |params_col, (path_part, index)| params_col[path_params_matcher[index]]= path_part if path_params_matcher[index] params_col end end def request_path_parts @request_env[::Rack::App::Constants::NORMALIZED_PATH_INFO].split('/') end def path_params_matcher @request_env[::Rack::App::Constants::PATH_PARAMS_MATCHER] || {} end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rack-app-3.0.0.alpha | lib/rack/app/params.rb |