Module: AbilityHost::InstanceHelpers

Defined in:
app/models/components/ability_host.rb

Instance Method Summary collapse

Instance Method Details

#instance_instance_user_hash(*roles) ⇒ Hash (protected) Also known as: instance_all_instance_users_hash

Returns The hash is relative to a component which has a +belongs_to+ association with an Instance.

Returns:

  • (Hash)

    The hash is relative to a component which has a +belongs_to+ association with an Instance.


76
77
78
# File 'app/models/components/ability_host.rb', line 76

def instance_instance_user_hash(*roles)
  { instance: instance_user_hash(*roles) }
end

#instance_user_hash(*roles) ⇒ Hash (protected)

Creates a hash which allows referencing a set of instance users.

Parameters:

  • roles (Array<Symbol>)

    The roles InstanceUser::Roles which should be referenced by this rule.

Returns:

  • (Hash)

    This hash is relative to a Instance.


67
68
69
70
71
72
# File 'app/models/components/ability_host.rb', line 67

def instance_user_hash(*roles)
  instance_users = { user_id: user.id }
  instance_users[:role] = roles.map { |role| InstanceUser.roles[role] } unless roles.empty?

  { instance_users: instance_users }
end