Class: Rack::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/zero/rack_request.rb

Instance Method Summary collapse

Instance Method Details

#delete_param(k) ⇒ Object

Destructively delete a parameter, whether it’s in GET or POST. Returns the value of the deleted parameter.

If the parameter is in both GET and POST, the POST value takes precedence since that’s how #params works.

env is not touched.



38
39
40
41
42
# File 'lib/zero/rack_request.rb', line 38

def delete_param(k)
  v = [ self.POST.delete(k), self.GET.delete(k) ].compact.first
  @params = nil
  v
end

#update_param(k, v) ⇒ Object

Destructively update a parameter, whether it’s in GET and/or POST. Returns nil.

The parameter is updated wherever it was previous defined, so GET, POST, or both. If it wasn’t previously defined, it’s inserted into GET.

env is not touched.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/zero/rack_request.rb', line 14

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