Module: IAmICan::Subject::RoleQuerying

Defined in:
lib/i_am_i_can/subject/role_querying.rb

Instance Method Summary collapse

Instance Method Details

#is!(role) ⇒ Object Also known as: is_role!, has_role!

Raises:



18
19
20
21
# File 'lib/i_am_i_can/subject/role_querying.rb', line 18

def is! role
  raise VerificationFailed if isnt? role
  true
end

#is?(role) ⇒ Boolean Also known as: is_role?, has_role?

Role Querying ===

Returns:

  • (Boolean)


7
8
9
# File 'lib/i_am_i_can/subject/role_querying.rb', line 7

def is? role
  role.to_sym.in?(local_role_names) || role.to_sym.in?(stored_role_names)
end

#is_every!(*roles) ⇒ Object Also known as: is_every_role_in!



44
45
46
# File 'lib/i_am_i_can/subject/role_querying.rb', line 44

def is_every! *roles
  roles.each { |role| is! role } && true
end

#is_every?(*roles) ⇒ Boolean Also known as: is_every_role_in?

Returns:

  • (Boolean)


38
39
40
# File 'lib/i_am_i_can/subject/role_querying.rb', line 38

def is_every? *roles
  roles.each { |role| return false if isnt? role } && true
end

#is_in_one_of?(*group_names) ⇒ Boolean Also known as: in_one_of?

Returns:

  • (Boolean)


59
60
61
# File 'lib/i_am_i_can/subject/role_querying.rb', line 59

def is_in_one_of? *group_names
  group_names.each { |name| return true if is_in_role_group? name } && false
end

#is_in_role_group?(name) ⇒ Boolean Also known as: in_role_group?

Group Querying ===

Returns:

  • (Boolean)


52
53
54
55
# File 'lib/i_am_i_can/subject/role_querying.rb', line 52

def is_in_role_group? name
  group_members = self.class.members_of_role_group(name)
  (roles & group_members).present?
end

#is_one_of!(*roles) ⇒ Object Also known as: is_one_of_roles!

Raises:



32
33
34
# File 'lib/i_am_i_can/subject/role_querying.rb', line 32

def is_one_of! *roles
  raise VerificationFailed unless is_one_of? *roles
end

#is_one_of?(*roles) ⇒ Boolean Also known as: is_one_of_roles?

Returns:

  • (Boolean)


26
27
28
# File 'lib/i_am_i_can/subject/role_querying.rb', line 26

def is_one_of? *roles
  roles.each { |role| return true if is? role } && false
end

#isnt?(role) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/i_am_i_can/subject/role_querying.rb', line 14

def isnt? role
!is? role
end