activefacts-api 1.9.9 → 1.9.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/activefacts/api/entity.rb +25 -19
- data/lib/activefacts/api/instance_index.rb +13 -4
- data/lib/activefacts/api/role_values.rb +2 -1
- data/lib/activefacts/api/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: b2ae2f52c3b4809d9032158fab55e93634e6bb6f
|
4
|
+
data.tar.gz: 9da905e8331bf238bc7d4aebd1dc556181cc24b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c5ab2949f5a5767f9e3eaa1951bbbe0de21bcbd2bb5a3469f127f17cae9ddbbfe0f5d184bcb6fcd6bd0d8a68cb80b683bb7abacf4e1dac3d0d2f33a77d3e0b5
|
7
|
+
data.tar.gz: d83db68561b25300a0ef71b753c0e983db8aacf35b6a7f0c48f5880772150801a4f7fcfc7e4ef1f90b4cbc361f3c9434c97cfa64bf72c621401961ce12c5c459
|
@@ -91,11 +91,10 @@ module ActiveFacts
|
|
91
91
|
|
92
92
|
public
|
93
93
|
def inspect #:nodoc:
|
94
|
-
inc = constellation ? " in #{constellation.inspect}" : ""
|
95
94
|
irnv = self.class.identifying_role_names.map do |role_name|
|
96
|
-
"
|
95
|
+
"#{role_name}: "+send(role_name).inspect
|
97
96
|
end
|
98
|
-
"
|
97
|
+
"<#{self.class.name} #{ irnv*', ' }>"
|
99
98
|
end
|
100
99
|
|
101
100
|
# When used as a hash key, the hash key of this entity instance is calculated
|
@@ -162,6 +161,7 @@ module ActiveFacts
|
|
162
161
|
# This function is transitive!
|
163
162
|
def analyse_impacts role
|
164
163
|
impacts = []
|
164
|
+
impacted_roles = []
|
165
165
|
|
166
166
|
# Consider the object itself and all its supertypes
|
167
167
|
([self.class]+self.class.supertypes_transitive).map do |supertype|
|
@@ -169,21 +169,28 @@ module ActiveFacts
|
|
169
169
|
|
170
170
|
old_key = identifying_role_values(supertype)
|
171
171
|
# puts "Need to reindex #{self.class} as #{supertype} from #{old_key.inspect}"
|
172
|
-
impacts << [supertype, self, old_key]
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
172
|
+
impacts << [constellation.instances[supertype], self, old_key]
|
173
|
+
|
174
|
+
supertype.
|
175
|
+
all_role.
|
176
|
+
each do |role_name, propagation_role|
|
177
|
+
next if role == propagation_role # Propagation has already been taken care of
|
178
|
+
next unless counterpart = propagation_role.counterpart # And the role is not unary
|
179
|
+
if counterpart.is_identifying # This object identifies another
|
180
|
+
# puts "Changing #{propagation_role.inspect} affects #{counterpart.inspect}"
|
181
|
+
impacted_roles << propagation_role
|
182
|
+
else
|
183
|
+
next if counterpart.unique # But a one-to-many
|
184
|
+
next unless value = send(propagation_role.getter) # A value is set
|
185
|
+
role_values = value.send(counterpart.getter) # This is the index we have to change
|
186
|
+
# puts "Changing #{role.inspect} of a #{self.class} requires updating #{propagation_role.counterpart.inspect}"
|
187
|
+
impacts << [role_values, self, old_key]
|
188
|
+
end
|
182
189
|
end
|
183
190
|
end
|
184
191
|
|
185
192
|
impacted_roles.each do |role|
|
186
|
-
affected_instances = Array(
|
193
|
+
affected_instances = Array(send(role.getter))
|
187
194
|
# puts "considering #{affected_instances.size} #{role.object_type.name} instances that include #{role.inspect}: #{affected_instances.map(&:identifying_role_values).inspect}"
|
188
195
|
affected_instances.each do |counterpart|
|
189
196
|
impacts.concat(counterpart.analyse_impacts(role.counterpart))
|
@@ -193,14 +200,13 @@ module ActiveFacts
|
|
193
200
|
end
|
194
201
|
|
195
202
|
def apply_impacts impacts
|
196
|
-
impacts.each do |
|
197
|
-
|
198
|
-
new_key = entity.identifying_role_values(klass)
|
203
|
+
impacts.each do |index, entity, old_key|
|
204
|
+
new_key = entity.identifying_role_values(index.object_type)
|
199
205
|
# puts "Reindexing #{klass} from #{old_key.inspect} to #{new_key.inspect}"
|
200
206
|
|
201
207
|
if new_key != old_key
|
202
|
-
|
203
|
-
|
208
|
+
index.delete_instance(entity, old_key)
|
209
|
+
index.add_instance(entity, new_key)
|
204
210
|
end
|
205
211
|
end
|
206
212
|
end
|
@@ -62,6 +62,7 @@ module ActiveFacts
|
|
62
62
|
#
|
63
63
|
class InstanceIndex
|
64
64
|
attr_reader :sort
|
65
|
+
attr_reader :object_type
|
65
66
|
|
66
67
|
# Should be in module ForwardableWithArityChecking
|
67
68
|
def self.def_single_delegator(accessor, method, *expected_arities)
|
@@ -84,15 +85,23 @@ module ActiveFacts
|
|
84
85
|
def_single_delegator :@hash, :values
|
85
86
|
def_single_delegator :@hash, :keys
|
86
87
|
|
87
|
-
def initialize(constellation,
|
88
|
+
def initialize(constellation, object_type, sort)
|
88
89
|
@constellation = constellation
|
89
|
-
@
|
90
|
+
@object_type = object_type
|
90
91
|
@sort = sort
|
91
92
|
@hash = sort ? RBTree.new : {}
|
92
93
|
end
|
93
94
|
|
94
95
|
def inspect
|
95
|
-
"<InstanceIndex for #{@
|
96
|
+
"<InstanceIndex for #{@object_type.name} in #{@constellation.inspect}>"
|
97
|
+
end
|
98
|
+
|
99
|
+
def add_instance(instance, k)
|
100
|
+
self[k] = instance
|
101
|
+
end
|
102
|
+
|
103
|
+
def delete_instance(instance, k)
|
104
|
+
@hash.delete(@sort ? form_key(k) : k)
|
96
105
|
end
|
97
106
|
|
98
107
|
def delete(k)
|
@@ -114,7 +123,7 @@ module ActiveFacts
|
|
114
123
|
|
115
124
|
def refresh_key(old_key)
|
116
125
|
value = @hash.delete(@sort ? form_key(old_key) : old_key)
|
117
|
-
new_key = value.identifying_role_values(@
|
126
|
+
new_key = value.identifying_role_values(@object_type)
|
118
127
|
@hash[@sort ? form_key(new_key) : new_key] = value if value
|
119
128
|
end
|
120
129
|
|
@@ -84,7 +84,6 @@ module ActiveFacts
|
|
84
84
|
# Exclude the excluded role, if any:
|
85
85
|
(key = key.dup).delete_at(@excluded_role) if @excluded_role
|
86
86
|
@a[form_key(key)] = value
|
87
|
-
# Old slow way: @a[form_key(index_values(value))] = value
|
88
87
|
else
|
89
88
|
@a << value
|
90
89
|
end
|
@@ -92,6 +91,8 @@ module ActiveFacts
|
|
92
91
|
|
93
92
|
def delete_instance(value, key)
|
94
93
|
if @sort
|
94
|
+
# Exclude the excluded role, if any:
|
95
|
+
(key = key.dup).delete_at(@excluded_role) if @excluded_role
|
95
96
|
deleted = @a.delete(form_key(key))
|
96
97
|
else
|
97
98
|
deleted = @a.delete(value) # Slow: it has to search the array
|