class RoleCore::CanCanCanPermission
Attributes
action[R]
options[R]
Public Class Methods
new(name, _namespace: [], _priority: 0, _callable: true, **options, &block)
click to toggle source
Calls superclass method
RoleCore::Permission::new
# File lib/role_core/contrib/can_can_can_permission.rb, line 7 def initialize(name, _namespace: [], _priority: 0, _callable: true, **options, &block) super return unless _callable @model_name = options[:model_name] @subject = options[:subject] @action = options[:action] || name @options = options.except(:model, :model_name, :subject, :action) @block = block end
Public Instance Methods
block_attached?()
click to toggle source
# File lib/role_core/contrib/can_can_can_permission.rb, line 31 def block_attached? !!@block end
call(context, *args)
click to toggle source
# File lib/role_core/contrib/can_can_can_permission.rb, line 18 def call(context, *args) return unless callable subject = @subject || @model_name.constantize if block_attached? context.can @action, subject, &@block.curry[*args] else context.can @action, subject, @options end rescue NameError raise "You must provide a valid model name." end