Class: Vorpal::DbLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/vorpal/db_loader.rb

Overview

Handles loading of objects from the database.

Instance Method Summary collapse

Constructor Details

#initialize(only_owned, db_driver) ⇒ DbLoader

Returns a new instance of DbLoader.



9
10
11
12
# File 'lib/vorpal/db_loader.rb', line 9

def initialize(only_owned, db_driver)
  @only_owned = only_owned
  @db_driver = db_driver
end

Instance Method Details

#load_from_db(ids, config) ⇒ Object



14
15
16
17
# File 'lib/vorpal/db_loader.rb', line 14

def load_from_db(ids, config)
  db_roots = @db_driver.load_by_unique_key(config.db_class, ids, "id")
  load_from_db_objects(db_roots, config)
end

#load_from_db_objects(db_roots, config) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/vorpal/db_loader.rb', line 19

def load_from_db_objects(db_roots, config)
  @loaded_objects = LoadedObjects.new
  @loaded_objects.add(config, db_roots)
  @lookup_instructions = LookupInstructions.new
  explore_objects(config, db_roots)

  until @lookup_instructions.empty?
    lookup = @lookup_instructions.next_lookup
    newly_loaded_objects = lookup.load_all(@db_driver)
    unexplored_objects = @loaded_objects.add(lookup.config, newly_loaded_objects)
    explore_objects(lookup.config, unexplored_objects)
  end

  @loaded_objects
end