Module: IAmICan::Role::Helpers::Cls
- Included in:
- Definition
- Defined in:
- lib/i_am_i_can/role/helpers.rb
Instance Method Summary collapse
- #_role_definition_result(names, failed_items) ⇒ Object
- #_to_store_role(name, **options) ⇒ Object
- #defined_local_roles ⇒ Object
- #defined_role_group_names ⇒ Object
- #defined_role_groups ⇒ Object
- #defined_roles ⇒ Object
- #defined_stored_role_names ⇒ Object
- #defined_stored_roles ⇒ Object
Instance Method Details
#_role_definition_result(names, failed_items) ⇒ Object
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, ** 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, **) end |
#defined_local_roles ⇒ Object
18 19 20 |
# File 'lib/i_am_i_can/role/helpers.rb', line 18 def defined_local_roles @local_roles ||= { } end |
#defined_role_group_names ⇒ Object
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_groups ⇒ Object
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_roles ⇒ Object
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_names ⇒ Object
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_roles ⇒ Object
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 |