class MmunicodeRails::RackMmunicode

Public Class Methods

new(app) click to toggle source
# File lib/mmunicode_rails.rb, line 289
def initialize(app)
        @app = app
end

Public Instance Methods

call(env) click to toggle source
# File lib/mmunicode_rails.rb, line 294
def call(env)
        request = Rack::Request.new env
        #This monkey patching is a hack for rack 1.4.5 compatibility required for rails 3.2.*
        unless request.respond_to? :update_param then
                request.instance_eval do
                       def update_param(k, v)
                             found = false
                             if self.GET.has_key?(k)
                               found = true
                               self.GET[k] = v
                             end
                             if self.POST.has_key?(k)
                               found = true
                               self.POST[k] = v
                             end
                             unless found
                               self.GET[k] = v
                             end
                             @params = nil
                             nil
                       end
                end
        end
        converted_params = []
        request.params.each_pair do|key,value|
                puts "#{key}: #{value}"
        end
        converted_params = nested_param_traversal(request.params)
        
        converted_params.each_pair do|key,value|
                puts "#{key}: #{value}"
                request.params[key] = value
        end
        @app.call(env)
end
update_param(k, v) click to toggle source
# File lib/mmunicode_rails.rb, line 299
def update_param(k, v)
      found = false
      if self.GET.has_key?(k)
        found = true
        self.GET[k] = v
      end
      if self.POST.has_key?(k)
        found = true
        self.POST[k] = v
      end
      unless found
        self.GET[k] = v
      end
      @params = nil
      nil
end

Private Instance Methods

nested_param_traversal(param) click to toggle source
# File lib/mmunicode_rails.rb, line 331
def nested_param_traversal(param)
        if param.respond_to? :each_pair
                param.each_pair do|k,v|
                        param[k] = nested_param_traversal(v)
                end
        elsif param.is_a? Array
                param.map do |item|
                        nested_param_traversal(item)
                end
        else
                # convert only strings , otherwise untouch
            if param.is_a? String then zg12uni51(param) else param end
        end
end