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
36 37 38 39 40 41 42 43 |
# File 'lib/hydra/role_mapper_behavior.rb', line 36 def byname return @byname if @byname m = Hash.new{|h,k| h[k]=[]} @byname = map.inject(m) do|memo, (role,usernames)| ((usernames if usernames.respond_to?(:each)) || [usernames]).each { |x| memo[x]<<role} memo end end |
#map ⇒ Object
31 32 33 |
# File 'lib/hydra/role_mapper_behavior.rb', line 31 def map @map ||= YAML.load(File.open(File.join(Rails.root, "config/role_map_#{Rails.env}.yml"))) end |
#role_names ⇒ Object
7 8 9 |
# File 'lib/hydra/role_mapper_behavior.rb', line 7 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
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/hydra/role_mapper_behavior.rb', line 14 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
27 28 29 |
# File 'lib/hydra/role_mapper_behavior.rb', line 27 def whois(r) map[r]||[] end |