aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller/base/hide_actions.rb
diff options
context:
space:
mode:
authorYehuda Katz + Carl Lerche <ykatz+clerche@engineyard.com>2009-06-15 11:44:45 -0700
committerYehuda Katz + Carl Lerche <ykatz+clerche@engineyard.com>2009-06-15 11:44:45 -0700
commita63caa4c0c2a8aabc13c354a9193ebd9c5e8ba73 (patch)
tree3d90ed4e56055eb4f4a7b7760321007586b3c87c /actionpack/lib/action_controller/base/hide_actions.rb
parent614374b3e5b19b737175a82c6dad2f146800eef1 (diff)
downloadrails-a63caa4c0c2a8aabc13c354a9193ebd9c5e8ba73.tar.gz
rails-a63caa4c0c2a8aabc13c354a9193ebd9c5e8ba73.tar.bz2
rails-a63caa4c0c2a8aabc13c354a9193ebd9c5e8ba73.zip
Get tests to run (with failures) without old base around
Diffstat (limited to 'actionpack/lib/action_controller/base/hide_actions.rb')
-rw-r--r--actionpack/lib/action_controller/base/hide_actions.rb35
1 files changed, 35 insertions, 0 deletions
diff --git a/actionpack/lib/action_controller/base/hide_actions.rb b/actionpack/lib/action_controller/base/hide_actions.rb
new file mode 100644
index 0000000000..af68c772b1
--- /dev/null
+++ b/actionpack/lib/action_controller/base/hide_actions.rb
@@ -0,0 +1,35 @@
+module ActionController
+ # ActionController::HideActions adds the ability to prevent public methods on a controller
+ # to be called as actions.
+ module HideActions
+ extend ActiveSupport::Concern
+
+ included do
+ extlib_inheritable_accessor(:hidden_actions) { Set.new }
+ end
+
+ private
+
+ # Overrides AbstractController::Base#action_method? to return false if the
+ # action name is in the list of hidden actions.
+ def action_method?(action_name)
+ !hidden_actions.include?(action_name) && super
+ end
+
+ module ClassMethods
+ # Sets all of the actions passed in as hidden actions.
+ #
+ # ==== Parameters
+ # *args<#to_s>:: A list of actions
+ def hide_action(*args)
+ hidden_actions.merge(args.map! {|a| a.to_s })
+ end
+
+ # Overrides AbstractController::Base#action_methods to remove any methods
+ # that are listed as hidden methods.
+ def action_methods
+ @action_methods ||= Set.new(super.reject {|name| hidden_actions.include?(name)})
+ end
+ end
+ end
+end