class Farcall::Provider

Could be used as a base class to export its methods to the remote. You are not limited to subclassing, instead, you can set any class instance as a provider setting it to the Farcall::Endpoint#provider. The provider has only one method^ which can not be accessed remotely: far_interface, which is used locally to object interface to call remote methods for two-way connections.

Public Class Methods

new(endpoint: nil, transport: nil, **params) click to toggle source

Create an instance connected to the Farcall::Transport or Farcall::Endpoint - use what suites you better.

Please remember that Farcall::Transport instance could be used with only one connected object, unlike Farcall::Endpoint, which could be connected to several consumers.

@param [Farcall::Endpoint] endpoint to connect to (no transport should be provided).

note that if endpoint is specified, transport would be ignored eeven if used

@param [Farcall::Transport] transport to use (don't use endpoint then)

# File lib/farcall/endpoint.rb, line 265
def initialize endpoint: nil, transport: nil, **params
  if endpoint || transport || params.size > 0
    @endpoint          = if endpoint
                           endpoint
                         else
                           transport ||= Farcall::Transport.create **params
                           Farcall::Endpoint.new transport
                         end
    @endpoint.provider = self
  end
end

Public Instance Methods

close_connection() click to toggle source

close connection if need

# File lib/farcall/endpoint.rb, line 288
def close_connection
  @endpoint.close
end
far_interface() click to toggle source

Get remote interface @return [Farcall::Interface] to call methods on the other end, e.g. if this provider would like to call other party's methiod, it can do it cimply by:

far_interface.some_method('hello')
# File lib/farcall/endpoint.rb, line 283
def far_interface
  @endpoint.remote
end

Protected Instance Methods

remote_call(name, args) click to toggle source

Override it to repond to remote calls. Base implementation let invoke only public method only owned by this class. Be careful to not to expose more than intended!

# File lib/farcall/endpoint.rb, line 296
def remote_call name, args
  m = public_method(name)
  if m && m.owner == self.class
    m.call(*args)
  else
    raise NoMethodError, "method #{name} is not found"
  end
rescue NameError
  raise NoMethodError, "method #{name} is not found"
end