lib/activefacts/api/instance.rb in activefacts-api-0.8.9 vs lib/activefacts/api/instance.rb in activefacts-api-0.8.10

- old
+ new

@@ -13,37 +13,45 @@ # What constellation does this Instance belong to (if any): attr_accessor :constellation def initialize(args = []) #:nodoc: unless (self.class.is_entity_type) - #if (self.class.superclass != Object) - # puts "constructing #{self.class.superclass} with #{args.inspect}" - super(*args) + begin + super(*args) + rescue ArgumentError => e + e.message << " constructing a #{self.class}" + raise + end end end # Verbalise this instance def verbalise # This method should always be overridden in subclasses - raise "#{self.class} Instance verbalisation needed" end # De-assign all functional roles and remove from constellation, if any. def retract - # Delete from the constellation first, so it can remember our identifying role values + # Delete from the constellation first, while it remembers our identifying role values @constellation.__retract(self) if @constellation # Now, for all roles (from this class and all supertypes), assign nil to all functional roles # The counterpart roles get cleared automatically. ([self.class]+self.class.supertypes_transitive).each do |klass| klass.roles.each do |role_name, role| next if role.unary? - next if !role.unique - counterpart = role.counterpart - puts "Nullifying mandatory role #{role.name} of #{role.owner.name}" if counterpart.mandatory + if role.unique + # puts "Nullifying mandatory role #{role.name} of #{role.object_type.name}" if counterpart.mandatory - send "#{role.name}=", nil + send role.setter, nil + else + # puts "Not removing role #{role_name} from counterpart RoleValues #{counterpart.name}" + # Duplicate the array using to_a, as the RoleValues here will be modified as we traverse it: + send(role.name).to_a.each do |v| + v.send(counterpart.setter, nil) + end + end end end end module ClassMethods #:nodoc: