Module: Roles::Generic::RoleUtil
- Extended by:
- RoleUtil
- Included in:
- RoleUtil, User::Implementation
- Defined in:
- lib/roles_generic/generic/role_util.rb
Instance Method Summary collapse
- #extract_role(role) ⇒ Object
-
#extract_roles(*roles) ⇒ Object
extract role symbols from roles should handle symbols, strings, arrays and Role instances.
Instance Method Details
#extract_role(role) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/roles_generic/generic/role_util.rb', line 8 def extract_role role role = case role when Array role.flat_uniq.first else role end if defined?(Role) && role.kind_of?(Role) raise 'Role instances should have a #name method that reflects the role name' if !role.respond_to? :name return role.name.to_s.to_sym end case role when String, Symbol role.to_sym else nil end end |
#extract_roles(*roles) ⇒ Object
extract role symbols from roles should handle symbols, strings, arrays and Role instances
4 5 6 |
# File 'lib/roles_generic/generic/role_util.rb', line 4 def extract_roles *roles roles.flatten.map{|role| extract_role role}.compact end |