Skip to content

jacktang/rinterface

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RInterface

Pure Ruby client that can send RPC calls to an Erlang node. It's very much a work in progress.

License: MIT License

Play it

  • Clone the project and enter the project directory and compile the project

      git clone https://github.com/jacktang/rinterface.git`
      cd rinterface; rake;
    
  • In one terminal run the command:

      rake daemon:start
    
    This will start the erlang node named 'math'.
  • Open another terminal, and run the rpc-call from client:

      ruby examples/client.rb
    

Install it

TODO

Use in Ruby app

In your Ruby code, make a call to the Erlang node like this:

    r = Erlang::Node.rpc("math","math_server","add",[10,20])

    if r[0] == :badrpc
      puts "Got and Error. Reason #{r[1]}"
    else
      puts "Success: #{r[1]}"
    end

Where:

  • math is the node name (the -sname of the Erlang node)
  • math_server is the name of the module
  • add is the funtion to call
  • [10,20] is an array of arguments to pass to the function

The result will always be an Array of the form:

    [:ok, Response]

Where Response is the result from the Erlang, or:

    [:badrpc, Reason]

Where Reason is the 'why' it failed.

Experimental new way

The code above can be written like this now:

Erl::MathServer.add(10, 20)

(Ain`t Ruby a beauty? ;)

Use in Rails app

Here's a quick and simple example. Make sure you put the rinterface lib into RAILS_ROOT/lib and start the math_server in 'test' In the controller(controllers/math_controller.rb):

  require "rinterface"
  class MathController < ApplicationController
    def index
      a = params[:a]
      b = params[:b]
      r = Erlang::Node.rpc("math","math_server","add",[a.to_i,b.to_i])
      if r[0] == :badrpc
        @result = "Error"
      else
        @result = r[1]
      end
    end
  end

Finally, add a template for the view, and try 'http://localhost:3000/math?a=2&b=3'. This is not ideal yet and not something I'd use yet in production, but it's a starting point for experimenting.

Development Plan

  • Adopt BERT as decoder/encoder

Contribute to the project

  • Fork the project
  • Improve the code or add your idea
  • Run specs before/after patching. Use either "rake spec" or "spec spec", it`ll start the erlang daemon automatically.
  • Send me the pull request on Github
  • Sync code from this fork if you want, act as below:

git remote add jackfork git://github.com/jacktang/rinterface.git git pull jackfork master git push origin

Other stuff

About

Pure Ruby client that can talk (make rpc calls) to an Erlang node

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 96.1%
  • Erlang 3.9%