Module: Entitlements::Extras

Includes:
Contracts::Core
Defined in:
lib/entitlements.rb,
lib/entitlements/extras.rb,
lib/entitlements/extras/base.rb,
lib/entitlements/extras/orgchart/base.rb,
lib/entitlements/extras/orgchart/logic.rb,
lib/entitlements/extras/ldap_group/base.rb,
lib/entitlements/extras/orgchart/person_methods.rb,
lib/entitlements/extras/orgchart/rules/management.rb,
lib/entitlements/extras/ldap_group/rules/ldap_group.rb,
lib/entitlements/extras/orgchart/rules/direct_report.rb,
lib/entitlements/extras/ldap_group/filters/member_of_ldap_group.rb

Defined Under Namespace

Classes: Base, LDAPGroup, Orgchart

Constant Summary collapse

C =
::Contracts

Class Method Summary collapse

Methods included from Contracts::Core

common, extended, included

Class Method Details

.load_extra(namespace, path = nil) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/entitlements/extras.rb', line 18

def self.load_extra(namespace, path = nil)
  path ||= File.expand_path("./extras", __dir__)
  unless File.file?(File.join(path, namespace, "base.rb"))
    raise Errno::ENOENT, "Error loading #{namespace}: There is no file `base.rb` in directory `#{path}/#{namespace}`."
  end

  require File.join(path, namespace, "base.rb")
  class_name = ["Entitlements", "Extras", Entitlements::Util::Util.camelize(namespace), "Base"].join("::")
  clazz = Kernel.const_get(class_name)
  clazz.init

  # Register any rules defined by this class with the handler
  register_rules(clazz)

  # Register any additional methods on Entitlements::Models::Person
  register_person_extra_methods(clazz)

  # Record this extra's class as having been loaded.
  Entitlements.record_loaded_extra(clazz)

  # Contract return
  @namespace_class ||= {}
  @namespace_class[namespace] ||= clazz
end

.register_person_extra_methods(clazz) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/entitlements/extras.rb', line 69

def self.register_person_extra_methods(clazz)
  return unless clazz.respond_to?(:person_methods)

  clazz.person_methods.each do |method_name|
    clazz_without_base = clazz.to_s.split("::")[0..-2]
    method_class_name = [clazz_without_base, "PersonMethods"].join("::")
    method_class = Kernel.const_get(method_class_name)
    Entitlements.register_person_extra_method(method_name, method_class)
  end

  nil
end

.register_rules(clazz) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/entitlements/extras.rb', line 50

def self.register_rules(clazz)
  return unless clazz.respond_to?(:rules)

  clazz.rules.each do |rule_name|
    rule_class_name = [clazz.to_s.sub(/::Base\z/, "::Rules"), Entitlements::Util::Util.camelize(rule_name)].join("::")
    rule_class = Kernel.const_get(rule_class_name)
    Entitlements::Data::Groups::Calculated.register_rule(rule_name, rule_class)
  end

  nil
end