Sha256: a51bbf0289c5ca801581601c85015cad32d744f2510c4544b495ff77ac9f3d4b

Contents?: true

Size: 1.4 KB

Versions: 149

Compression:

Stored size: 1.4 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 inherited(klass)
        klass.class_eval { @visible_actions = {} }
        super
      end

      def visible_action?(action_name)
        return @visible_actions[action_name] if @visible_actions.key?(action_name)
        @visible_actions[action_name] = !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) })
      end
    end
  end
end

Version data entries

149 entries across 113 versions & 16 rubygems

Version Path
active_mailer-0.0.10 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.12/lib/action_controller/metal/hide_actions.rb
judge-2.0.5 vendor/bundle/ruby/2.1.0/gems/actionpack-3.2.12/lib/action_controller/metal/hide_actions.rb
active_mailer-0.0.9 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.12/lib/action_controller/metal/hide_actions.rb
active_mailer-0.0.8 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.12/lib/action_controller/metal/hide_actions.rb
active_mailer-0.0.7 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.12/lib/action_controller/metal/hide_actions.rb
active_mailer-0.0.6 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.12/lib/action_controller/metal/hide_actions.rb
font-awesome-rails-3.1.1.2 vendor/ruby/1.9.1/gems/actionpack-3.2.12/lib/action_controller/metal/hide_actions.rb
font-awesome-rails-3.1.1.2 vendor/ruby/2.0.0/gems/actionpack-3.2.12/lib/action_controller/metal/hide_actions.rb
font-awesome-rails-3.1.1.1 vendor/ruby/1.9.1/gems/actionpack-3.2.12/lib/action_controller/metal/hide_actions.rb
font-awesome-rails-3.1.1.1 vendor/ruby/2.0.0/gems/actionpack-3.2.12/lib/action_controller/metal/hide_actions.rb
challah-1.0.0.beta vendor/bundle/gems/actionpack-3.2.11/lib/action_controller/metal/hide_actions.rb
actionpack-3.1.12 lib/action_controller/metal/hide_actions.rb
active_mailer-0.0.5 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.12/lib/action_controller/metal/hide_actions.rb
active_mailer-0.0.4 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.12/lib/action_controller/metal/hide_actions.rb
active_mailer-0.0.3 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.12/lib/action_controller/metal/hide_actions.rb
actionpack-3.2.12 lib/action_controller/metal/hide_actions.rb
actionpack-3.1.11 lib/action_controller/metal/hide_actions.rb
graphael-on-rails-0.5.1 vendor/bundle/gems/actionpack-3.2.11/lib/action_controller/metal/hide_actions.rb
graphael-on-rails-0.0.1 vendor/bundle/gems/actionpack-3.2.11/lib/action_controller/metal/hide_actions.rb
challah-0.9.1.beta.3 vendor/bundle/gems/actionpack-3.2.11/lib/action_controller/metal/hide_actions.rb