Module: IAmICan::Role::Helpers::Cls

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

Instance Method Summary collapse

Instance Method Details

#_role_definition_result(names, failed_items) ⇒ Object

Raises:



10
11
12
13
14
15
16
# File 'lib/i_am_i_can/role/helpers.rb', line 10

def _role_definition_result(names, failed_items)
  prefix = 'Role Definition Done'
  fail_msg = prefix + ", but name #{failed_items} have been used by other role or group" 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_role(name, **options) ⇒ Object



5
6
7
8
# File 'lib/i_am_i_can/role/helpers.rb', line 5

def _to_store_role name, **options
  return false if i_am_i_can.role_model.exists?(name: name) || i_am_i_can.role_group_model&.exists?(name: name)
  i_am_i_can.role_model.create!(name: name, **options)
end

#defined_local_rolesObject



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

def defined_local_roles
  @local_roles ||= { }
end

#defined_role_group_namesObject



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

def defined_role_group_names
  i_am_i_can.role_group_model.pluck(:name).map(&:to_sym)
end

#defined_role_groupsObject



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

def defined_role_groups
  i_am_i_can.role_group_model.all.map { |group| [ group.name.to_sym, group.member_names.map(&:to_sym).sort ] }.to_h
end

#defined_rolesObject



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

def defined_roles
  defined_local_roles.deep_merge(defined_stored_roles)
end

#defined_stored_role_namesObject



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

def defined_stored_role_names
  i_am_i_can.role_model.pluck(:name).map(&:to_sym)
end

#defined_stored_rolesObject



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

def defined_stored_roles
  i_am_i_can.role_model.all.map { |role| [ role.name.to_sym, role.desc ] }.to_h
end