class Rack::App::Params
Constants
- E
Public Class Methods
new(env)
click to toggle source
# File lib/rack/app/params.rb, line 29 def initialize(env) @env = env end
Public Instance Methods
merged_params()
click to toggle source
# File lib/rack/app/params.rb, line 11 def merged_params @env[E::MERGED_PARAMS] ||= query_string_params.merge(path_segments_params) end
path_segments_params()
click to toggle source
# File lib/rack/app/params.rb, line 19 def path_segments_params @env[E::PATH_SEGMENTS_PARAMS] end
query_string_params()
click to toggle source
# File lib/rack/app/params.rb, line 15 def query_string_params @env[E::QUERY_STRING_PARAMS] ||= generate_query_params end
to_hash()
click to toggle source
# File lib/rack/app/params.rb, line 7 def to_hash validated_params || merged_params end
validated_params()
click to toggle source
# File lib/rack/app/params.rb, line 23 def validated_params @env[E::VALIDATED_PARAMS] end
Protected Instance Methods
formatted_value(key, value)
click to toggle source
# File lib/rack/app/params.rb, line 44 def formatted_value(key, value) single_paramter_value?(value) && !key.end_with?('[]') ? value[0] : value end
generate_query_params()
click to toggle source
# File lib/rack/app/params.rb, line 33 def generate_query_params raw_rack_formatted_params.reduce({}) do |params_collection, (k, v)| params_collection[k.sub(/\[\]$/, '')] = v params_collection end end
params_that_presented_multiple_times()
click to toggle source
# File lib/rack/app/params.rb, line 56 def params_that_presented_multiple_times cgi_params = CGI.parse(query_string) cgi_params.reject! { |k, v| v.length == 1 && k !~ /^\w+$/ } cgi_params.reduce({}) do |result, (key, value)| result[key] = formatted_value(key, value) result end end
query_string()
click to toggle source
# File lib/rack/app/params.rb, line 48 def query_string @env[::Rack::QUERY_STRING] end
raw_rack_formatted_params()
click to toggle source
# File lib/rack/app/params.rb, line 52 def raw_rack_formatted_params ::Rack::Utils.parse_nested_query(query_string).merge!(params_that_presented_multiple_times) end
single_paramter_value?(v)
click to toggle source
# File lib/rack/app/params.rb, line 40 def single_paramter_value?(v) v.is_a?(Array) && v.length === 1 end