Class: Marvin::Loader

Inherits:
Object
  • Object
show all
Defined in:
lib/marvin/loader.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.after_stop(&blk) ⇒ Object



21
22
23
# File 'lib/marvin/loader.rb', line 21

def self.after_stop(&blk)
  self.stop_hooks << blk unless blk.blank?
end

.before_connecting(&blk) ⇒ Object



9
10
11
# File 'lib/marvin/loader.rb', line 9

def self.before_connecting(&blk)
  self.setup_block = blk
end

.before_run(&blk) ⇒ Object



17
18
19
# File 'lib/marvin/loader.rb', line 17

def self.before_run(&blk)
  self.start_hooks << blk unless blk.blank?
end

.run!(type = :client) ⇒ Object



76
77
78
79
# File 'lib/marvin/loader.rb', line 76

def self.run!(type = :client)
  self.type = type.to_sym
  self.new.run!
end

.stop!Object



81
82
83
# File 'lib/marvin/loader.rb', line 81

def self.stop!
  self.new.stop!
end

Instance Method Details

#load_handlersObject



25
26
27
28
29
30
# File 'lib/marvin/loader.rb', line 25

def load_handlers
  handlers = Dir[Marvin::Settings.root / "handlers/**/*.rb"].map { |h| h[0..-4] }
  handlers.each do |handler|
    require handler
  end
end

#load_settingsObject



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/marvin/loader.rb', line 32

def load_settings
  Marvin::Settings.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

#pre_connect_setupObject



45
46
47
48
49
# File 'lib/marvin/loader.rb', line 45

def pre_connect_setup
  Marvin::DataStore.load!
  require(Marvin::Settings.root / "config/setup")
  self.setup_block.call unless self.setup_block.blank?
end

#run!Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/marvin/loader.rb', line 51

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 }
  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

#setup_defaultsObject



13
14
15
# File 'lib/marvin/loader.rb', line 13

def setup_defaults
  Marvin::Logger.setup
end

#stop!Object



70
71
72
73
74
# File 'lib/marvin/loader.rb', line 70

def stop!
  Marvin::Settings.default_client.stop if self.type == :client
  self.stop_hooks.each { |h| h.call }
  Marvin::DataStore.dump!
end