Class: DataMapper::DependencyQueue
- Inherits:
-
Object
- Object
- DataMapper::DependencyQueue
- Defined in:
- 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
- #add(class_name, &callback) ⇒ Object
-
#initialize ⇒ DependencyQueue
constructor
A new instance of DependencyQueue.
- #resolve! ⇒ Object
Constructor Details
#initialize ⇒ DependencyQueue
Returns a new instance of DependencyQueue.
8 9 10 |
# File '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/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/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 |