Module: Faraday::DecodeMethods

Included in:
NestedParamsEncoder
Defined in:
lib/faraday/encoders/nested_params_encoder.rb

Overview

Sub-module for decoding query-string into parameters.

Instance Method Summary collapse

Instance Method Details

#decode(query) ⇒ Array<Array, String>

Returns the decoded params.

Parameters:

  • query (nil, String)

Returns:

  • (Array<Array, String>)

    the decoded params

Raises:

  • (TypeError)

    if the nesting is incorrect


81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/faraday/encoders/nested_params_encoder.rb', line 81

def decode(query)
  return nil if query.nil?

  params = {}
  query.split('&').each do |pair|
    next if pair.empty?

    key, value = pair.split('=', 2)
    key = unescape(key)
    value = unescape(value.tr('+', ' ')) if value
    decode_pair(key, value, params)
  end

  dehash(params, 0)
end