Class: RackUndefined

Inherits:
Struct
  • Object
show all
Defined in:
lib/rack-undefined.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#appObject

Returns the value of attribute app

Returns:

  • (Object)

    the current value of app



2
3
4
# File 'lib/rack-undefined.rb', line 2

def app
  @app
end

Instance Method Details

#call(env) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/rack-undefined.rb', line 5

def call(env)
  request = Rack::Request.new(env)
  request.params.each do |key, value|
    request.update_param key, undefine(value)
  end
  app.call(env)
end

#undefine(obj) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/rack-undefined.rb', line 13

def undefine(obj)
  case obj
  when "null", "undefined"
    nil
  when Array
    obj.map(&undefine)
  when Hash
    Hash[obj.map(&undefine)]
  else
    obj
  end
end