Module: AD::Framework::Patterns::Persistence::InstanceMethods

Defined in:
lib/ad-framework/patterns/persistence.rb

Instance Method Summary collapse

Instance Method Details

#createObject



30
31
32
33
34
35
36
37
# File 'lib/ad-framework/patterns/persistence.rb', line 30

def create
  self.fields[:distinguishedname] = self.dn
  self.fields[:objectclass] = (self.schema.object_classes.collect do |object_class|
    object_class.schema.ldap_name
  end).compact
  self.connection.add({ :dn => self.dn, :attributes => self.fields.to_hash })
  self.reload
end

#destroyObject



47
48
49
# File 'lib/ad-framework/patterns/persistence.rb', line 47

def destroy
  self.connection.delete(self.dn)
end

#new_entry?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/ad-framework/patterns/persistence.rb', line 19

def new_entry?
  !(self.fields[:distinguishedname] || self.fields[:dn])
end

#saveObject



23
24
25
26
27
28
29
# File 'lib/ad-framework/patterns/persistence.rb', line 23

def save
  if self.new_entry?
    self.create
  else
    self.update
  end
end

#updateObject



38
39
40
41
42
43
44
45
# File 'lib/ad-framework/patterns/persistence.rb', line 38

def update
  self.connection.open do |c|
    self.fields.changes.each do |name, value|
      c.replace_attribute(self.dn, name, value)
    end
  end
  self.reload
end