Sha256: 7d16a6b8189f8d1255d0630fe5a19666ce6da5a208113919ed7beffb83dc1568

Contents?: true

Size: 799 Bytes

Versions: 5

Compression:

Stored size: 799 Bytes

Contents

module ResourceController
  module ClassMethods
    
    # Use this method in your controller to specify which actions you'd like it to respond to.
    #
    #   class PostsController < ResourceController::Base
    #     actions :all, :except => :create
    #   end
    def actions(*opts)
      config = {}
      config.merge!(opts.pop) if opts.last.is_a?(Hash)

      all_actions = (singleton? ? ResourceController::SINGLETON_ACTIONS : ResourceController::ACTIONS) - [:new_action] + [:new]

      actions_to_remove = []
      actions_to_remove += all_actions - opts unless opts.first == :all
      actions_to_remove += [*config[:except]] if config[:except]
      actions_to_remove.uniq!

      actions_to_remove.each { |action| undef_method(action) if method_defined?(action) }
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
makandra_resource_controller-0.8.0 lib/resource_controller/class_methods.rb
makandra_resource_controller-0.7.3 lib/resource_controller/class_methods.rb
makandra_resource_controller-0.7.2 lib/resource_controller/class_methods.rb
makandra_resource_controller-0.7.1 lib/resource_controller/class_methods.rb
makandra_resource_controller-0.7.0 lib/resource_controller/class_methods.rb