Class: Entitlements::Extras::Orgchart::PersonMethods

Inherits:
Base
  • Object
show all
Includes:
Contracts::Core
Defined in:
lib/entitlements/extras/orgchart/person_methods.rb

Constant Summary collapse

C =
::Contracts

Class Method Summary collapse

Methods inherited from Base

init, person_methods, rules

Methods inherited from Base

config

Class Method Details

.manager(person) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/entitlements/extras/orgchart/person_methods.rb', line 20

def self.manager(person)
  # User to manager map is assumed to be stored in a YAML file wherein the key is the
  # username and the value is a hash. The value contains a key "manager" with the username
  # of the manager.
  @user_to_manager_map ||= begin
    unless config["manager_map_file"]
      raise ArgumentError, "To use #{self}, `manager_map_file` must be defined in the configuration!"
    end

    manager_map_file = Entitlements::Util::Util.absolute_path(config["manager_map_file"])

    unless File.file?(manager_map_file)
      raise Errno::ENOENT, "The `manager_map_file` #{manager_map_file} does not exist!"
    end

    YAML.load(File.read(manager_map_file))
  end

  u = person.uid.downcase
  unless @user_to_manager_map.key?(u)
    raise "User #{u} is not included in manager map data!"
  end
  unless @user_to_manager_map[u]["manager"]
    raise "User #{u} does not have a manager listed in manager map data!"
  end
  @user_to_manager_map[u]["manager"]
end

.reset!Object



48
49
50
51
# File 'lib/entitlements/extras/orgchart/person_methods.rb', line 48

def self.reset!
  @user_to_manager_map = nil
  @extra_config = nil
end