lib/acs/ldap/pusher.rb in acs-ldap-0.2.0 vs lib/acs/ldap/pusher.rb in acs-ldap-0.2.1

- old
+ new

@@ -9,19 +9,19 @@ def mapper=(mapper) @mapper = mapper end - def save(model) + def save(model, options = {}) if exist?(model) update(model) else create(model) end end - def create(model) + def create(model, options = {}) attributes = @mapper.attributes(model).except!(:uid) attributes.merge!(objectClass: @mapper.object_class) Acs::Ldap.logger.debug "Pusher#create dn '#{dn(model)}' attributes '#{attributes.inspect}'" @@ -29,23 +29,30 @@ dn(model), attributes ) end - def update(model, attributes = nil) + def update(model, options = {}) + changes = options.fetch(:changes, nil) attributes = @mapper.attributes(model).except(:uid) operations = [] attributes.each do |key, value| - operations << [:replace, key.to_s, value] if attributes.nil? or attributes.include?(key) + if attributes.nil? or attributes.include?(key) + if changes.nil? + operations << [:replace, key.to_s, value] + else + operations << [:replace, key.to_s, value] if changes.has_key?(key) + end + end end @connector.update( dn(model), operations ) end - def destroy(model) + def destroy(model, options = {}) @connector.delete(dn(model)) end def flush @connector.delete_all(ou)