Module: IAmICan::Permission::Definition
- Includes:
- Helpers::Cls
- Defined in:
- lib/i_am_i_can/permission/definition.rb
Class Method Summary
collapse
Instance Method Summary
collapse
#_pms_definition_result, #_to_store_permission, #deconstruct_obj, #defined_local_permissions, #defined_permissions, #defined_stored_permissions, #defined_stored_pms_names, #pms_naming, #pms_of_defined_local_role
Class Method Details
.extended(kls) ⇒ Object
36
37
38
|
# File 'lib/i_am_i_can/permission/definition.rb', line 36
def self.extended(kls)
kls.delegate :defined_permissions, :pms_naming, :deconstruct_obj, :pms_of_defined_local_role, to: kls
end
|
Instance Method Details
#declare_permission(*preds, **options) ⇒ Object
Also known as:
declare_permissions
30
31
32
|
# File 'lib/i_am_i_can/permission/definition.rb', line 30
def declare_permission *preds, **options
have_permission *preds, **options, save: false
end
|
#have_permission(*preds, obj: nil, desc: nil, save: i_am_i_can.default_save) ⇒ Object
Also known as:
have_permissions, has_permission, has_permissions
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/i_am_i_can/permission/definition.rb', line 9
def have_permission *preds, obj: nil, desc: nil, save: i_am_i_can.default_save
failed_items = [ ]
preds.each do |pred|
pms_name = pms_naming(pred, obj)
description = desc || pms_name.to_s.tr('_', ' ')
if save
failed_items << pms_name unless _to_store_permission(pred, obj, desc: description)
else
failed_items << pms_name if pms_name.in?(defined_local_permissions.keys)
defined_local_permissions[pms_name] ||= { desc: description }
end
end
_pms_definition_result(preds, obj, failed_items)
end
|