-
Notifications
You must be signed in to change notification settings - Fork 89
The DSL Namespaced
sprsquish edited this page Aug 12, 2010
·
1 revision
You can opt out of the default behavior of mixing the DSL methods into Kernel by including the DSL itself and mixing them into your own namespace. This enables the ability to run multiple clients within the same process.
Using this method you’ll lose the command line options. Setup, start, and daemonization will need to be handled within the script.
The following example is a single ruby process that plays ping-pong with itself over XMPP:
require 'blather/client/dsl'
$stdout.sync = true
module Ping
extend Blather::DSL
def self.run; client.run; end
setup '[email protected]/ping', 'echo'
status :from => Blather::JID.new('[email protected]/pong') do |s|
puts "serve!"
say s.from, 'ping'
end
message :chat?, :body => 'pong' do |m|
puts "ping!"
say m.from, 'ping'
end
end
module Pong
extend Blather::DSL
def self.run; client.run; end
setup '[email protected]/pong', 'echo'
message :chat?, :body => 'ping' do |m|
puts "pong!"
say m.from, 'pong'
end
end
trap(:INT) { EM.stop }
trap(:TERM) { EM.stop }
EM.run do
Ping.run
Pong.run
end