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 ? 5 : 1)
}

Class Method Summary collapse

Class Method Details

.cleanupObject



64
65
66
# File 'lib/otaku.rb', line 64

def cleanup
  @logger.close if @logger
end

.configObject



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

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

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



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

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

.log(*msgs) ⇒ Object



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

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

.process(data) ⇒ Object



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

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

.rootObject



41
42
43
# File 'lib/otaku.rb', line 41

def root
  File.expand_path(File.dirname(__FILE__))
end

.start(&handler) ⇒ Object



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

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

.stopObject



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

def stop
  Server.stop
end