lib/rubyonacid/factories/meta.rb in rubyonacid-0.3.1 vs lib/rubyonacid/factories/meta.rb in rubyonacid-0.4.0
- old
+ new
@@ -1,29 +1,26 @@
require 'rubyonacid/factory'
module RubyOnAcid
-#The MetaFactory assigns factories to requested value types.
+#The MetaFactory assigns its source factories to requested value types.
class MetaFactory < Factory
- #An array of Factory objects to assign to keys.
- attr_accessor :factory_pool
-
- def initialize(factory_pool = [])
+ #Takes a hash with all keys supported by Factory.
+ def initialize(options = {})
super
- @factory_pool = factory_pool
@assigned_factories = {}
end
#Assign a factory for subsequent get_unit requests for the given key.
def assign_factory(key, factory)
@assigned_factories[key] = factory
end
#Returns the value of get_unit from the Factory assigned to the given key.
- #When a key is needed that a Factory is not already assigned to, one will be assigned at random from the factory_pool.
+ #When a key is needed that a Factory is not already assigned to, one will be assigned at random from the pool of source factories.
def get_unit(key)
- @assigned_factories[key] ||= @factory_pool[rand(@factory_pool.length)]
+ @assigned_factories[key] ||= source_factories[rand(source_factories.length)]
@assigned_factories[key].get_unit(key)
end
#Clear all factory assignments.
def reset_assignments
\ No newline at end of file