lib/universe_compiler/universe/entities.rb in universe_compiler-0.3.5 vs lib/universe_compiler/universe/entities.rb in universe_compiler-0.3.6
- old
+ new
@@ -38,49 +38,55 @@
entities.each do |e|
e.class.fields_constraints.each do |field_name, constraints|
if constraints.keys.include? :has_one
if e[field_name] == entity
e[field_name] = nil
- impacted_entities[e] ||= 0
- impacted_entities[e] += 1
+ impacted_entities[e] ||= []
+ impacted_entities[e] << field_name
end
end
if constraints.keys.include? :has_many
if e[field_name].include? entity
e[field_name].delete entity
- impacted_entities[e] ||= 0
- impacted_entities[e] += 1
+ impacted_entities[e] ||= []
+ impacted_entities[e] << field_name unless impacted_entities[e].include? field_name
end
end
end
end
# Then delete the entity
entities.delete entity
reindex_all entities
- impacted_entities.keys
+ unless impacted_entities.empty?
+ UniverseCompiler.logger.warn "Impacts of '#{entity.as_path}' deletion:"
+ impacted_entities.each do |k, v|
+ UniverseCompiler.logger.warn " - '#{k.as_path}' fields : #{v.join ', '}"
+ end
+ end
+ impacted_entities
end
def replace(entity, by)
raise UniverseCompiler::Error, "Wrong type, cannot replace '#{entity.as_path}' by '#{by.as_path}' !" unless entity.type == by.type
raise UniverseCompiler::Error, "Cannot replace '#{entity.as_path}' with '#{by.as_path}' which is alreadyin the universe!" if entity.universe == by.universe
# Change references to entity
- impacted_entities = {by => 1}
+ impacted_entities = {}
entities.each do |e|
e.class.fields_constraints.each do |field_name, constraints|
if constraints.keys.include? :has_one
if e[field_name] == entity
e[field_name] = by
- impacted_entities[e] ||= 0
- impacted_entities[e] += 1
+ impacted_entities[e] ||= []
+ impacted_entities[e] << field_name
end
end
if constraints.keys.include? :has_many
if e[field_name].map! do |entity_list_item|
if (entity == entity_list_item)
- impacted_entities[e] ||= 0
- impacted_entities[e] += 1
+ impacted_entities[e] ||= []
+ impacted_entities[e] << field_name unless impacted_entities[e].include? field_name
by
else
entity_list_item
end
end
@@ -89,10 +95,16 @@
end
end
# Then replace the entity
entities[entities.index(entity)] = by
reindex_all entities
- impacted_entities.keys
+ unless impacted_entities.empty?
+ UniverseCompiler.logger.warn "Impacts of '#{entity.as_path}' deletion:"
+ impacted_entities.each do |k, v|
+ UniverseCompiler.logger.warn " - '#{k.as_path}' fields : #{v.join ', '}"
+ end
+ end
+ impacted_entities
end
def clear
entities.clear
clear_indices