add acl to drb server
[god.git] / lib / god / server.rb
blob4f578c74065ff30378b3886d24b3e1c71bc83b07
1 require 'drb'
2 require 'drb/acl'
4 # The God::Server oversees the DRb server which dishes out info on this God daemon.
6 module God
8   class Server
9     attr_reader :host, :port
11     def initialize(host = nil, port = nil, allow = [])
12       @host = host
13       @port = port
14       @acl = %w{deny all} + allow.inject([]) { |acc, a| acc + ['allow', a] }
15       puts "Starting on #{@host}:#{@port}"
16       start
17     end
19     def method_missing(*args, &block)
20       God.send(*args, &block)
21     end
23     private
25     def start
26       acl = ACL.new(@acl)
27       DRb.install_acl(acl)
28       
29       @drb ||= DRb.start_service("druby://#{@host}:#{@port}", self) 
30     end
31   end
33 end