From bd6b61be88dfe6eb1ff1dcc5c17542d804a842c7 Mon Sep 17 00:00:00 2001 From: Yehuda Katz Date: Thu, 6 Aug 2009 19:52:11 -0300 Subject: Rename /base to /metal and make base.rb and metal.rb top-level to reflect their module locations --- .../lib/action_controller/metal/hide_actions.rb | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 actionpack/lib/action_controller/metal/hide_actions.rb (limited to 'actionpack/lib/action_controller/metal/hide_actions.rb') diff --git a/actionpack/lib/action_controller/metal/hide_actions.rb b/actionpack/lib/action_controller/metal/hide_actions.rb new file mode 100644 index 0000000000..af68c772b1 --- /dev/null +++ b/actionpack/lib/action_controller/metal/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 -- cgit v1.2.3