From f55514125cae291791365effc856d237008f7cd2 Mon Sep 17 00:00:00 2001 From: Yehuda Katz Date: Tue, 17 Mar 2009 18:04:22 -0700 Subject: Working toward getting a basic AbstractController framework --- actionpack/lib/action_controller/new_base/base.rb | 37 +++++++++++++++++++++- .../lib/action_controller/new_base/hide_actions.rb | 6 ++++ .../lib/action_controller/new_base/renderer.rb | 11 +++++++ 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 actionpack/lib/action_controller/new_base/renderer.rb (limited to 'actionpack/lib/action_controller/new_base') diff --git a/actionpack/lib/action_controller/new_base/base.rb b/actionpack/lib/action_controller/new_base/base.rb index ebe7c8dda6..0400ddbf7a 100644 --- a/actionpack/lib/action_controller/new_base/base.rb +++ b/actionpack/lib/action_controller/new_base/base.rb @@ -1,26 +1,61 @@ module ActionController class AbstractBase < AbstractController::Base + + # :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_methods @action_names ||= Set.new(self.public_instance_methods - self::CORE_METHODS) end + # :api: private def self.action_names() action_methods end + # :api: private def action_methods() self.class.action_names end + + # :api: private def action_names() action_methods end + + # :api: plugin + def self.call(env) + controller = new + controller.call(env).to_rack + end + + # :api: plugin + def response_body=(body) + @_response["Content-Length"] = body.length + @_response.body = body + end + + # :api: private + def call(env) + @_request = ActionDispatch::Request.new(env) + @_response = ActionDispatch::Response.new + process(@_request.parameters[:action]) + end + + # :api: private + def to_rack + response.to_a + end end end \ No newline at end of file diff --git a/actionpack/lib/action_controller/new_base/hide_actions.rb b/actionpack/lib/action_controller/new_base/hide_actions.rb index 9847d7b086..b3777c3c1e 100644 --- a/actionpack/lib/action_controller/new_base/hide_actions.rb +++ b/actionpack/lib/action_controller/new_base/hide_actions.rb @@ -10,6 +10,12 @@ module ActionController def action_methods() self.class.action_names end def action_names() action_methods end + + private + + def respond_to_action?(action_name) + !hidden_actions.include?(action_name) && (super || respond_to?(:method_missing)) + end module ClassMethods def hide_action(*args) diff --git a/actionpack/lib/action_controller/new_base/renderer.rb b/actionpack/lib/action_controller/new_base/renderer.rb new file mode 100644 index 0000000000..503450c246 --- /dev/null +++ b/actionpack/lib/action_controller/new_base/renderer.rb @@ -0,0 +1,11 @@ +module ActionController + module Renderer + + def render(options) + if text = options[:text] + self.response_body = text + end + end + + end +end \ No newline at end of file -- cgit v1.2.3