Class: DataMapper::DependencyQueue

Inherits:
Object
  • Object
show all
Defined in:
lib/gems/dm-core-0.9.9/lib/dm-core/dependency_queue.rb

Overview

DataMapper’s DependencyQueue is used to store callbacks for classes which may or may not be loaded already.

Instance Method Summary collapse

Constructor Details

#initializeDependencyQueue

Returns a new instance of DependencyQueue.



8
9
10
# File 'lib/gems/dm-core-0.9.9/lib/dm-core/dependency_queue.rb', line 8

def initialize
  @dependencies = {}
end

Instance Method Details

#add(class_name, &callback) ⇒ Object



12
13
14
15
16
# File 'lib/gems/dm-core-0.9.9/lib/dm-core/dependency_queue.rb', line 12

def add(class_name, &callback)
  @dependencies[class_name] ||= []
  @dependencies[class_name] << callback
  resolve!
end

#resolve!Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/gems/dm-core-0.9.9/lib/dm-core/dependency_queue.rb', line 18

def resolve!
  @dependencies.each do |class_name, callbacks|
    begin
      klass = Object.find_const(class_name)
      callbacks.each do |callback|
        callback.call(klass)
      end
      callbacks.clear
    rescue NameError
    end
  end
end