universe_compiler 0.3.4 → 0.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/universe_compiler/universe/entities.rb +26 -4
- data/lib/universe_compiler/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 68f3d590258d656e0fa5e6d432f6311198b9012c
|
4
|
+
data.tar.gz: adbcd0dbbe00ec7c6d01ee02783e2f80c93f7957
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe3c6d9693b48a3a0518c265514280aacb0a410cefcca8589bf602e318121d31faf6e7393987414f8500b0522ea8560806b0ce7cba0e4a0cf20bd4de6a09ca31
|
7
|
+
data.tar.gz: 6f4dfad75605f90f49cc0057ac68a08509ba82359bacb26328a8ece4c7827e9f8b7f6bd1550b6932a32f2cfb765148e0e6b9cec812d0bee33c5f0ea8af47d621
|
@@ -34,19 +34,29 @@ module UniverseCompiler
|
|
34
34
|
|
35
35
|
def delete(entity)
|
36
36
|
# Remove references to entity
|
37
|
+
impacted_entities = {}
|
37
38
|
entities.each do |e|
|
38
39
|
e.class.fields_constraints.each do |field_name, constraints|
|
39
40
|
if constraints.keys.include? :has_one
|
40
|
-
|
41
|
+
if e[field_name] == entity
|
42
|
+
e[field_name] = nil
|
43
|
+
impacted_entities[e] ||= 0
|
44
|
+
impacted_entities[e] += 1
|
45
|
+
end
|
41
46
|
end
|
42
47
|
if constraints.keys.include? :has_many
|
43
|
-
|
48
|
+
if e[field_name].include? entity
|
49
|
+
e[field_name].delete entity
|
50
|
+
impacted_entities[e] ||= 0
|
51
|
+
impacted_entities[e] += 1
|
52
|
+
end
|
44
53
|
end
|
45
54
|
end
|
46
55
|
end
|
47
56
|
# Then delete the entity
|
48
57
|
entities.delete entity
|
49
58
|
reindex_all entities
|
59
|
+
impacted_entities.keys
|
50
60
|
end
|
51
61
|
|
52
62
|
def replace(entity, by)
|
@@ -54,14 +64,25 @@ module UniverseCompiler
|
|
54
64
|
raise UniverseCompiler::Error, "Cannot replace '#{entity.as_path}' with '#{by.as_path}' which is alreadyin the universe!" if entity.universe == by.universe
|
55
65
|
|
56
66
|
# Change references to entity
|
67
|
+
impacted_entities = {by => 1}
|
57
68
|
entities.each do |e|
|
58
69
|
e.class.fields_constraints.each do |field_name, constraints|
|
59
70
|
if constraints.keys.include? :has_one
|
60
|
-
|
71
|
+
if e[field_name] == entity
|
72
|
+
e[field_name] = by
|
73
|
+
impacted_entities[e] ||= 0
|
74
|
+
impacted_entities[e] += 1
|
75
|
+
end
|
61
76
|
end
|
62
77
|
if constraints.keys.include? :has_many
|
63
78
|
if e[field_name].map! do |entity_list_item|
|
64
|
-
(entity == entity_list_item)
|
79
|
+
if (entity == entity_list_item)
|
80
|
+
impacted_entities[e] ||= 0
|
81
|
+
impacted_entities[e] += 1
|
82
|
+
by
|
83
|
+
else
|
84
|
+
entity_list_item
|
85
|
+
end
|
65
86
|
end
|
66
87
|
end
|
67
88
|
end
|
@@ -70,6 +91,7 @@ module UniverseCompiler
|
|
70
91
|
# Then replace the entity
|
71
92
|
entities[entities.index(entity)] = by
|
72
93
|
reindex_all entities
|
94
|
+
impacted_entities.keys
|
73
95
|
end
|
74
96
|
|
75
97
|
def clear
|