OTAKU
Dead simple server/client service built using eventmachine.
Introduction
Otaku’s original intent is to support testing of cross-process stubbing in CrossStub (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:
$ 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 ~'
Wait a minute, how abt contextual references ??
Previously, when there is references to local variables outside the proc, we need to start Otaku in a very awkward manner:
Otaku.start(:mark => '*') do |data|
'%s %s %s' % [mark, data, mark]
end
Otaku.process('hello')
# >> '* hello *'
This is no longer needed from release-0.4.0 onwards, thanks to the help with SerializableProc (github.com/ngty/serializable_proc), contextual references to global, class, instance & local variables are automatically taken care of:
x, @x, @@x, $x = 'lx', 'ix', 'cx', 'gx'
Otaku.start do |data|
[x, @x, @@x, $x].join(data)
end
Otaku.process(' & ')
# >> 'lx & ix & cx & gx'
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
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
Copyright © since 2010 NgTzeYang. See LICENSE for details.