Sha256: 898a551b15c6b3fcab52a78ef0f963fe484e4a5aee592b75a2b22190c0ff2d52

Contents?: true

Size: 500 Bytes

Versions: 5

Compression:

Stored size: 500 Bytes

Contents

require 'yaml'
class RoleMapper
  @@map = YAML.load(File.open(File.join(Rails.root, "config/role_map_#{Rails.env}.yml")))
  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
  class << self
    def role_names
      @@map.keys
    end
    def roles(username)
      @@byname[username]||[]
    end
    
    def whois(r)
      @@map[r]||[]
    end
    
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
hydra-head-4.0.0.rc6 app/models/role_mapper.rb
hydra-head-4.0.0.rc5 app/models/role_mapper.rb
hydra-head-4.0.0.rc4 app/models/role_mapper.rb
hydra-head-4.0.0.rc3 app/models/role_mapper.rb
hydra-head-4.0.0.rc2 app/models/role_mapper.rb