aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller/abstract/base.rb
diff options
context:
space:
mode:
authorYehuda Katz + Carl Lerche <ykatz+clerche@engineyard.com>2009-04-30 15:13:40 -0700
committerYehuda Katz + Carl Lerche <ykatz+clerche@engineyard.com>2009-05-01 17:31:02 -0700
commit4ee3e5b094463383891789f484e927b19fccc744 (patch)
tree4595acf5dc068ebad2f796992d12659d65460337 /actionpack/lib/action_controller/abstract/base.rb
parentd58b57a3caf4ad434c2be4f63eecd9a1921c7c4a (diff)
downloadrails-4ee3e5b094463383891789f484e927b19fccc744.tar.gz
rails-4ee3e5b094463383891789f484e927b19fccc744.tar.bz2
rails-4ee3e5b094463383891789f484e927b19fccc744.zip
Ported over the concept of public instance methods on controller child classes as callable action methods
Diffstat (limited to 'actionpack/lib/action_controller/abstract/base.rb')
-rw-r--r--actionpack/lib/action_controller/abstract/base.rb48
1 files changed, 41 insertions, 7 deletions
diff --git a/actionpack/lib/action_controller/abstract/base.rb b/actionpack/lib/action_controller/abstract/base.rb
index a87a490a2d..3b85ba5565 100644
--- a/actionpack/lib/action_controller/abstract/base.rb
+++ b/actionpack/lib/action_controller/abstract/base.rb
@@ -4,13 +4,44 @@ module AbstractController
attr_internal :response_body
attr_internal :response_obj
attr_internal :action_name
-
- def self.process(action)
- new.process(action)
+
+ class << self
+ attr_reader :abstract
+
+ def abstract!
+ @abstract = true
+ end
+
+ alias_method :abstract?, :abstract
+
+ def internal_methods
+ controller = self
+ controller = controller.superclass until controller.abstract?
+ controller.public_instance_methods(true)
+ end
+
+ def process(action)
+ new.process(action)
+ end
+
+ def hidden_actions
+ []
+ end
+
+ def action_methods
+ @action_methods ||=
+ # All public instance methods of this class, including ancestors
+ public_instance_methods(true).map { |m| m.to_sym }.to_set -
+ # Except for public instance methods of Base and its ancestors
+ internal_methods.map { |m| m.to_sym } +
+ # Be sure to include shadowed public instance methods of this class
+ public_instance_methods(false).map { |m| m.to_sym } -
+ # And always exclude explicitly hidden actions
+ hidden_actions
+ end
end
- def self.inherited(klass)
- end
+ abstract!
def initialize
self.response_obj = {}
@@ -29,6 +60,10 @@ module AbstractController
private
+ def action_methods
+ self.class.action_methods
+ end
+
# It is possible for respond_to?(action_name) to be false and
# respond_to?(:action_missing) to be false if respond_to_action?
# is overridden in a subclass. For instance, ActionController::Base
@@ -45,8 +80,7 @@ module AbstractController
# you must handle it by also overriding process_action and
# handling the case.
def respond_to_action?(action_name)
- respond_to?(action_name) || respond_to?(:action_missing, true)
+ action_methods.include?(action_name) || respond_to?(:action_missing, true)
end
-
end
end \ No newline at end of file