Class: Rubyang::Database::ComponentManager
- Inherits:
-
Object
- Object
- Rubyang::Database::ComponentManager
- Defined in:
- lib/rubyang/database/component_manager.rb
Defined Under Namespace
Classes: Component
Instance Method Summary collapse
-
#initialize ⇒ ComponentManager
constructor
A new instance of ComponentManager.
- #run(hook) ⇒ Object
- #update(components) ⇒ Object
Constructor Details
#initialize ⇒ ComponentManager
Returns a new instance of ComponentManager.
46 47 48 |
# File 'lib/rubyang/database/component_manager.rb', line 46 def initialize @components = Array.new end |
Instance Method Details
#run(hook) ⇒ Object
70 71 72 73 74 |
# File 'lib/rubyang/database/component_manager.rb', line 70 def run hook @components.select{ |c| c.hook == hook }.each{ |c| c.run } end |
#update(components) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/rubyang/database/component_manager.rb', line 50 def update components current_component_names = @components.map{ |c| c.name } new_component_names = components.map{ |c| c[0] } unloading_component_names = current_component_names - new_component_names loading_component_names = new_component_names - current_component_names puts "Load: #{loading_component_names}" puts "Unload: #{unloading_component_names}" unloading_component_names.each{ |n| component = @components.find{ |c| c.name == n } component.thread.kill @components.delete_if{ |c| c.name == n } } loading_component_names.each{ |n| name, hook, path = components.find{ |c| c[0] == n } component = Component.new name, hook, path component.start @components.push component } end |