Module: Troles::Common::Api::Read
- Defined in:
- lib/troles/common/api/read.rb
Instance Method Summary collapse
-
#has_any_role?(*roles) ⇒ Boolean
Checks if the role subject has any of the listed roles (see #has_roles?).
-
#has_role?(role) ⇒ true, false
Does the role subject has the role or not?.
-
#has_roles?(*roles) ⇒ true, false
(also: #has_all_roles?)
Checks if the role subject has any of the listed roles.
-
#is_role?(role) ⇒ true, false
Does the role subject have ONLY that role or not?.
-
#role_list ⇒ Object
Ensures that the common API methods always have a common underlying model to work on.
Instance Method Details
#has_any_role?(*roles) ⇒ Boolean
Checks if the role subject has any of the listed roles (see #has_roles?)
41 42 43 |
# File 'lib/troles/common/api/read.rb', line 41 def has_any_role? *roles !(role_list & roles.to_symbols).empty? end |
#has_role?(role) ⇒ true, false
Does the role subject has the role or not?
21 22 23 |
# File 'lib/troles/common/api/read.rb', line 21 def has_role? role role_list.include? role.to_sym end |
#has_roles?(*roles) ⇒ true, false Also known as: has_all_roles?
Checks if the role subject has any of the listed roles
34 35 36 |
# File 'lib/troles/common/api/read.rb', line 34 def has_roles? *roles (roles.to_symbols - role_list).empty? end |
#is_role?(role) ⇒ true, false
Does the role subject have ONLY that role or not?
27 28 29 |
# File 'lib/troles/common/api/read.rb', line 27 def is_role? role role_list.first == role.to_sym && role_list.size == 1 end |
#role_list ⇒ Object
Note:
This Set should be cached and only invalidated when the user has a change of roles
Ensures that the common API methods always have a common underlying model to work on
13 14 15 16 17 |
# File 'lib/troles/common/api/read.rb', line 13 def role_list @role_list ||= begin store.display_roles.flatten end end |