class Lifesaver::Notification::IndexingGraph

Attributes

loader[RW]
models_to_index[RW]
queue[RW]

Public Class Methods

new() click to toggle source
# 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

Public Instance Methods

generate() click to toggle source
# 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) click to toggle source
# 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

Private Instance Methods

add_model_to_loader(class_name, id) click to toggle source
# File lib/lifesaver/notification/indexing_graph.rb, line 54
def add_model_to_loader(class_name, id)
  loader.add_model(class_name, id)
end
add_unvisited_associations(model) click to toggle source
# File lib/lifesaver/notification/indexing_graph.rb, line 78
def add_unvisited_associations(model)
  models = load_associations_for_model(model)
  models.each do |m|
    if model_needs_to_notify?(model)
      add_model_to_loader(m.class.name, m.id)
    else
      push_model(model)
    end
  end
end
load_associations_for_model(model) click to toggle source
# File lib/lifesaver/notification/indexing_graph.rb, line 70
def load_associations_for_model(model)
  model.associations_to_notify
end
load_into_queue() click to toggle source
# File lib/lifesaver/notification/indexing_graph.rb, line 62
def load_into_queue
  load_models.each { |model| queue << model }
end
load_models() click to toggle source
# File lib/lifesaver/notification/indexing_graph.rb, line 58
def load_models
  loader.load
end
loader_full?() click to toggle source
# File lib/lifesaver/notification/indexing_graph.rb, line 38
def loader_full?
  !loader.empty?
end
model_needs_to_notify?(model) click to toggle source
# File lib/lifesaver/notification/indexing_graph.rb, line 74
def model_needs_to_notify?(model)
  model.needs_to_notify?
end
model_should_be_indexed?(model) click to toggle source
# File lib/lifesaver/notification/indexing_graph.rb, line 66
def model_should_be_indexed?(model)
  model.has_index?
end
pop_model() click to toggle source
# File lib/lifesaver/notification/indexing_graph.rb, line 46
def pop_model
  queue.pop
end
push_model(model) click to toggle source
# File lib/lifesaver/notification/indexing_graph.rb, line 50
def push_model(model)
  queue << model
end
queue_full?() click to toggle source
# File lib/lifesaver/notification/indexing_graph.rb, line 42
def queue_full?
  !queue.empty?
end