Module: Pakada::Dispatch::Controller

Defined in:
lib/pakada/dispatch/controller.rb

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



11
12
13
# File 'lib/pakada/dispatch/controller.rb', line 11

def options
  @options
end

#paramsObject (readonly)

Returns the value of attribute params.



11
12
13
# File 'lib/pakada/dispatch/controller.rb', line 11

def params
  @params
end

#requestObject (readonly)

Returns the value of attribute request.



11
12
13
# File 'lib/pakada/dispatch/controller.rb', line 11

def request
  @request
end

#responseObject (readonly)

Returns the value of attribute response.



11
12
13
# File 'lib/pakada/dispatch/controller.rb', line 11

def response
  @response
end

Class Method Details

.included(klass) ⇒ Object



7
8
9
# File 'lib/pakada/dispatch/controller.rb', line 7

def self.included(klass)
  klass.extend Pakada.safety(self::ClassMethods)
end

Instance Method Details

#access_deniedObject



41
42
43
44
45
46
47
# File 'lib/pakada/dispatch/controller.rb', line 41

def access_denied
  if Pakada[:render]
    response.write "403 Access Denied" if options[:render]
    options[:render] = false
  end
  response.status = 403
end

#access_denied!Object



49
50
51
52
# File 'lib/pakada/dispatch/controller.rb', line 49

def access_denied!
  access_denied
  finish!
end

#action(name, options = {}) ⇒ Object



66
67
68
69
70
# File 'lib/pakada/dispatch/controller.rb', line 66

def action(name, options = {})
  options[:response] ||= response
  aecktschn = self.class.action(name, options)
  proc { aecktschn.call request.env }
end

#finish!Object



24
25
26
# File 'lib/pakada/dispatch/controller.rb', line 24

def finish!
  throw :finish
end

#initialize(env, options = {}) ⇒ Object



13
14
15
16
17
# File 'lib/pakada/dispatch/controller.rb', line 13

def initialize(env, options = {})
  @request = Rack::Request.new(env)
  @response = options[:response] || Rack::Response.new
  @options, @params = options, (request.env["router.params"] || {}).dup
end

#json(data) ⇒ Object



54
55
56
57
58
59
# File 'lib/pakada/dispatch/controller.rb', line 54

def json(data)
  options[:render] = false
  options[:layout] = false
  response.headers["Content-Type"] = "application/json"
  response.write MultiJson.encode(data)
end

#json!(data) ⇒ Object



61
62
63
64
# File 'lib/pakada/dispatch/controller.rb', line 61

def json!(data)
  json data
  finish!
end

#not_foundObject



28
29
30
31
32
33
34
# File 'lib/pakada/dispatch/controller.rb', line 28

def not_found
  if Pakada[:render]
    response.write "404 Not Found" if options[:render]
    options[:render] = false
  end
  response.status = 404
end

#not_found!Object



36
37
38
39
# File 'lib/pakada/dispatch/controller.rb', line 36

def not_found!
  not_found
  finish!
end

#process(&block) ⇒ Object



19
20
21
22
# File 'lib/pakada/dispatch/controller.rb', line 19

def process(&block)
  catch(:finish) { instance_eval &block }
  self
end