Sha256: 77020b0aaa31344747dd639dc1af112307c9c691b439a68d626a3ae017944fc5
Contents?: true
Size: 913 Bytes
Versions: 28
Compression:
Stored size: 913 Bytes
Contents
class Rack::App::Middlewares::Params::Parser def initialize(app, descriptor) @app = app @descriptor = descriptor @merged_params_descriptor = descriptor.values.reduce(:merge) end def call(env) set_params(env) @app.call(env) end protected def set_params(env) params = Rack::App::Params.new(env).merged_params validated_params = (env[::Rack::App::Constants::ENV::VALIDATED_PARAMS] ||= {}) parse_params(validated_params, params) end def parse_params(validated_params, params) @merged_params_descriptor.each do |key, properties| next if params[key].nil? if properties[:of] validated_params[key]= [*params[key]].map{ |str| parse(properties[:of], str) } else validated_params[key]= parse(properties[:class], params[key]) end end end def parse(type, str) Rack::App::Utils::Parser.parse(type, str) end end
Version data entries
28 entries across 28 versions & 2 rubygems