Sha256: 423ae62484e5df68c61a3c689f6a46ea5d040895bfd5494f4706b5dd38e70139

Contents?: true

Size: 811 Bytes

Versions: 1

Compression:

Stored size: 811 Bytes

Contents

require 'active_support/concern'

module Fume
  module Cancan
    module ControllerExtensions
      extend ActiveSupport::Concern

      module ClassMethods
        def authorize_object(*args)
          options = args.extract_options!
          object = args.shift || options[:object]

          filter_options = options.slice(:only, :except)
          before_action(filter_options || {}) do |controller|
            controller.send :authorize_object!, object, options
          end
        end
      end

    protected
      def authorize_object!(object, options = {})
        action = (options[:action] || params[:action]).to_sym
        authorize! action, object
      end
    end
  end
end

if defined? ActionController::Base
  ActionController::Base.send :include, ::Fume::Cancan::ControllerExtensions
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fume-cancan-0.1.0 lib/fume/cancan/controller_extensions.rb