Class: RoleCore::CanCanCanPermission
- Inherits:
-
Permission
- Object
- Permission
- RoleCore::CanCanCanPermission
- Defined in:
- lib/role_core/contrib/can_can_can_permission.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Attributes inherited from Permission
#callable, #name, #namespace, #priority
Instance Method Summary collapse
- #block_attached? ⇒ Boolean
- #call(context, *args) ⇒ Object
-
#initialize(name, _namespace: [], _priority: 0, _callable: true, **options, &block) ⇒ CanCanCanPermission
constructor
A new instance of CanCanCanPermission.
Methods inherited from Permission
Constructor Details
#initialize(name, _namespace: [], _priority: 0, _callable: true, **options, &block) ⇒ CanCanCanPermission
Returns a new instance of CanCanCanPermission.
7 8 9 10 11 12 13 14 15 |
# File 'lib/role_core/contrib/can_can_can_permission.rb', line 7 def initialize(name, _namespace: [], _priority: 0, _callable: true, **, &block) super return unless _callable @model_name = [:model_name] @action = [:action] || name @options = .except(:model, :model_name, :action) @block = block end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
5 6 7 |
# File 'lib/role_core/contrib/can_can_can_permission.rb', line 5 def action @action end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/role_core/contrib/can_can_can_permission.rb', line 5 def @options end |
Instance Method Details
#block_attached? ⇒ Boolean
28 29 30 |
# File 'lib/role_core/contrib/can_can_can_permission.rb', line 28 def block_attached? !!@block end |
#call(context, *args) ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/role_core/contrib/can_can_can_permission.rb', line 17 def call(context, *args) return unless callable model = @model_name.constantize if block_attached? context.can @action, model, &@block.curry[*args] else context.can @action, model, @options end end |