2009-03-12 19:19:13 +00:00
|
|
|
module ActionController
|
2009-06-10 21:43:43 +00:00
|
|
|
# ActionController::HideActions adds the ability to prevent public methods on a controller
|
|
|
|
# to be called as actions.
|
2009-03-12 19:19:13 +00:00
|
|
|
module HideActions
|
2009-05-28 16:35:36 +00:00
|
|
|
extend ActiveSupport::Concern
|
2009-05-12 00:07:05 +00:00
|
|
|
|
2009-05-07 15:38:57 +00:00
|
|
|
included do
|
2009-06-10 21:43:43 +00:00
|
|
|
extlib_inheritable_accessor(:hidden_actions) { Set.new }
|
2009-03-12 19:19:13 +00:00
|
|
|
end
|
2009-05-07 15:38:57 +00:00
|
|
|
|
2009-06-10 21:43:43 +00:00
|
|
|
private
|
2009-05-28 14:49:02 +00:00
|
|
|
|
2009-06-10 22:27:53 +00:00
|
|
|
# Overrides AbstractController::Base#action_method? to return false if the
|
|
|
|
# action name is in the list of hidden actions.
|
2009-06-10 21:43:43 +00:00
|
|
|
def action_method?(action_name)
|
|
|
|
!hidden_actions.include?(action_name) && super
|
|
|
|
end
|
2009-05-28 14:49:02 +00:00
|
|
|
|
2009-06-10 21:43:43 +00:00
|
|
|
module ClassMethods
|
2009-06-10 22:27:53 +00:00
|
|
|
# Sets all of the actions passed in as hidden actions.
|
|
|
|
#
|
|
|
|
# ==== Parameters
|
|
|
|
# *args<#to_s>:: A list of actions
|
2009-06-10 21:43:43 +00:00
|
|
|
def hide_action(*args)
|
2009-06-10 22:27:53 +00:00
|
|
|
hidden_actions.merge(args.map! {|a| a.to_s })
|
2009-06-10 21:43:43 +00:00
|
|
|
end
|
2009-05-28 14:49:02 +00:00
|
|
|
|
2009-06-10 22:27:53 +00:00
|
|
|
# Overrides AbstractController::Base#action_methods to remove any methods
|
|
|
|
# that are listed as hidden methods.
|
2009-06-10 21:43:43 +00:00
|
|
|
def action_methods
|
2009-06-10 22:27:53 +00:00
|
|
|
@action_methods ||= Set.new(super.reject {|name| hidden_actions.include?(name)})
|
2009-05-28 14:49:02 +00:00
|
|
|
end
|
2009-06-10 21:43:43 +00:00
|
|
|
end
|
2009-03-12 19:19:13 +00:00
|
|
|
end
|
2009-05-28 14:49:02 +00:00
|
|
|
end
|