Class: Entitlements::Extras::Orgchart::Logic
- Inherits:
-
Object
- Object
- Entitlements::Extras::Orgchart::Logic
show all
- Includes:
- Contracts::Core
- Defined in:
- lib/entitlements/extras/orgchart/logic.rb
Constant Summary
collapse
- C =
::Contracts
Instance Method Summary
collapse
common, extended, included
Constructor Details
#initialize(people:) ⇒ Logic
Returns a new instance of Logic.
18
19
20
21
22
|
# File 'lib/entitlements/extras/orgchart/logic.rb', line 18
def initialize(people:)
@people_hash = people.map { |uid, person| [uid.downcase, person] }.to_h
@direct_reports_cache = nil
@all_reports_cache = nil
end
|
Instance Method Details
#all_reports(manager) ⇒ Object
45
46
47
48
|
# File 'lib/entitlements/extras/orgchart/logic.rb', line 45
def all_reports(manager)
manager_uid = manager.uid.downcase
all_reports_cache.key?(manager_uid) ? all_reports_cache[manager_uid] : Set.new
end
|
#direct_reports(manager) ⇒ Object
32
33
34
35
|
# File 'lib/entitlements/extras/orgchart/logic.rb', line 32
def direct_reports(manager)
manager_uid = manager.uid.downcase
direct_reports_cache.key?(manager_uid) ? direct_reports_cache[manager_uid] : Set.new
end
|
#management_chain(person) ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/entitlements/extras/orgchart/logic.rb', line 57
def management_chain(person)
person_uid = person.uid.downcase
@management_chain_cache ||= {}
return @management_chain_cache[person_uid] if @management_chain_cache[person_uid].is_a?(Set)
@management_chain_cache[person_uid] = Set.new
if person.manager && person.manager != person.uid
person_manager_uid = person.manager.downcase
unless @people_hash.key?(person_manager_uid)
raise ArgumentError, "Manager #{person.manager.inspect} for person #{person.uid.inspect} does not exist!"
end
@management_chain_cache[person_uid].add @people_hash[person_manager_uid]
@management_chain_cache[person_uid].merge management_chain(@people_hash[person_manager_uid])
end
@management_chain_cache[person_uid]
end
|