Class: Liquor::Rails::Request

Inherits:
Object
  • Object
show all
Includes:
External
Defined in:
lib/liquor/extensions/rails.rb

Instance Method Summary collapse

Methods included from External

included, #liquor_send

Constructor Details

#initialize(request, controller) ⇒ Request

Returns a new instance of Request



27
28
29
30
# File 'lib/liquor/extensions/rails.rb', line 27

def initialize(request, controller)
  @request    = request
  @controller = controller
end

Instance Method Details

#actionObject



59
60
61
# File 'lib/liquor/extensions/rails.rb', line 59

def action
  @controller.action_name
end

#controllerObject



55
56
57
# File 'lib/liquor/extensions/rails.rb', line 55

def controller
  @controller.controller_name
end

#escape_params(input) ⇒ Object



42
43
44
45
46
47
48
49
50
51
# File 'lib/liquor/extensions/rails.rb', line 42

def escape_params(input)
  case input
  when String
    Rack::Utils.escape_html(input)
  when Array
    input.map &method(:escape_params)
  when Hash
    Hash[input.map { |k, v| [k.to_s, escape_params(v)] }]
  end
end

#form_authenticity_tokenObject



65
66
67
68
69
70
# File 'lib/liquor/extensions/rails.rb', line 65

def form_authenticity_token
  # Sorry for sends
  if @controller.send(:protect_against_forgery?)
    @controller.send(:form_authenticity_token)
  end
end

#param(arg, kw = {}) ⇒ Object



38
39
40
# File 'lib/liquor/extensions/rails.rb', line 38

def param(arg, kw={})
  escape_params(@request.params)[arg.to_s]
end