Sha256: 952f612bfef77275a1a4d994f8683124de50d791a1139e7976222076f907d34e

Contents?: true

Size: 1.15 KB

Versions: 125

Compression:

Stored size: 1.15 KB

Contents

module ActionController
  # Adds the ability to prevent public methods on a controller to be called as actions.
  module HideActions
    extend ActiveSupport::Concern

    included do
      class_attribute :hidden_actions
      self.hidden_actions = Set.new.freeze
    end

  private

    # Overrides AbstractController::Base#action_method? to return false if the
    # action name is in the list of hidden actions.
    def method_for_action(action_name)
      self.class.visible_action?(action_name) && super
    end

    module ClassMethods
      # Sets all of the actions passed in as hidden actions.
      #
      # ==== Parameters
      # * <tt>args</tt> - A list of actions
      def hide_action(*args)
        self.hidden_actions = hidden_actions.dup.merge(args.map(&:to_s)).freeze
      end

      def visible_action?(action_name)
        not hidden_actions.include?(action_name)
      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) }).freeze
      end
    end
  end
end

Version data entries

125 entries across 121 versions & 10 rubygems

Version Path
actionpack-4.2.11.3 lib/action_controller/metal/hide_actions.rb
actionpack-4.2.11.2 lib/action_controller/metal/hide_actions.rb
actionpack-4.2.11.1 lib/action_controller/metal/hide_actions.rb
actionpack-4.2.11 lib/action_controller/metal/hide_actions.rb
actionpack-4.2.10 lib/action_controller/metal/hide_actions.rb
actionpack-4.2.10.rc1 lib/action_controller/metal/hide_actions.rb
actionpack-4.2.9 lib/action_controller/metal/hide_actions.rb
actionpack-4.2.9.rc2 lib/action_controller/metal/hide_actions.rb
actionpack-4.2.9.rc1 lib/action_controller/metal/hide_actions.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/actionpack-4.2.8/lib/action_controller/metal/hide_actions.rb
actionpack-4.2.8 lib/action_controller/metal/hide_actions.rb
actionpack-4.2.8.rc1 lib/action_controller/metal/hide_actions.rb
actionpack-4.2.7.1 lib/action_controller/metal/hide_actions.rb
actionpack-4.2.7 lib/action_controller/metal/hide_actions.rb
actionpack-4.1.16 lib/action_controller/metal/hide_actions.rb
actionpack-4.1.16.rc1 lib/action_controller/metal/hide_actions.rb
actionpack-4.2.7.rc1 lib/action_controller/metal/hide_actions.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/actionpack-4.2.6/lib/action_controller/metal/hide_actions.rb
actionpack-4.1.15 lib/action_controller/metal/hide_actions.rb
actionpack-4.2.6 lib/action_controller/metal/hide_actions.rb