Sha256: 86be6674ccf350c2902adc4b0ac3dd5b2b0194e37315f73e95815afa3c2da27a

Contents?: true

Size: 1.61 KB

Versions: 1

Compression:

Stored size: 1.61 KB

Contents

=begin
                  Arachni-RPC
  Copyright (c) 2011 Tasos "Zapotek" Laskos <tasos.laskos@gmail.com>

  This is free software; you can copy and distribute and modify
  this program under the term of the GPL v2.0 License
  (See LICENSE file for details)

=end

require File.join( File.expand_path( File.dirname( __FILE__ ) ), '../', 'rpc' )

module Arachni
module RPC

#
# Maps the methods of remote objects to local ones.
# (Well, not really, it just passes the message along to the remote end.)
#
# You start like:
#
#    server = Arachni::RPC::EM::Client.new( :host => 'localhost', :port => 7331 )
#    bench  = Arachni::RPC::EM::Client::Mapper.new( server, 'bench' )
#
# And it allows you to do this:
#
#    res = bench.foo( 1, 2, 3 )
#
# Instead of:
#
#    res = client.call( 'bench.foo', 1, 2, 3 )
#
#
#
# The server on the other end must have an appropriate handler set, like:
#
#    class Bench
#        def foo( i = 0 )
#            return i
#        end
#    end
#
#    server = Arachni::RPC::EM::Server.new( :host => 'localhost', :port => 7331 )
#    server.add_handler( 'bench', Bench.new )
#
# @author: Tasos "Zapotek" Laskos
#                                      <tasos.laskos@gmail.com>
#                                      <zapotek@segfault.gr>
# @version: 0.1
#
class RemoteObjectMapper

    def initialize( server, remote )
        @server = server
        @remote = remote
    end

    private
    #
    # Used to provide the illusion of locality for remote methods
    #
    def method_missing( sym, *args, &block )
        call = "#{@remote}.#{sym.to_s}"
        @server.call( call, *args, &block )
    end

end

end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
arachni-rpc-0.1 lib/arachni/rpc/remote_object_mapper.rb