module LOM::Mapper::InstanceMethods

Public Instance Methods

lh() click to toggle source

LDAP handler

# File lib/lom/mapper.rb, line 29
def lh
    self.class.lh
end
save!() click to toggle source

Save object to ldap.

If object already exists, it will be updated otherwise created.

@return [true, false]

# File lib/lom/mapper.rb, line 39
def save!
    model  = self.class
    attrs  = instance_exec(self, &model.ldap_to)
                 .transform_values {|v|
                      # Don't use Array(), not what you think on
                      # some classes such as Time
                      v = [   ] if     v.nil? 
                      v = [ v ] unless v.is_a?(Array)
                      v.to_ldap
                 }
    id, _  = Array(attrs[model.ldap_prefix])
    raise MappingError, 'prefix for dn has multiple values' if _
    dn     = model.ldap_dn_from_id(id)
    
    lh.update(dn: dn, attributes: attrs).then {|res|
        break res unless res.nil?
        attrs.reject! {|k, v| Array(v).empty? }
        lh.add(dn: dn, attributes: attrs)
    }
end