Class: Lifesaver::Notification::IndexingGraph

Inherits:
Object
  • Object
show all
Defined in:
lib/lifesaver/notification/indexing_graph.rb

Instance Method Summary collapse

Constructor Details

#initializeIndexingGraph

Returns a new instance of IndexingGraph.



4
5
6
7
8
# File 'lib/lifesaver/notification/indexing_graph.rb', line 4

def initialize
  @queue = Lifesaver::Notification::TraversalQueue.new
  @loader = Lifesaver::Notification::EagerLoader.new
  @models_to_index = []
end

Instance Method Details

#generateObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/lifesaver/notification/indexing_graph.rb', line 19

def generate
  loop do
    if queue_full?
      model = pop_model
      models_to_index << model if model_should_be_indexed?(model)
      add_unvisited_associations(model)
    elsif loader_full?
      load_into_queue
    else
      break
    end
  end
  models_to_index
end

#initialize_models(serialized_models) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/lifesaver/notification/indexing_graph.rb', line 10

def initialize_models(serialized_models)
  serialized_models.each do |model_hash|
    model = Lifesaver::SerializedModel.new
    model.class_name = model_hash['class_name']
    model.id = model_hash['id']
    add_model_to_loader(model.class_name, model.id)
  end
end