Module: Rack::Typhoeus::Middleware::ParamsDecoder::Helper

Included in:
Rack::Typhoeus::Middleware::ParamsDecoder
Defined in:
lib/rack/typhoeus/middleware/params_decoder/helper.rb

Overview

Since:

  • 0.5.4

Instance Method Summary collapse

Instance Method Details

#decode(hash) ⇒ Object

Since:

  • 0.5.4



36
37
38
# File 'lib/rack/typhoeus/middleware/params_decoder/helper.rb', line 36

def decode(hash)
  decode!(hash.dup)
end

#decode!(hash) ⇒ Hash

Recursively decodes Typhoeus encoded arrays in given Hash.

Parameters:

  • hash (Hash)

    . This Hash will be modified!

Returns:

  • (Hash)

    Hash with properly decoded nested arrays.

Since:

  • 0.5.4



25
26
27
28
29
30
31
32
33
34
# File 'lib/rack/typhoeus/middleware/params_decoder/helper.rb', line 25

def decode!(hash)
  return hash unless hash.is_a?(Hash)
  hash.each_pair do |key,value|
    if value.is_a?(Hash)
      decode!(value)
      hash[key] = convert(value)
    end
  end
  hash
end

#decode_typhoeus_arraysObject

Recursively decodes Typhoeus encoded arrays in given Hash.

Examples:

Use directly in a Rails controller.

class ApplicationController
   before_filter :decode_typhoeus_arrays
end

Author:

  • Dwayne Macgowan

Since:

  • 0.5.4



16
17
18
# File 'lib/rack/typhoeus/middleware/params_decoder/helper.rb', line 16

def decode_typhoeus_arrays
  decode!(params)
end