Sha256: 5d05d58d5e0d9f821d01ed638a598b8f48cba2236240d2aed020cc1a564f0844

Contents?: true

Size: 777 Bytes

Versions: 5

Compression:

Stored size: 777 Bytes

Contents

# this code will be moved/renamed to Hydra::AccessControl::RoleMapperBehavior (with the appropriate namespace changes) in Hydra 5.0
require 'yaml'
module Hydra::RoleMapperBehavior
  extend ActiveSupport::Concern

  module ClassMethods
    def role_names
      map.keys
    end
    def roles(username)
      byname[username]||[]
    end
    
    def whois(r)
      map[r]||[]
    end

    def map
      @map ||= YAML.load(File.open(File.join(Rails.root, "config/role_map_#{Rails.env}.yml")))
    end


    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
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
hydra-access-controls-0.0.2 lib/hydra/role_mapper_behavior.rb
hydra-access-controls-0.0.1 lib/hydra/role_mapper_behavior.rb
hydra-head-4.0.3 app/models/hydra/role_mapper_behavior.rb
hydra-head-4.0.2 app/models/hydra/role_mapper_behavior.rb
hydra-head-4.0.1 app/models/hydra/role_mapper_behavior.rb