This repository is private.
All pages are served over SSL and all pushing and pulling is done over SSH.
No one may fork, clone, or view it unless they are added as a member.
Every repository with this icon (
) is private.
Every repository with this icon (
This repository is public.
Anyone may fork, clone, or view it.
Every repository with this icon (
) is public.
Every repository with this icon (
| name | age | message | |
|---|---|---|---|
| |
.gitignore | Sun May 03 23:02:07 -0700 2009 | |
| |
History.txt | Wed Oct 28 12:39:49 -0700 2009 | |
| |
LICENSE | Sun Apr 26 10:49:12 -0700 2009 | |
| |
README.md | Wed Apr 29 15:12:00 -0700 2009 | |
| |
Rakefile | Mon Apr 27 23:18:34 -0700 2009 | |
| |
VERSION.yml | Wed Oct 28 12:39:54 -0700 2009 | |
| |
benchmarks/ | Mon Apr 27 23:18:34 -0700 2009 | |
| |
erlectricity.gemspec | Wed Oct 28 12:40:07 -0700 2009 | |
| |
examples/ | Mon Apr 27 22:41:33 -0700 2009 | |
| |
ext/ | Wed Oct 28 12:37:50 -0700 2009 | |
| |
lib/ | Wed Oct 28 12:19:56 -0700 2009 | |
| |
test/ | Wed Oct 28 12:34:41 -0700 2009 |
README.md
Erlectricity
http://github.com/mojombo/erlectricity
By Scott Fleckenstein, Tom Preston-Werner
Development Status: Production/Stable
Description
Erlectricity allows a Ruby program to receive and respond to Erlang messages sent over the Erlang binary protocol.
Install
$ gem install erlectricity
-or-
$ gem install mojombo-erlectricity -s http://gems.github.com
The Simplest Example
Ruby side (echo.rb)
require 'rubygems'
require 'erlectricity'
receive do |f|
f.when([:echo, String]) do |text|
f.send!([:result, "You said: #{text}"])
f.receive_loop
end
end
Erlang side (echo.erl)
-module(echo).
-export([test/0]).
test() ->
Cmd = "ruby echo.rb",
Port = open_port({spawn, Cmd}, [{packet, 4}, nouse_stdio, exit_status, binary]),
Payload = term_to_binary({echo, <<"hello world!">>}),
port_command(Port, Payload),
receive
{Port, {data, Data}} ->
{result, Text} = binary_to_term(Data),
io:format("~p~n", [Text])
end.
Data Type Conversions and Matching
% Port is the port opened via open_port({spawn, Cmd}, [{packet, 4}, ...])
% Message is the Erlang term to encode and send to the port
send(Port, Message) ->
port_command(Port, term_to_binary(Message)).
# Each triplet below represents:
# (line 1) the Erlang call
# (line 2) the Ruby matcher
# (line 3) the Ruby output
send(Port, test).
f.when(:test) { p :ok }
# :ok
send(Port, {atom, symbol}).
f.when([:atom, Symbol]) { |sym| p sym }
# :symbol
send(Port, {number, 1}).
f.when([:number, Fixnum]) { |num| p num }
# 1
send(Port, {string, <<"foo">>}).
f.when([:string, String]) { |str| p str }
# "foo"
send(Port, {array, [1,2,3]}).
f.when([:array, Array]) { |arr| p arr }
# [1, 2, 3]
send(Port, {array, [<<"abc">>, <<"def">>]}).
f.when([:array, Array]) { |arr| p arr }
# ["abc", "def"]
send(Port, {hash, [{key,val}]}).
f.when([:hash, Erl.hash]) { |hash| p hash }
# {:key=>:val}
send(Port, {object, {1,{2},3,<<"four">>}}).
f.when([:object, Any]) { |any| p any }
# [1, [2], 3, "four"]
Contribute
If you'd like to hack on Erlectricity, start by forking my repo on GitHub:
http://github.com/mojombo/erlectricity
To get all of the dependencies, install the gem first. The best way to get your changes merged back into core is as follows:
- Clone down your fork
- Create a topic branch to contain your change
- Hack away
- Add tests and make sure everything still passes by running
rake - If you are adding new functionality, document it in the README.md
- Do not change the version number, I will do that on my end
- If necessary, rebase your commits into logical chunks, without errors
- Push the branch up to GitHub
- Send me (mojombo) a pull request for your branch
Copyright
Copyright (c) 2009 Scott Fleckenstein and Tom Preston-Werner. See LICENSE for details.







