Class: Crosstest::Psychic::FactoryManager

Inherits:
Object
  • Object
show all
Includes:
Core::Logger
Defined in:
lib/crosstest/psychic/factory_manager.rb

Constant Summary collapse

BUILT_IN_DIR =
File.expand_path('../factories', __FILE__)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ FactoryManager


31
32
33
# File 'lib/crosstest/psychic/factory_manager.rb', line 31

def initialize(*args)
  @factories = self.class.factory_classes.map { |k| k.new(*args) }
end

Instance Attribute Details

#factoriesObject (readonly)

Returns the value of attribute factories


29
30
31
# File 'lib/crosstest/psychic/factory_manager.rb', line 29

def factories
  @factories
end

Class Method Details

.autoload_factories!Object


9
10
11
12
13
14
# File 'lib/crosstest/psychic/factory_manager.rb', line 9

def autoload_factories!
  # Load built-in task factories
  Dir.glob("#{BUILT_IN_DIR}/*.rb", File::FNM_CASEFOLD).each do |task_factory_file|
    require task_factory_file
  end
end

.clearObject


24
25
26
# File 'lib/crosstest/psychic/factory_manager.rb', line 24

def clear
  factory_classes.clear
end

.factory_classesObject


16
17
18
# File 'lib/crosstest/psychic/factory_manager.rb', line 16

def factory_classes
  @factory_classes ||= Set.new
end

.register_factory(klass) ⇒ Object


20
21
22
# File 'lib/crosstest/psychic/factory_manager.rb', line 20

def register_factory(klass)
  factory_classes.add klass
end

Instance Method Details

#active?(klass) ⇒ Boolean


39
40
41
42
43
# File 'lib/crosstest/psychic/factory_manager.rb', line 39

def active?(klass)
  factories.find do | factory |
    factory.is_a? klass
  end
end

#active_factoriesObject


35
36
37
# File 'lib/crosstest/psychic/factory_manager.rb', line 35

def active_factories
  factories.select(&:active?).sort_by(&:priority)
end