class Rhino::Controller
Public Class Methods
action(act, rp = {})
click to toggle source
# File lib/rhino/controller.rb, line 25 def self.action(act, rp = {}) proc {|e| self.new(e).dispatch(act, rp)} end
new(env)
click to toggle source
# File lib/rhino/controller.rb, line 9 def initialize(env) @env = env @routing_params = {} end
Public Instance Methods
controller_name()
click to toggle source
# File lib/rhino/controller.rb, line 58 def controller_name klass = self.class klass = klass.to_s.gsub(/Controller$/, "") Rhino.to_underscore(klass) end
dispatch(action, routing_params = {})
click to toggle source
# File lib/rhino/controller.rb, line 14 def dispatch(action, routing_params = {}) @routing_params = routing_params text = self.send(action) if get_response st, hd, rs = get_response.to_a [st, hd, [rs].flatten] else [200, {'Context-Type' => 'text/html'}, [text].flatten] end end
env()
click to toggle source
# File lib/rhino/controller.rb, line 29 def env @env end
get_response()
click to toggle source
# File lib/rhino/controller.rb, line 43 def get_response @response end
params()
click to toggle source
# File lib/rhino/controller.rb, line 47 def params request.params.merge(@routing_params) end
render(view_name, locals={})
click to toggle source
# File lib/rhino/controller.rb, line 51 def render(view_name, locals={}) file_name = File.join 'app', 'views', controller_name, "#{view_name}.html.erb" template = File.read file_name eruby = Erubis::Eruby.new(template) eruby.result locals.merge(env: env) end
request()
click to toggle source
# File lib/rhino/controller.rb, line 33 def request @request ||= Rack::Request.new(@env) end
response(text, status=200, headers = {})
click to toggle source
# File lib/rhino/controller.rb, line 37 def response(text, status=200, headers = {}) raise "Already responded!" if @response a = [text].flatten @response = Rack::Response.new(a, status, headers) end