Class: Acs::Ldap::Mapper

Inherits:
Object
  • Object
show all
Defined in:
lib/acs/ldap/mapper.rb

Instance Method Summary collapse

Constructor Details

#initialize(mapping, object_class, ou, options = {}) ⇒ Mapper

mapping

key: method, key: method

> [uid: :id, sn: ‘object.other_object.sn’]]

object_class

“top”, “extensibleObject”

options method_separator => used to separate methods call if they are composed force_method_calls => perform method calls even if object#respond_to? :method returns false (util when method_missing is used)



12
13
14
15
16
17
18
19
# File 'lib/acs/ldap/mapper.rb', line 12

def initialize(mapping, object_class, ou, options = {})
  @mapping = mapping
  @object_class = object_class
  @ou = ou
  @method_separator = options[:method_separator] || '.'
  @force_method_calls = options[:force_method_calls] || false
  Acs::Ldap::logger.debug "Acs::Ldap::Mapper with options methods_separator '#{@method_separator}' force_method_calls '#{@force_method_calls}'"
end

Instance Method Details

#attributes(object) ⇒ Object

Populate a hash based on the provided mapping and object



22
23
24
25
26
27
28
# File 'lib/acs/ldap/mapper.rb', line 22

def attributes(object)
  attributes = {}
  @mapping.each do |key, method|
    attributes[key.to_sym] = chain_methods(object, method, {method_separator: @method_separator, force_method_calls: @force_method_calls}) # unless key.to_sym == :uid
  end
  attributes
end

#get(key, object) ⇒ Object

returns the value correponding to the key of the object based on the provided mapping



36
37
38
39
40
41
42
43
# File 'lib/acs/ldap/mapper.rb', line 36

def get(key, object)
  if @mapping.has_key?(key)
    chain_methods(object, @mapping[key], {method_separator: @method_separator, force_method_calls: @force_method_calls})
  else
    Acs::Ldap::logger.error "Acs::Ldap::Mapper Error while trying to fetch key '#{key}' on object '#{object}' with mapping '#{@mapping}'"
    nil
  end
end

#object_classObject

return the object classes



31
32
33
# File 'lib/acs/ldap/mapper.rb', line 31

def object_class
  @object_class
end

#ouObject

get the ou (eg. ‘people’)



51
52
53
# File 'lib/acs/ldap/mapper.rb', line 51

def ou
  @ou
end

#uid(object) ⇒ Object

shortcut method



46
47
48
# File 'lib/acs/ldap/mapper.rb', line 46

def uid(object)
  get(:uid, object)
end