Project

General

Profile

« Previous | Next » 

Revision d8cfa085

Added by Marc Dequènes over 14 years ago

  • ID d8cfa08523d916f7e4189fa900ecb6be4e38e696

[evol] completed aspect hooks panoply

View differences:

lib/ldap_shadows/object.rb
def save
before_save_jobs
super
after_save_jobs
end
def save!
before_save_jobs
super
after_save_jobs
end
def delete
before_delete_job
super
after_save_jobs
end
def delete_recursive
# TODO: recursive instanciation and reverse recursive hook calls
before_delete_job
self.class.delete_all(nil, :scope => :sub, :base => self.dn)
after_delete_jobs
end
protected
def before_save_jobs
check_hooks_before
check_hooks_before(:save)
check_missing_attributes
end
def check_hooks_before
def before_delete_jobs
check_hooks_before(:delete)
end
def check_hooks_before(action)
self.aspects.each do |aspect|
aklass = self.class.mapper.get_aspect_klass(aspect)
next if aklass.nil?
if self.new_entry?
aklass.hook_before_create(self.class.mapper, self)
else
aklass.hook_before_modify(self.class.mapper, self)
case action
when :save
if self.new_entry?
aklass.hook_before_create(self.class.mapper, self)
else
aklass.hook_before_modify(self.class.mapper, self)
end
when :delete
aklass.hook_before_delete(self.class.mapper, self)
end
end
end
......
end
end
def after_save_jobs
check_hooks_after(:save)
end
def after_delete_jobs
check_hooks_after(:delete)
end
def check_hooks_after(action)
self.aspects.each do |aspect|
aklass = self.class.mapper.get_aspect_klass(aspect)
next if aklass.nil?
case action
when :save
if self.new_entry?
aklass.hook_after_create(self.class.mapper, self)
else
aklass.hook_after_modify(self.class.mapper, self)
end
when :delete
aklass.hook_after_delete(self.class.mapper, self)
end
end
end
def fetch_attributes_data(attr_list, expert_attributes, admin_attributes)
attr_data = self.attributes.collect do |key, val|
if attr_list.include?(key)

Also available in: Unified diff