Module: TyphoeusFix

Defined in:
lib/typhoeus_fix/array_decoder.rb

Overview

Typhoeus encodes arrays as hashes {‘0’ => v0, ‘1’ => v1, .., ‘n’ => vN }

To fix this in your rails server your should: in Gemfile:

gem 'logical_model', '~> 0.3.2'

in application_controller.rb:

require 'typhoeus_fix/array_decoder'
class ApplicationController < ActionController::Base
  include TyphoeusFix
  before_filter :decode_typhoeus_arrays
end

Instance Method Summary collapse

Instance Method Details

#decode(hash) ⇒ Object



46
47
48
# File 'lib/typhoeus_fix/array_decoder.rb', line 46

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.



35
36
37
38
39
40
41
42
43
44
# File 'lib/typhoeus_fix/array_decoder.rb', line 35

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



26
27
28
# File 'lib/typhoeus_fix/array_decoder.rb', line 26

def decode_typhoeus_arrays
  decode!(params)
end