Sha256: ab54c4654024138f6882a74401f92da5ca931b11928ba8c1f48c47a9d352a85c

Contents?: true

Size: 1.3 KB

Versions: 7

Compression:

Stored size: 1.3 KB

Contents

module CanCanNamespace
  # Handle the load and authorization controller logic so we don't clutter up all controllers with non-interface methods.
  # This class is used internally, so you do not need to call methods directly on it.
  module ControllerResource # :nodoc:
    def self.included(base)
      base.send :include, InstanceMethods
      base.send :extend,  ClassMethods
    end
    
    module ClassMethods
      def self.extended(base)
        base.class_eval do
          alias_method :authorize_resource, :authorize_resource_with_context
        end
      end
    end
    
    module InstanceMethods
      def authorize_resource_with_context
        unless skip?(:authorize)
          options = { :context => (@options[:context] || module_from_controller) }
          @controller.authorize!(authorization_action, resource_instance || resource_class_with_parent, options)
        end
      end
      
      private
      
        def module_from_controller
          modules = @params[:controller].sub("Controller", "").underscore.split('/')
          if modules.size > 1
            modules.first.singularize
          else
            return nil
          end
        end
    end
  end
end

if defined? CanCan::ControllerResource
  CanCan::ControllerResource.send(:include, CanCanNamespace::ControllerResource)
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
sunrise-cms-0.5.0.rc1 vendor/bundle/ruby/1.9.1/gems/cancan_namespace-0.1.3/lib/cancan_namespace/controller_resource.rb
sunrise-cms-0.3.3 vendor/bundle/ruby/1.9.1/gems/cancan_namespace-0.1.3/lib/cancan_namespace/controller_resource.rb
sunrise-cms-0.3.2 vendor/bundle/ruby/1.9.1/gems/cancan_namespace-0.1.3/lib/cancan_namespace/controller_resource.rb
sunrise-cms-0.3.1 vendor/bundle/ruby/1.9.1/gems/cancan_namespace-0.1.3/lib/cancan_namespace/controller_resource.rb
sunrise-cms-0.3.0 vendor/bundle/ruby/1.9.1/gems/cancan_namespace-0.1.3/lib/cancan_namespace/controller_resource.rb
sunrise-cms-0.3.0.rc vendor/bundle/ruby/1.9.1/gems/cancan_namespace-0.1.3/lib/cancan_namespace/controller_resource.rb
cancan_namespace-0.1.3 lib/cancan_namespace/controller_resource.rb