Class: Seedable::ObjectTracker

Inherits:
Object
  • Object
show all
Defined in:
lib/seedable/object_tracker.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeObjectTracker

Create a new instance of the object tracker.



10
11
12
# File 'lib/seedable/object_tracker.rb', line 10

def initialize
  @graph = {}
end

Instance Attribute Details

#graphObject

Returns the value of attribute graph.



6
7
8
# File 'lib/seedable/object_tracker.rb', line 6

def graph
  @graph
end

Instance Method Details

#add(object) ⇒ Object

Add this object to the object tracker.



24
25
26
27
28
# File 'lib/seedable/object_tracker.rb', line 24

def add(object)
  key, id = to_key_and_id(object)

  @graph[key] ? @graph[key] << id : @graph[key] = [id]
end

#contains?(object) ⇒ Boolean

Determine if the object tracker has already picked this object up.

Returns:

  • (Boolean)


16
17
18
19
20
# File 'lib/seedable/object_tracker.rb', line 16

def contains?(object)
  key, id = to_key_and_id(object)

  @graph[key].is_a?(Enumerable) ? @graph[key].include?(id) : @graph[key]
end

#to_sObject

Display the object tracker in yaml for easy viewing.



32
33
34
# File 'lib/seedable/object_tracker.rb', line 32

def to_s
  @graph.to_yaml
end