class WebRouter::Controller
Constants
- RESPONSE_TYPES
Attributes
request[R]
Public Class Methods
action(action_name)
click to toggle source
# File lib/web_router/controller.rb, line 16 def self.action(action_name) proc { |env| new(action_name).call(env)} end
new(action_name)
click to toggle source
# File lib/web_router/controller.rb, line 23 def initialize(action_name) @action_name = action_name end
Public Instance Methods
call(env)
click to toggle source
# File lib/web_router/controller.rb, line 8 def call(env) @env = env @request = Rack::Request.new(env) @request.params.merge!(env['router.params'] || {}) send(@action_name) [200, @response_headers, [@response_body]] end
Private Instance Methods
erb(template)
click to toggle source
# File lib/web_router/controller.rb, line 37 def erb(template) path = File.join(File.expand_path('.'), template.to_s) ERB.new(File.read(path)).result(binding) end
params()
click to toggle source
# File lib/web_router/controller.rb, line 27 def params request.params end
response(type, content)
click to toggle source
# File lib/web_router/controller.rb, line 31 def response(type, content) @response_headers ||= {} @response_headers.merge!('Content-Type' => RESPONSE_TYPES[type][0] ) @response_body = RESPONSE_TYPES[type][1].call(content) end