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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f86657355ff6c748b745dadd01508eb174992352
4
- data.tar.gz: 874518fe95ea9674746018eb1e2d28fb12b92e2f
3
+ metadata.gz: b2ae2f52c3b4809d9032158fab55e93634e6bb6f
4
+ data.tar.gz: 9da905e8331bf238bc7d4aebd1dc556181cc24b8
5
5
  SHA512:
6
- metadata.gz: 221ca6727dcfdde1389070a40aab5bc56133a51134ea346f82169bbe8239b9ae57c2bbc6c46cea22343107c1e4c0b64921957396707776b63f557a2c1192764b
7
- data.tar.gz: b2f8b6dba4580ca1c9a3e7f15d6f8a7ffc20fdb197596b710aaaefbe132eaae12a865206d3490f9134cbdea2f47e94899b014a1c744f13f2606a2667a0afa18d
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
- "@#{role_name}="+send(role_name).inspect
95
+ "#{role_name}: "+send(role_name).inspect
97
96
  end
98
- "\#<#{self.class.basename}:#{object_id}#{inc} #{ irnv*' ' }>"
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
- end
174
-
175
- # Now consider objects whose identifiers include this object.
176
- # Find our roles in those identifiers first.
177
- impacted_roles = []
178
- self.class.all_role_transitive.each do |n, role|
179
- if role.counterpart && role.counterpart.is_identifying
180
- # puts "Changing #{role.inspect} affects #{role.inspect}"
181
- impacted_roles << role
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(instance_variable_get(role.variable))
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 |klass, entity, old_key|
197
- instance_index = entity.constellation.instances[klass]
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
- instance_index.delete(old_key)
203
- instance_index[new_key] = entity
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, klass, sort)
88
+ def initialize(constellation, object_type, sort)
88
89
  @constellation = constellation
89
- @klass = klass
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 #{@klass.name} in #{@constellation.inspect}>"
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(@klass)
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
@@ -1,5 +1,5 @@
1
1
  module ActiveFacts
2
2
  module API
3
- VERSION = "1.9.9"
3
+ VERSION = "1.9.10"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activefacts-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.9
4
+ version: 1.9.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Clifford Heath