class Ubiquity::Client

Public Class Methods

new(remote_ip='localhost', port=1978) click to toggle source
# File lib/ubiquity/protocol.rb, line 40
def initialize remote_ip='localhost', port=1978
    @hooks = []
    @client = TCPSocket.new remote_ip, port
    Thread.new {
        while line = @client.gets
            if line =~ /NOTIFY:(.+)/
                notify_msg = $1.gsub("\n", "")
                @hooks.each do |h|
                    if notify_msg == h[:hook]
                        h[:cb].call
                    end
                end
            elsif line =~ /PUTS:(.+)/
                puts $1
            end

        end
    }
end

Public Instance Methods

exec(&block) click to toggle source
# File lib/ubiquity/protocol.rb, line 60
def exec &block
    a = block.to_source
    @client.puts ({:cmd => a}.to_json)
end
on(msg, &block) click to toggle source
# File lib/ubiquity/protocol.rb, line 65
def on msg, &block
    @hooks << {:hook => msg, :cb => block}
end