2009-05-14 04:56:07 -04:00
|
|
|
require 'action_controller/abstract'
|
|
|
|
require 'active_support/core_ext/module/delegation'
|
|
|
|
|
2009-05-01 20:27:44 -04:00
|
|
|
module ActionController
|
|
|
|
class Http < AbstractController::Base
|
|
|
|
abstract!
|
|
|
|
|
|
|
|
# :api: public
|
|
|
|
attr_internal :request, :response, :params
|
|
|
|
|
|
|
|
# :api: public
|
|
|
|
def self.controller_name
|
|
|
|
@controller_name ||= controller_path.split("/").last
|
|
|
|
end
|
|
|
|
|
|
|
|
# :api: public
|
|
|
|
def controller_name() self.class.controller_name end
|
|
|
|
|
|
|
|
# :api: public
|
|
|
|
def self.controller_path
|
|
|
|
@controller_path ||= self.name.sub(/Controller$/, '').underscore
|
|
|
|
end
|
|
|
|
|
|
|
|
# :api: public
|
|
|
|
def controller_path() self.class.controller_path end
|
|
|
|
|
|
|
|
# :api: private
|
|
|
|
def self.action_names() action_methods end
|
|
|
|
|
|
|
|
# :api: private
|
|
|
|
def action_names() action_methods end
|
|
|
|
|
|
|
|
# :api: plugin
|
|
|
|
def self.call(env)
|
|
|
|
controller = new
|
|
|
|
controller.call(env).to_rack
|
|
|
|
end
|
|
|
|
|
2009-05-12 19:21:34 -04:00
|
|
|
delegate :headers, :to => "@_response"
|
|
|
|
|
|
|
|
def params
|
|
|
|
@_params ||= @_request.parameters
|
|
|
|
end
|
|
|
|
|
2009-05-01 20:27:44 -04:00
|
|
|
# :api: private
|
2009-05-02 05:15:09 -04:00
|
|
|
def call(name, env)
|
2009-05-01 20:27:44 -04:00
|
|
|
@_request = ActionDispatch::Request.new(env)
|
|
|
|
@_response = ActionDispatch::Response.new
|
2009-05-11 15:04:43 -04:00
|
|
|
@_response.request = request
|
2009-05-02 05:15:09 -04:00
|
|
|
process(name)
|
|
|
|
to_rack
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.action(name)
|
|
|
|
@actions ||= {}
|
2009-05-14 04:56:07 -04:00
|
|
|
@actions[name.to_s] ||= proc do |env|
|
2009-05-02 05:15:09 -04:00
|
|
|
new.call(name, env)
|
|
|
|
end
|
2009-05-01 20:27:44 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
# :api: private
|
|
|
|
def to_rack
|
2009-05-15 20:49:11 -04:00
|
|
|
@_response.body = response_body
|
|
|
|
@_response.prepare!
|
2009-05-01 20:27:44 -04:00
|
|
|
@_response.to_a
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|