class BindingDumper::Dumpers::ExistingObjectDumper
profile = Profile.allocate profile.first_name = profile # <– so the object is recursive profile.last_name = StringIO.new # <– and unmarshalable dump = BindingDumper::UniversalDumper.convert(profile)
>¶ ↑
{
:_klass => Profile, :_ivars => { :@first_name => { :_existing_object_id => 47687640 # <-- right here }, :@last_name => { :_klass => StringIO, :_undumpable => true } }, :_old_object_id => 47687640
}
restored = BindingDumper::UniversalDumper.deconvert(profile)
restored.profile.equal?(restored) # => true # (they have the same object id)
Public Instance Methods
can_convert?()
click to toggle source
Returns false, this class is only for deconverting
# File lib/binding_dumper/dumpers/existing_object_dumper.rb, line 47 def can_convert? false # really, it's only for deconverting end
can_deconvert?()
click to toggle source
Returns true if ExistingObjectDumper
can deconvert passed abstract_object
@return [true, false]
# File lib/binding_dumper/dumpers/existing_object_dumper.rb, line 55 def can_deconvert? hash.is_a?(Hash) && hash.has_key?(:_existing_object_id) end
convert()
click to toggle source
Raises an exception, don’t use this class for converting
@raise [NotImplementedError]
# File lib/binding_dumper/dumpers/existing_object_dumper.rb, line 63 def convert raise NotImplementedError end
deconvert()
click to toggle source
Deconverts passed abstract_object
back to the original state
@return [Object]
@raise [RuntimeError] when object doesn’t exist in the memory
# File lib/binding_dumper/dumpers/existing_object_dumper.rb, line 73 def deconvert data_without_object_id = hash.dup.delete(:_existing_object_id) unless UniversalDumper.memories.has_key?(existing_object_id) raise "Object with id #{existing_object_id} wasn't dumped. Something is wrong." end UniversalDumper.memories[existing_object_id] end
Private Instance Methods
existing_object_id()
click to toggle source
# File lib/binding_dumper/dumpers/existing_object_dumper.rb, line 85 def existing_object_id hash[:_existing_object_id] end