Module: Pakada::Dispatch::Controller
- Defined in:
- lib/pakada/dispatch/controller.rb
Defined Under Namespace
Modules: ClassMethods
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Class Method Summary collapse
Instance Method Summary collapse
- #access_denied ⇒ Object
- #access_denied! ⇒ Object
- #action(name, options = {}) ⇒ Object
- #finish! ⇒ Object
- #initialize(env, options = {}) ⇒ Object
- #json(data) ⇒ Object
- #json!(data) ⇒ Object
- #not_found ⇒ Object
- #not_found! ⇒ Object
- #process(&block) ⇒ Object
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
11 12 13 |
# File 'lib/pakada/dispatch/controller.rb', line 11 def @options end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
11 12 13 |
# File 'lib/pakada/dispatch/controller.rb', line 11 def params @params end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
11 12 13 |
# File 'lib/pakada/dispatch/controller.rb', line 11 def request @request end |
#response ⇒ Object (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_denied ⇒ Object
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 [:render] [: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, = {}) [:response] ||= response aecktschn = self.class.action(name, ) 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, = {}) @request = Rack::Request.new(env) @response = [:response] || Rack::Response.new @options, @params = , (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) [:render] = false [: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_found ⇒ Object
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 [:render] [: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 |