Class: BindingDumper::Dumpers::ExistingObjectDumper
- Defined in:
- lib/binding_dumper/dumpers/existing_object_dumper.rb
Overview
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)
Instance Attribute Summary
Attributes inherited from Abstract
Instance Method Summary collapse
-
#can_convert? ⇒ Boolean
Returns false, this class is only for deconverting.
-
#can_deconvert? ⇒ true, false
Returns true if ExistingObjectDumper can deconvert passed
abstract_object. -
#convert ⇒ Object
Raises an exception, don’t use this class for converting.
-
#deconvert ⇒ Object
Deconverts passed
abstract_objectback to the original state.
Methods inherited from Abstract
Constructor Details
This class inherits a constructor from BindingDumper::Dumpers::Abstract
Instance Method Details
#can_convert? ⇒ Boolean
Returns false, this class is only for deconverting
47 48 49 |
# File 'lib/binding_dumper/dumpers/existing_object_dumper.rb', line 47 def can_convert? false # really, it's only for deconverting end |
#can_deconvert? ⇒ true, false
Returns true if ExistingObjectDumper can deconvert passed abstract_object
55 56 57 |
# 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 ⇒ Object
Raises an exception, don’t use this class for converting
63 64 65 |
# File 'lib/binding_dumper/dumpers/existing_object_dumper.rb', line 63 def convert raise NotImplementedError end |
#deconvert ⇒ Object
Deconverts passed abstract_object back to the original state
73 74 75 76 77 78 79 80 81 |
# 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 |