lib/service_manager.rb in service_manager-0.1 vs lib/service_manager.rb in service_manager-0.2
- old
+ new
@@ -15,27 +15,27 @@
path ||= SERVICES_PATH
return if @services_loaded
load path
@services_loaded = true
end
-
+
def define_service(name = nil, &block)
name ||= File.basename(caller.first.gsub(/.rb:.+$/, ""))
ServiceManager::Service.new(:name => name).tap do |service|
yield service
services << service
end
end
-
+
def services_hash
Hash[ServiceManager.services.map { |s| [s.name.to_sym, s]}]
end
def stop(which = :all)
puts "Stopping the services..."
services.map {|s| Thread.new { s.stop } }.map(&:join)
end
-
+
def start(which = :all)
load_services
raise RuntimeError, "No services defined" if services.empty?
threads = services.map do |s|
Thread.new do