Module: IAmICan::Permission::Helpers::Cls

Included in:
Definition
Defined in:
lib/i_am_i_can/permission/helpers.rb

Instance Method Summary collapse

Instance Method Details

#_pms_definition_result(preds, obj, failed_items) ⇒ Object

Raises:



5
6
7
8
9
10
11
# File 'lib/i_am_i_can/permission/helpers.rb', line 5

def _pms_definition_result(preds, obj, failed_items)
  prefix = 'Permission Definition Done'
  fail_msg = prefix + ", but #{failed_items} have been defined" if failed_items.present?
  raise Error, fail_msg if  i_am_i_can.strict_mode && fail_msg
  puts fail_msg || prefix unless ENV['ITEST']
  prefix.present?
end

#_to_store_permission(pred, obj, **options) ⇒ Object



13
14
15
16
# File 'lib/i_am_i_can/permission/helpers.rb', line 13

def _to_store_permission(pred, obj, **options)
  return false if i_am_i_can.permission_model.exists?(pred, obj)
  i_am_i_can.permission_model.create!(pred: pred, **deconstruct_obj(obj), **options)
end

#deconstruct_obj(obj) ⇒ Object



22
23
24
# File 'lib/i_am_i_can/permission/helpers.rb', line 22

def deconstruct_obj(obj)
  i_am_i_can.permission_model.deconstruct_obj(obj)
end

#defined_local_permissionsObject



26
27
28
# File 'lib/i_am_i_can/permission/helpers.rb', line 26

def defined_local_permissions
  @defined_local_permissions ||= { }
end

#defined_permissionsObject



38
39
40
# File 'lib/i_am_i_can/permission/helpers.rb', line 38

def defined_permissions
  defined_local_permissions.deep_merge(defined_stored_permissions)
end

#defined_stored_permissionsObject



34
35
36
# File 'lib/i_am_i_can/permission/helpers.rb', line 34

def defined_stored_permissions
  i_am_i_can.permission_model.all.map { |pms| [ pms.name, pms.desc ] }.to_h
end

#defined_stored_pms_namesObject



30
31
32
# File 'lib/i_am_i_can/permission/helpers.rb', line 30

def defined_stored_pms_names
  i_am_i_can.permission_model.all.map(&:name)
end

#pms_naming(pred, obj) ⇒ Object



18
19
20
# File 'lib/i_am_i_can/permission/helpers.rb', line 18

def pms_naming(pred, obj)
  i_am_i_can.permission_model.naming(pred, obj)
end

#pms_of_defined_local_role(role_name) ⇒ Object



42
43
44
# File 'lib/i_am_i_can/permission/helpers.rb', line 42

def pms_of_defined_local_role(role_name)
  i_am_i_can.subject_model.defined_local_roles[role_name.to_sym]&.[](:permissions) || []
end