Project

General

Profile

« Previous | Next » 

Revision 00fff28a

Added by Marc Dequènes over 13 years ago

  • ID 00fff28a64b7072bfad54f849d5d29c3c08a9903

[evol] attributes parameters rework §7 (organized data fix) (refs #142)

View differences:

lib/ldap_shadows/elements/object.rb
obj_aspects = {}
self.aspects.values.each do |aspect|
aspect_mapping = aspect.parameters[:mapping]
obj_aspects[aspect.handle] ||= {}
unless aspect_mapping[:associated_attributes].empty?
taken_attr_list = aspect_mapping[:associated_attributes] & attr_list
unless taken_attr_list.empty?
attrs_data = taken_attr_list.collect do |attr|
[attr, fetch_attribute_data(attr, aspect)]
end.compact
obj_aspects[aspect.handle] ||= {}
obj_aspects[aspect.handle].merge!(Hash[attrs_data])
taken_attr_list.each do |attr|
data = fetch_attribute_data(attr, aspect)
obj_aspects[aspect.handle][attr] = data unless data.nil?
end
attr_list -= taken_attr_list
end
end
......
unless aspect_mapping[:associated_relations].empty?
taken_rel_list = aspect_mapping[:associated_relations] & rel_list
unless taken_rel_list.empty?
rels_data = taken_rel_list.collect do |rel|
["rel:" + rel, fetch_relation_data(rel, aspect)]
end.compact
obj_aspects[aspect.handle] ||= {}
obj_aspects[aspect.handle].merge!(Hash[rels_data])
taken_rel_list.each do |rel|
data = fetch_relation_data(rel, aspect)
obj_aspects[aspect.handle]['rel:' + rel] = data unless data.nil?
end
rel_list -= taken_rel_list
end
end
......
end
taken_attr_list = taken_attr_list.uniq & attr_list
taken_attr_list += self.class.virtual_attributes
attrs_data = taken_attr_list.collect do |attr|
[attr, fetch_attribute_data(attr, self)]
end.compact
obj_info = Hash[attrs_data]
taken_attr_list.each do |attr|
data = fetch_attribute_data(attr, self)
obj_info[attr] = data unless data.nil?
end
attr_list -= taken_attr_list
# manage general relations
if self.class.parameters[:mapping][:associated_relations]
taken_rel_list = self.class.parameters[:mapping][:associated_relations] & rel_list
unless taken_rel_list.empty?
rels_data = taken_rel_list.collect do |rel|
["rel:" + rel, fetch_relation_data(rel, self)]
end.compact
obj_info.merge!(Hash[rels_data])
taken_rel_list.each do |rel|
data = fetch_relation_data(rel, self)
obj_info['rel:' + rel] = data unless data.nil?
end
rel_list -= taken_rel_list
end
end
......
self.aspects.values.each do |aspect|
taken_attr_list = (aspect.possible_attributes & attr_list)
taken_attr_list += aspect.virtual_attributes
attrs_data = taken_attr_list.collect do |attr|
[attr, fetch_attribute_data(attr, aspect)]
end.compact
obj_aspects[aspect.handle] ||= {}
obj_aspects[aspect.handle].merge!(Hash[attrs_data])
attr_list -= taken_attr_list
unless taken_attr_list.empty?
taken_attr_list.each do |attr|
data = fetch_attribute_data(attr, aspect)
obj_aspects[aspect.handle][attr] = data unless data.nil?
end
attr_list -= taken_attr_list
end
break if attr_list.empty?
end
......
# third pass to dispath the remaining attributes
unless attr_list.empty?
attrs_data = attr_list.collect do |attr|
[attr, fetch_attribute_data(attr, self)]
end.compact
obj_info.merge!(Hash[attrs_data])
attr_list.each do |attr|
data = fetch_attribute_data(attr, self)
obj_info[attr] = data unless data.nil?
end
end
[obj_info, obj_aspects]

Also available in: Unified diff