Sha256: 669f26afa101c5400721538db1184aae844a4c63b78073751b4f52007f7c0c95

Contents?: true

Size: 1.19 KB

Versions: 13

Compression:

Stored size: 1.19 KB

Contents

require 'active_support/core_ext/class/attribute'

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)
        action_methods.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

13 entries across 13 versions & 5 rubygems

Version Path
swipe-rails-0.0.5 vendor/bundle/gems/actionpack-3.2.13/lib/action_controller/metal/hide_actions.rb
font-awesome-rails-3.1.1.2 vendor/ruby/1.9.1/gems/actionpack-3.2.13/lib/action_controller/metal/hide_actions.rb
font-awesome-rails-3.1.1.1 vendor/ruby/1.9.1/gems/actionpack-3.2.13/lib/action_controller/metal/hide_actions.rb
challah-1.0.0.beta3 vendor/bundle/gems/actionpack-3.2.13/lib/action_controller/metal/hide_actions.rb
fc-webicons-0.0.4 vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.13/lib/action_controller/metal/hide_actions.rb
challah-1.0.0.beta2 vendor/bundle/gems/actionpack-3.2.13/lib/action_controller/metal/hide_actions.rb
challah-1.0.0.beta vendor/bundle/gems/actionpack-3.2.13/lib/action_controller/metal/hide_actions.rb
fc-webicons-0.0.3 vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.13/lib/action_controller/metal/hide_actions.rb
fc-webicons-0.0.2 vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.13/lib/action_controller/metal/hide_actions.rb
fc-webicons-0.0.1 vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.13/lib/action_controller/metal/hide_actions.rb
actionpack-3.2.13 lib/action_controller/metal/hide_actions.rb
actionpack-3.2.13.rc2 lib/action_controller/metal/hide_actions.rb
actionpack-3.2.13.rc1 lib/action_controller/metal/hide_actions.rb