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.



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

def options
  @options
end

#paramsObject (readonly)

Returns the value of attribute params.



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

def params
  @params
end

#requestObject (readonly)

Returns the value of attribute request.



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

def request
  @request
end

#responseObject (readonly)

Returns the value of attribute response.



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

def response
  @response
end

Class Method Details

.create(&block) ⇒ Object



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

def self.create(&block)
  Class.new.tap {|cls|
    cls.send :include, self
    cls.class_eval &block
  }
end

.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

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



38
39
40
41
42
# File 'lib/pakada/dispatch/controller.rb', line 38

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

#actionsObject



34
35
36
# File 'lib/pakada/dispatch/controller.rb', line 34

def actions
  self.class.actions
end

#finish!Object



30
31
32
# File 'lib/pakada/dispatch/controller.rb', line 30

def finish!
  throw :finish
end

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



20
21
22
23
24
25
26
27
28
# File 'lib/pakada/dispatch/controller.rb', line 20

def initialize(env, options = {}, &block)
  @request = Rack::Request.new(env)
  @response = options[:response] || Rack::Response.new
  
  @options, @params = options, request.env["router.params"]
  (request.env["pakada.controllers"] ||= []) << self
  
  catch(:finish) { instance_eval &block }
end