Class: Sqreen::Ecosystem::ModuleRegistry

Inherits:
Object
  • Object
show all
Includes:
Loggable
Defined in:
lib/sqreen/ecosystem/module_registry.rb

Instance Method Summary collapse

Constructor Details

#initializeModuleRegistry

Returns a new instance of ModuleRegistry.



13
14
15
# File 'lib/sqreen/ecosystem/module_registry.rb', line 13

def initialize
  @mods = []
end

Instance Method Details

#destroy_allObject



34
35
36
# File 'lib/sqreen/ecosystem/module_registry.rb', line 34

def destroy_all
  # not implemented
end

#each_module(type = nil, &block) ⇒ Object

Parameters:

  • type (Class) (defaults to: nil)


39
40
41
42
43
44
45
46
# File 'lib/sqreen/ecosystem/module_registry.rb', line 39

def each_module(type = nil, &block)
  selected_mods = type ? (@mods.select { |mod| mod.is_a?(type) }) : @mods
  if block_given?
    selected_mods.each(&block)
  else
    selected_mods.each
  end
end

#init_allObject



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/sqreen/ecosystem/module_registry.rb', line 21

def init_all
  logger.info { "Initializing #{@mods.size} ecosystem modules" }
  each_module do |mod|
    unless mod.respond_to? :setup
      logger.debug { "Module with type #{mod.class} requires no initialization" }
      next
    end

    logger.debug { "Initializing module with type #{mod.class}" }
    mod.setup
  end
end

#module_subset(type) ⇒ Object



48
49
50
# File 'lib/sqreen/ecosystem/module_registry.rb', line 48

def module_subset(type)
  each_module(type).to_a
end

#register(mod) ⇒ Object



17
18
19
# File 'lib/sqreen/ecosystem/module_registry.rb', line 17

def register(mod)
  @mods << mod
end