module Dry::Ability::Controller::DSL
Public Instance Methods
cancan_skipper()
click to toggle source
# File lib/dry/ability/controller/dsl.rb, line 155 def cancan_skipper @_cancan_skipper ||= { authorize: {}, load: {} } end
load_resource(name, **opts)
@!method load_resource
(*args, **opts)
@see #load_and_authorize_resource @option opts [Array<String,Symbol>] :only Only applies before filter to given actions. @option opts [Array<String,Symbol>] :except Does not apply before filter to given actions. @option opts [Boolean] :prepend Prepend callback @option opts [Symbol] :through Load this resource through another one. @option opts [Symbol] :through_association @option opts [Boolean] :shallow (false) allow this resource to be loaded directly when parent is +nil+ @option opts [Boolean] :singleton (false) singleton resource through a +has_one+ association. @option opts [Boolean] :parent defaults to +true+ if a resource name is given which does not match the controller. @option opts [String,Class] :class The class to use for the model (string or constant). @option opts [String,Symbol] :instance_name The name of the instance variable to load the resource into. @option opts [Symbol] :find_by will use find_by(permalink: params[:id]) @option opts [Symbol] :id_param Find using a param key other than :id. For example: @option opts [Array<Symbol>] :collection External actions as resource collection @option opts [Array<Symbol>] :new External actions as new resource
Alias for: set_resource_mediator_callback
set_resource_mediator_callback(name, **opts)
click to toggle source
@api private
# File lib/dry/ability/controller/dsl.rb, line 17 def set_resource_mediator_callback(name, **opts) callback_options = opts.extract!(:only, :except, :if, :unless, :prepend) @_resource_mediators ||= Concurrent::Map.new @_resource_mediators.fetch_or_store(name) do ResourceMediator.new(name, controller_path, __callee__, **opts). tap { |m| before_action m, callback_options } end.sequence << __callee__ end
skip_load_resource(name, **options)
click to toggle source
Skip the loading behavior of CanCan. This is useful when using load_and_authorize_resource
but want to only do authorization on certain actions. You can pass :only and :except options to specify which actions to skip the effects on. It will apply to all actions by default.
class ProjectsController < ApplicationController load_and_authorize_resource skip_load_resource :only => :index end
You can also pass the resource name as the first argument to skip that resource.
# File lib/dry/ability/controller/dsl.rb, line 85 def skip_load_resource(name, **options) cancan_skipper[:load][name] = options end
Private Instance Methods
inherited(klass)
click to toggle source
Calls superclass method
# File lib/dry/ability/controller/dsl.rb, line 9 def inherited(klass) super(klass) klass.instance_variable_set(:@_resource_mediators, @_resource_mediators.dup) klass.instance_variable_set(:@_cancan_skipper, @_cancan_skipper.dup) klass end