module IAmICan::Subject::RoleQuerying

Public Instance Methods

has_role!(role_name, with_tmp: true)
Alias for: is!
has_role?(role_name, with_tmp: true)
Alias for: is?
in_one_of?(*group_names)
Alias for: is_in_one_of?
in_role_group?(name)
Alias for: is_in_role_group?
is!(role_name, with_tmp: true) click to toggle source
# File lib/i_am_i_can/subject/role_querying.rb, line 22
def is! role_name, with_tmp: true
  raise VerificationFailed if isnt? role_name, with_tmp: with_tmp
  true
end
Also aliased as: is_role!, has_role!
is?(role_name, with_tmp: true) click to toggle source

Role Querying ===

# File lib/i_am_i_can/subject/role_querying.rb, line 9
def is? role_name, with_tmp: true
  role_id = i_am_i_can.role_model.find_by(name: role_name)&.id
  return false unless role_id
  get_roles(with_tmp: with_tmp).exists?(id: role_id)
end
Also aliased as: is_role?, has_role?
is_every!(*role_names, with_tmp: true) click to toggle source
# File lib/i_am_i_can/subject/role_querying.rb, line 53
def is_every! *role_names, with_tmp: true
  raise VerificationFailed unless is_every?(*role_names, with_tmp: true)
  true
end
Also aliased as: is_every_role_in!
is_every?(*role_names, with_tmp: true) click to toggle source
# File lib/i_am_i_can/subject/role_querying.rb, line 45
def is_every? *role_names, with_tmp: true
  role_ids = i_am_i_can.role_model.where(name: role_names).ids
  return false if role_ids.size != role_names.size
  get_roles(with_tmp: with_tmp).where(id: role_ids).size == role_names.size
end
Also aliased as: is_every_role_in?
is_every_role_in!(*role_names, with_tmp: true)
Alias for: is_every!
is_every_role_in?(*role_names, with_tmp: true)
Alias for: is_every?
is_in_one_of?(*group_names) click to toggle source
# File lib/i_am_i_can/subject/role_querying.rb, line 69
def is_in_one_of? *group_names
  group_names.each { |name| return true if is_in_role_group? name } && false
end
Also aliased as: in_one_of?
is_in_role_group?(name) click to toggle source

Group Querying ===

# File lib/i_am_i_can/subject/role_querying.rb, line 62
def is_in_role_group? name
  group_members = i_am_i_can.role_group_model.find_by!(name: name)._roles.names
  (get_roles.names & group_members).present?
end
Also aliased as: in_role_group?
is_one_of!(*role_names, with_tmp: true) click to toggle source
# File lib/i_am_i_can/subject/role_querying.rb, line 38
def is_one_of! *role_names, with_tmp: true
  raise VerificationFailed unless is_one_of? *role_names, with_tmp: with_tmp
  true
end
Also aliased as: is_one_of_roles!
is_one_of?(*role_names, with_tmp: true) click to toggle source
# File lib/i_am_i_can/subject/role_querying.rb, line 30
def is_one_of? *role_names, with_tmp: true
  role_ids = i_am_i_can.role_model.where(name: role_names).ids
  return false if role_ids.blank?
  get_roles(with_tmp: with_tmp).exists?(id: role_ids)
end
Also aliased as: is_one_of_roles?
is_one_of_roles!(*role_names, with_tmp: true)
Alias for: is_one_of!
is_one_of_roles?(*role_names, with_tmp: true)
Alias for: is_one_of?
is_role!(role_name, with_tmp: true)
Alias for: is!
is_role?(role_name, with_tmp: true)
Alias for: is?
isnt?(role_name, with_tmp: true) click to toggle source
# File lib/i_am_i_can/subject/role_querying.rb, line 18
def isnt? role_name, with_tmp: true
!is? role_name, with_tmp: with_tmp
end