Module: ActionDispatch::ParamBuilder

Defined in:
runtime/action_dispatch/param_builder.rb

Defined Under Namespace

Classes: Invalid

Constant Summary collapse

DEPTH_LIMIT =
100

Class Method Summary collapse

Class Method Details

.build(keys, values, present) ⇒ Hash

the nested params for the pairs.

Examples:

ActionDispatch::ParamBuilder.build(["a[]"], ["1"], [true])   # => { "a" => ["1"] }

Parameters:

  • keys (Array<String>) —

    the decoded parameter names

  • values (Array<String>) —

    the decoded values ("" where the pair carried none)

  • present (Array<Boolean>) —

    which pairs carried a value

Returns:

  • (Hash) —

    the nested params; nil where the input is a 400



32
33
34
35
36
37
38
39
40
41
42
43
# File 'runtime/action_dispatch/param_builder.rb', line 32

def self.build(keys, values, present)
  params = {}
  i = 0
  while i < keys.length
    v = present[i] ? values[i] : nil
    store(params, keys[i], v, 0)
    i += 1
  end
  params
rescue ParamBuilder::Invalid
  nil
end

.from_query_string(s) ⇒ Hash

a query string (or an urlencoded body) straight to the nested params.

Examples:

ActionDispatch::ParamBuilder.from_query_string("a[b]=1")   # => { "a" => { "b" => "1" } }

Parameters:

  • s (String) —

    the raw query string

Returns:

  • (Hash) —

    the nested params; nil where the input is a 400



51
52
53
54
55
56
57
# File 'runtime/action_dispatch/param_builder.rb', line 51

def self.from_query_string(s)
  keys = []
  values = []
  present = []
  return nil unless split(s, keys, values, present)
  ActionDispatch::ParamBuilder.build(keys, values, present)
end