lib/perobs/ObjectBase.rb in perobs-4.0.0 vs lib/perobs/ObjectBase.rb in perobs-4.1.0
- old
+ new
@@ -84,10 +84,14 @@
# @param obj object to compare this object with.
def ==(obj)
_referenced_object == obj
end
+ def eql?(obj)
+ _referenced_object._id == obj._id
+ end
+
# BasicObject provides a equal?() method that prevents method_missing from
# being called. So we have to pass the call manually to the referenced
# object.
# @param obj object to compare this object with.
def equal?(obj)
@@ -112,10 +116,24 @@
# Base class for all persistent objects. It provides the functionality
# common to all classes of persistent objects.
class ObjectBase
+ # This is a list of the native Ruby classes that are supported for
+ # instance variable assignements in addition to other PEROBS objects.
+ if RUBY_VERSION < '2.2'
+ NATIVE_CLASSES = [
+ NilClass, Integer, Bignum, Fixnum, Float, String, Time,
+ TrueClass, FalseClass
+ ]
+ else
+ NATIVE_CLASSES = [
+ NilClass, Integer, Float, String, Time,
+ TrueClass, FalseClass
+ ]
+ end
+
attr_reader :_id, :store, :myself
# New PEROBS objects must always be created by calling # Store.new().
# PEROBS users should never call this method or equivalents of derived
# methods directly.
@@ -190,10 +208,29 @@
'data' => _serialize
}
@store.db.put_object(db_obj, @_id)
end
+ #
+ def _check_assignment_value(val)
+ if val.respond_to?(:is_poxreference?)
+ # References to other PEROBS::Objects must be handled somewhat
+ # special.
+ if @store != val.store
+ PEROBS.log.fatal 'The referenced object is not part of this store'
+ end
+ elsif val.is_a?(ObjectBase)
+ PEROBS.log.fatal 'A PEROBS::ObjectBase object escaped! ' +
+ 'Have you used self() instead of myself() to get the reference ' +
+ 'of the PEROBS object that you are trying to assign here?'
+ elsif !NATIVE_CLASSES.include?(val.class)
+ PEROBS.log.fatal "Assigning objects of class #{val.class} is not " +
+ "supported. Only PEROBS objects or one of the following classes " +
+ "are supported: #{NATIVE_CLASSES.join(', ')}"
+ end
+ end
+
# Read an raw object with the specified ID from the backing store and
# instantiate a new object of the specific type.
def ObjectBase.read(store, id)
# Read the object from database.
db_obj = store.db.get_object(id)
@@ -216,13 +253,10 @@
# was created during the transaction, there is not previous state to
# restore to.
data = nil
if @_stash_map
(level - 1).downto(0) do |lvl|
- if @_stash_map[lvl]
- data = @_stash_map[lvl]
- break
- end
+ break if (data = @_stash_map[lvl])
end
end
if data
# We have a stashed version that we can restore from.
_deserialize(data)