Module: Seedable::CoreExt::Serialization::InstanceMethods

Defined in:
lib/seedable/core_ext.rb

Overview

Use thread-local storage to carry the object tracker through the association traversal.

Instance Method Summary collapse

Instance Method Details

#serializable_hash_with_object_tracker(options = {}) ⇒ Object

Extend serializable_hash functionality by calling out to the object tracker.



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/seedable/core_ext.rb', line 41

def serializable_hash_with_object_tracker(options = {})
  unless object_tracker = Thread.current[:object_tracker]
    object_tracker                  = ObjectTracker.new
    clean_up                        = true
    Thread.current[:object_tracker] = object_tracker
  end

  if object_tracker.contains?(self)
    return_value = {}
  else
    object_tracker.add(self)
    return_value = serializable_hash_without_object_tracker(options)
  end
 
  Thread.current[:object_tracker] = nil if clean_up

  return_value
end