lib/marvin/loader.rb in jeffrafter-marvin-0.1.20081115 vs lib/marvin/loader.rb in jeffrafter-marvin-0.1.20081120
- old
+ new
@@ -1,13 +1,13 @@
module Marvin
class Loader
- cattr_accessor :setup_block
-
- cattr_accessor :start_hooks, :stop_hooks
+ cattr_accessor :start_hooks, :stop_hooks, :setup_block, :type
self.stop_hooks, self.start_hooks = [], []
+ self.type = :client
+
def self.before_connecting(&blk)
self.setup_block = blk
end
def setup_defaults
@@ -29,35 +29,53 @@
end
end
def load_settings
Marvin::Settings.setup
- Marvin::Settings.default_client.configuration = Marvin::Settings.to_hash
- Marvin::Settings.default_client.setup
+ case Marvin::Loader.type
+ when :client
+ Marvin::Settings.default_client.configuration = Marvin::Settings.to_hash
+ Marvin::Settings.default_client.setup
+ when :distributed_client
+ Marvin::Settings.default_client = Marvin::Distributed::DRbClient
+ when :server
+ when :console
+ end
end
def pre_connect_setup
Marvin::DataStore.load!
require(Marvin::Settings.root / "config/setup")
self.setup_block.call unless self.setup_block.blank?
end
def run!
+ Marvin::Options.parse! unless self.type == :console
self.setup_defaults
self.load_settings
self.load_handlers
self.pre_connect_setup
self.start_hooks.each { |h| h.call }
- Marvin::Settings.default_client.run
+ case self.type
+ when :client
+ Marvin::Settings.default_client.run
+ when :server
+ Marvin::IRC::Server.run
+ when :ring_server
+ Marvin::Distributed::RingServer.run
+ when :distributed_client
+ Marvin::Distributed::DRbClient.run
+ end
end
def stop!
- Marvin::Settings.default_client.stop
+ Marvin::Settings.default_client.stop if self.type == :client
self.stop_hooks.each { |h| h.call }
Marvin::DataStore.dump!
end
- def self.run!
+ def self.run!(type = :client)
+ self.type = type.to_sym
self.new.run!
end
def self.stop!
self.new.stop!
\ No newline at end of file