Giter Site home page Giter Site logo

beambridge's Introduction

Beambridge

https://github.com/mathieul/beambridge

Fork of Erlectricity by Scott Fleckenstein, Tom Preston-Werner (http://github.com/mojombo/erlectricity).

The original erlectricity gem doesn't seem to be supported and updated anymore, no commit in 4 years, a pull request pending for the last 3 years.

So I've forked the repository origin of the pending pull request and did cherry pick most of the pull request commits. And I had to rename the gem so I could publish it.

Development Status: port for 1.9.3, 2.0.x, 2.1.x in progress

Description

Beambridge allows a Ruby program to receive and respond to Erlang messages sent over the Erlang binary protocol.

Install

$ gem install beambridge

The Simplest Example

Ruby side (echo.rb)

require 'beambridge'

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 Beambridge, start by forking my repo on GitHub:

https://github.com/mathieul/beambridge

To get all of the dependencies, install the gem first. The best way to get your changes merged back into core is as follows:

  1. Clone down your fork
  2. Create a topic branch to contain your change
  3. Hack away
  4. Add tests and make sure everything still passes by running rake
  5. If you are adding new functionality, document it in the README.md
  6. Do not change the version number, I will do that on my end
  7. If necessary, rebase your commits into logical chunks, without errors
  8. Push the branch up to GitHub
  9. Send me (mojombo) a pull request for your branch

Copyright

Copyright (c) 2009 Scott Fleckenstein and Tom Preston-Werner. See LICENSE for details.

beambridge's People

Contributors

mojombo avatar tmm1 avatar halorgium avatar bwbuchanan avatar abhay avatar kirindave avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.