Class: Entitlements::Data::People

Inherits:
Object
  • Object
show all
Includes:
Contracts::Core
Defined in:
lib/entitlements.rb,
lib/entitlements/data/people.rb,
lib/entitlements/data/people/ldap.rb,
lib/entitlements/data/people/yaml.rb,
lib/entitlements/data/people/dummy.rb,
lib/entitlements/data/people/combined.rb

Defined Under Namespace

Classes: Combined, Dummy, LDAP, NoSuchPersonError, YAML

Constant Summary collapse

C =
::Contracts
PEOPLE_CLASSES =
{
  "combined" => Entitlements::Data::People::Combined,
  "dummy"    => Entitlements::Data::People::Dummy,
  "ldap"     => Entitlements::Data::People::LDAP,
  "yaml"     => Entitlements::Data::People::YAML
}

Class Method Summary collapse

Methods included from Contracts::Core

common, extended, included

Class Method Details

.class_for_config(config) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/entitlements/data/people.rb', line 30

def self.class_for_config(config)
  unless config.key?("type")
    raise ArgumentError, "'type' is undefined in: #{config.inspect}"
  end

  unless Entitlements::Data::People::PEOPLE_CLASSES.key?(config["type"])
    raise ArgumentError, "'type' #{config['type'].inspect} is invalid!"
  end

  Entitlements::Data::People::PEOPLE_CLASSES.fetch(config["type"])
end

.new_from_config(config) ⇒ Object



50
51
52
53
54
55
# File 'lib/entitlements/data/people.rb', line 50

def self.new_from_config(config)
  Entitlements.cache[:people_class] ||= {}
  clazz = class_for_config(config)
  fingerprint = clazz.fingerprint(config.fetch("config"))
  Entitlements.cache[:people_class][fingerprint] ||= clazz.new_from_config(config.fetch("config"))
end