diff options
author | Yehuda Katz <wycats@gmail.com> | 2009-03-17 18:04:22 -0700 |
---|---|---|
committer | Yehuda Katz <wycats@gmail.com> | 2009-03-17 18:04:22 -0700 |
commit | f55514125cae291791365effc856d237008f7cd2 (patch) | |
tree | 6080509ce323a5880b8b7552efc5d8f76afaade3 /actionpack/lib | |
parent | a2637e9f1fba92bc0b8dbf461ce9f4f8ffb4cfaa (diff) | |
download | rails-f55514125cae291791365effc856d237008f7cd2.tar.gz rails-f55514125cae291791365effc856d237008f7cd2.tar.bz2 rails-f55514125cae291791365effc856d237008f7cd2.zip |
Working toward getting a basic AbstractController framework
Diffstat (limited to 'actionpack/lib')
7 files changed, 76 insertions, 8 deletions
diff --git a/actionpack/lib/action_controller/abstract.rb b/actionpack/lib/action_controller/abstract.rb index 85995189a3..3f5c4a185f 100644 --- a/actionpack/lib/action_controller/abstract.rb +++ b/actionpack/lib/action_controller/abstract.rb @@ -1,8 +1,10 @@ module AbstractController - autoload :Base, "action_controller/abstract/base" - autoload :Callbacks, "action_controller/abstract/callbacks" - autoload :Helpers, "action_controller/abstract/helpers" - autoload :Layouts, "action_controller/abstract/layouts" - autoload :Logger, "action_controller/abstract/logger" - autoload :Renderer, "action_controller/abstract/renderer" + autoload :Base, "action_controller/abstract/base" + autoload :Callbacks, "action_controller/abstract/callbacks" + autoload :Helpers, "action_controller/abstract/helpers" + autoload :Layouts, "action_controller/abstract/layouts" + autoload :Logger, "action_controller/abstract/logger" + autoload :Renderer, "action_controller/abstract/renderer" + # === Exceptions + autoload :ActionNotFound, "action_controller/abstract/exceptions" end
\ No newline at end of file diff --git a/actionpack/lib/action_controller/abstract/base.rb b/actionpack/lib/action_controller/abstract/base.rb index fa86d68c04..ade7719cc0 100644 --- a/actionpack/lib/action_controller/abstract/base.rb +++ b/actionpack/lib/action_controller/abstract/base.rb @@ -17,14 +17,24 @@ module AbstractController end def process(action_name) + unless respond_to_action?(action_name) + raise ActionNotFound, "The action '#{action_name}' could not be found" + end + @_action_name = action_name process_action self.response_obj[:body] = self.response_body self end + private + def process_action - send(action_name) + respond_to?(action_name) ? send(action_name) : send(:action_missing, action_name) + end + + def respond_to_action?(action_name) + respond_to?(action_name) || respond_to?(:action_missing, true) end end diff --git a/actionpack/lib/action_controller/abstract/exceptions.rb b/actionpack/lib/action_controller/abstract/exceptions.rb new file mode 100644 index 0000000000..ec4680629b --- /dev/null +++ b/actionpack/lib/action_controller/abstract/exceptions.rb @@ -0,0 +1,3 @@ +module AbstractController + class ActionNotFound < StandardError ; end +end
\ No newline at end of file diff --git a/actionpack/lib/action_controller/new_base.rb b/actionpack/lib/action_controller/new_base.rb index 2cef221de3..2870f71b7d 100644 --- a/actionpack/lib/action_controller/new_base.rb +++ b/actionpack/lib/action_controller/new_base.rb @@ -1,5 +1,6 @@ module ActionController autoload :AbstractBase, "action_controller/new_base/base" autoload :HideActions, "action_controller/new_base/hide_actions" + autoload :Renderer, "action_controller/new_base/renderer" autoload :UrlFor, "action_controller/new_base/url_for" end
\ No newline at end of file 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 |