aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller/new_base/hide_actions.rb
blob: af68c772b16f90b14f6e76dab5c14b25e4ad7e9a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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