Module: Otaku

Defined in:
lib/otaku.rb,
lib/otaku/client.rb,
lib/otaku/server.rb,
lib/otaku/encoder.rb,
lib/otaku/handler.rb

Defined Under Namespace

Modules: Client, Encoder, Server Classes: DataProcessError, Handler, HandlerNotDefinedError

Constant Summary collapse

DEFAULTS =
{
  :ruby => 'ruby',
  :address => '127.0.0.1',
  :port => 10999,
  :log_file => '/tmp/otaku.log',
  :init_wait_time => 2 * (RUBY_PLATFORM =~ /java/i ? 3 : 1)
}

Class Method Summary collapse

Class Method Details

.cleanupObject



61
62
63
# File 'lib/otaku.rb', line 61

def cleanup
  @logger.close if @logger
end

.configObject



36
37
38
39
40
# File 'lib/otaku.rb', line 36

def config
  DEFAULTS.keys.inject({}) do |memo, name|
    memo.merge(name => send(name))
  end
end

.configure(config = {}, &block) ⇒ Object



31
32
33
34
# File 'lib/otaku.rb', line 31

def configure(config = {}, &block)
  block_given? ? yield(self) :
    config.each{|name, val| send(:"#{name}=", val) }
end

.log(*msgs) ⇒ Object



56
57
58
59
# File 'lib/otaku.rb', line 56

def log(*msgs)
  @logger ||= Logger.new(Otaku.log_file)
  [msgs].flatten.each{|msg| @logger << "[Otaku] %s\n" % msg }
end

.process(data) ⇒ Object



52
53
54
# File 'lib/otaku.rb', line 52

def process(data)
  Client.get(data)
end

.start(context = {}, &handler) ⇒ Object



42
43
44
45
46
# File 'lib/otaku.rb', line 42

def start(context = {}, &handler)
  raise HandlerNotDefinedError unless block_given?
  Server.handler = Handler.new(context, handler)
  Server.start
end

.stopObject



48
49
50
# File 'lib/otaku.rb', line 48

def stop
  Server.stop
end