Class: Rango::Controller
- Object
- Rango::Controller
Included Modules
Rango::HttpExceptions, Rango::Helpers, Rango::ControllerMixin, Rango::Templates::TemplateHelpers
Attributes
Instance Attributes
session | [RW] | public |
Returns the value of attribute session. |
---|
Constructor Summary
public
initialize(request, params)
[View source]
102 103 104 105 106 107 108 |
# File 'lib/rango/mvc/controller.rb', line 102 def initialize(request, params) @request = request @params = params = request. @session = request.session Rango.logger.inspect(params: params, : , session: session) end |
Public Visibility
Public Class Method Summary
after(action = nil, options = Hash.new, &block) | |
---|---|
before(action = nil, options = Hash.new, &block) |
before :login before :login, actions: [:send]. |
call(env) |
|
controller? | |
get_filters(type) | |
inherited(subclass) | |
proceed_value(value) | |
route_to(env, action, params = Hash.new) |
Public Class Methods Included from Rango::Helpers
Public Instance Method Summary
#route_to(action, params = Hash.new) | |
---|---|
#run_filters(name, method) |
Public Instance Methods Included from Rango::Helpers
copyright, error_messages_for, javascript, javascripts, link_item, link_to, mail_to, markdown, maruku, stylesheet, stylesheets, syntax, textile
Public Instance Methods Included from Rango::ControllerMixin
autorender, capture, concat, display, layout, message, redirect, render, template_location
Public Instance Methods Included from Rango::Templates::TemplateHelpers
Public Class Method Details
after
public
after(action = nil, options = Hash.new, &block)
[View source]
40 41 42 |
# File 'lib/rango/mvc/controller.rb', line 40 def after(action = nil, = Hash.new, &block) self.after_filters[action || block] = end |
before
public
before(action = nil, options = Hash.new, &block)
before :login before :login, actions: [:send]
[View source]
35 36 37 |
# File 'lib/rango/mvc/controller.rb', line 35 def before(action = nil, = Hash.new, &block) self.before_filters[action || block] = end |
call
public
call(env)
- master
- Change Merb::Controller to respond to #call and return a Rack Array. (wycats)rubyurl.com/BhoY
[View source]
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/rango/mvc/controller.rb', line 46 def call(env) self.set_rack_env(env) request = Rango::Request.new(env) = env["rango.router.params"] method = [:action] || :index response = Rack::Response.new controller = self.new(request, .merge(request.params)) controller.response = response Rango.logger.info("#{self.name}.call(env) with method #{method}") # Rango.logger.inspect(before: ::Application.get_filters(:before), after: ::Application.get_filters(:after)) # Rango.logger.inspect(before: get_filters(:before), after: get_filters(:after)) controller.run_filters(:before, method.to_sym) # If you don't care about arguments or if you prefer usage of params. args = controller.params.map { |key, value| value } if controller.method(method).arity.eql?(0) Rango.logger.info("Calling method #{self.name}##{method} without arguments") value = controller.method(method).call else Rango.logger.info("Calling method #{self.name}##{method} with arguments #{args.inspect}") value = controller.method(method).call(*args) end controller.autorender if self.autorendering controller.run_filters(:after, method) response.body = proceed_value(value) response.status = controller.status if controller.status response.headers.merge!(controller.headers) return response.finish end |
controller?
public
controller?
[View source]
92 93 94 |
# File 'lib/rango/mvc/controller.rb', line 92 def controller? true end |
get_filters
public
get_filters(type)
[View source]
97 98 99 |
# File 'lib/rango/mvc/controller.rb', line 97 def get_filters(type) self.send("#{type}_filters") end |
inherited
public
inherited(subclass)
[View source]
25 26 27 28 29 30 |
# File 'lib/rango/mvc/controller.rb', line 25 def inherited(subclass) Rango.logger.debug("Inheritting filters from #{self.inspect} to #{subclass.inspect}") subclass.before_filters = self.before_filters subclass.after_filters = self.after_filters subclass.autorendering = self.autorendering end |
proceed_value
public
proceed_value(value)
[View source]
84 85 86 87 88 89 90 |
# File 'lib/rango/mvc/controller.rb', line 84 def proceed_value(value) case value when true, false then value.to_s when nil then String.new else value end end |
route_to
public
route_to(env, action, params = Hash.new)
[View source]
76 77 78 79 80 81 82 |
# File 'lib/rango/mvc/controller.rb', line 76 def route_to(env, action, params = Hash.new) env["rango.controller"] = self env["rango.controller.action"] = action env["rango.router.params"] = params env["rango.action"] = action Rango::Router::Dispatcher.route_to(env, self) end |
Public Instance Method Details
route_to
public
route_to(action, params = Hash.new)
[View source]
111 112 113 |
# File 'lib/rango/mvc/controller.rb', line 111 def route_to(action, params = Hash.new) self.class.route_to(request.env, action, params) end |
run_filters
public
run_filters(name, method)
[View source]
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/rango/mvc/controller.rb', line 116 def run_filters(name, method) # Rango.logger.debug(self.class.instance_variables) # Rango.logger.inspect(name: name, method: method) self.class.get_filters(name).each do |filter_method, | begin unless [:except] && [:except].include?(method) if filter_method.is_a?(Symbol) && self.respond_to?(filter_method) Rango.logger.info("Calling filter #{filter_method} for controller #{self}") self.send(filter_method) elsif filter_method.respond_to?(:call) Rango.logger.info("Calling filter #{filter_method.inspect} for controller #{self}") self.instance_eval(&filter_method) else Rango.logger.error("Filter #{filter_method} doesn't exists!") end end rescue SkipFilter Rango.logger.info("Skipping #{name} filter") next end end end |