Module: Hydra::RoleMapperBehavior::ClassMethods
- Defined in:
- lib/hydra/role_mapper_behavior.rb
Instance Method Summary collapse
- #byname ⇒ Object
- #map ⇒ Object
- #role_names ⇒ Object
-
#roles(user_or_uid) ⇒ Object
If you pass in a nil User object (ie. user isn’t logged in), or a uid that doesn’t exist, it will return an empty array.
- #whois(r) ⇒ Object
Instance Method Details
#byname ⇒ Object
34 35 36 37 38 |
# File 'lib/hydra/role_mapper_behavior.rb', line 34 def byname @byname ||= map.each_with_object(Hash.new{ |h,k| h[k] = [] }) do |(role, usernames), memo| Array(usernames).each { |x| memo[x] << role} end end |
#map ⇒ Object
29 30 31 |
# File 'lib/hydra/role_mapper_behavior.rb', line 29 def map @map ||= load_role_map end |
#role_names ⇒ Object
5 6 7 |
# File 'lib/hydra/role_mapper_behavior.rb', line 5 def role_names map.keys end |
#roles(user_or_uid) ⇒ Object
If you pass in a nil User object (ie. user isn’t logged in), or a uid that doesn’t exist, it will return an empty array
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/hydra/role_mapper_behavior.rb', line 12 def roles(user_or_uid) if user_or_uid.kind_of?(String) user = Hydra::Ability.user_class.find_by_user_key(user_or_uid) user_id = user_or_uid elsif user_or_uid.kind_of?(Hydra::Ability.user_class) && user_or_uid.user_key user = user_or_uid user_id = user.user_key end array = byname[user_id].dup || [] array = array << 'registered' unless (user.nil? || user.new_record?) array end |
#whois(r) ⇒ Object
25 26 27 |
# File 'lib/hydra/role_mapper_behavior.rb', line 25 def whois(r) map[r] || [] end |