Sha256: 6fb5f45009437481ce4ccb618444281f9ed4cb18ee16fa67591c3dbee09984a4

Contents?: true

Size: 565 Bytes

Versions: 4

Compression:

Stored size: 565 Bytes

Contents

require 'rubyonacid/factory'

module RubyOnAcid

class MetaFactory < Factory
  
  attr_accessor :factory_pool
  attr_accessor :assigned_factories
  
  def initialize(factory_pool = [])
    super
    @factory_pool = factory_pool
    @assigned_factories = {}
  end
  
  def assign_factory(key, factory)
    @assigned_factories[key] = factory
  end
  
  def get_unit(key)
    @assigned_factories[key] ||= @factory_pool[rand(@factory_pool.length)]
    @assigned_factories[key].get_unit(key)
  end
  
  def reset_assignments
    @assigned_factories.clear
  end

end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rubyonacid-0.2.0 lib/rubyonacid/factories/meta.rb
rubyonacid-0.1.2 lib/rubyonacid/factories/meta.rb
rubyonacid-0.1.1 lib/rubyonacid/factories/meta.rb
rubyonacid-0.1.0 lib/rubyonacid/factories/meta.rb