OTAKU

Dead simple server/client service built using eventmachine.

Introduction

Otaku’s original intent is to support testing of cross-process stubbing in cross-stub (github.com/ngty/cross-stub). It’s usefulness in other aspects of my hacking life prompts me to extract it out, & package it as a generic solution. Its primary intent is to be dead simple to use & easy to customize, of course, both criteria subjected to very my own tastes.

Getting Started

It’s hosted on rubygems.org:

$ sudo gem install otaku

Using It

1. Starting service & defining handler

require 'otaku'

Otaku.start do |data|
  result = '~ %s ~' % data
end

2. Sending processing request

require 'otaku'

Otaku.process('hello')
# >> '~ hello ~'

Unfortunately …

Most of the times, we won’t have anything as simple as above, the following illustrates the problem of contextual reference:

mark = '*'
Otaku.start do |data|
  '%s %s %s' % [mark, data, mark]
end

Otaku.process('hello') # failure !!

The reason is that the proc that we passed to Otaku.start is being marshalled while being passed to the server as a handler, in the process, the contextual references are lost. A workaround for this problem is:

Otaku.start(:mark => '*') do |data|
  '%s %s %s' % [mark, data, mark]
end

Otaku.process('hello') # >> '* hello *'

Configuraing It

Otaku ships with the following defaults:

Otaku.address         # >> '127.0.0.1'
Otaku.port            # >> 10999
Otaku.init_wait_time  # >> 2
Otaku.log_file        # >> '/tmp/otaku.log'
Otaku.ruby            # >> 'ruby' # (the current in-use ruby)

Configuring can be done via:

1. Configuration Proc

Otaku.configure do |config|
  config.init_wait_time = 10
  # (more typing, more customizing)
end

2. Configuration Hash

Otaku.configure({
  :init_wait_time => 10
  # (more typing, more customizing)
})

3. Writer Method

Otaku.init_wait_time = 10

TODO

  1. Currently, only integration testing is done …

Note on Patches/Pull Requests

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)

  • Send me a pull request. Bonus points for topic branches.

Copyright © since 2010 NgTzeYang. See LICENSE for details.