Class: DRb::DRbObject
| Relationships & Source Files | |
| Inherits: | Object | 
| Defined in: | lib/drb/drb.rb, lib/drb/eq.rb, lib/drb/gw.rb  | 
    
Overview
Object wrapping a reference to a remote drb object.
Method calls on this object are relayed to the remote object that this object is a stub for.
Class Method Summary
- 
    
      ._load(s)  
    
    
Unmarshall a marshalled
DRbObject. - 
    
      .new(obj, uri = nil)  ⇒ DRbObject 
    
    constructor
    
Create a new remote object stub.
 - 
    
      .new_with(uri, ref)  
    
    
Creates a
DRbObjectgiven the reference information to the remote host uri and objectref. - 
    
      .new_with_uri(uri)  
    
    
Create a new
DRbObjectfrom a URI alone. - 
    
      .prepare_backtrace(uri, result)  
    
    
Returns a modified backtrace from
resultwith the uri where each call in the backtrace came from. - 
    
      .with_friend(uri)  
    
    
Given the uri of another host executes the block provided.
 
Instance Method Summary
- #==(other) (also: #eql?)
 - 
    
      #__drbref  
    
    
Get the reference of the object, if local.
 - 
    
      #__drburi  
    
    
Get the URI of the remote object.
 - 
    
      #_dump(lv)  
    
    
Marshall this object.
 - 
    
      #eql?(other)  
    
    
Alias for #==.
 - #hash
 - 
    
      #method_missing(msg_id, *a, &b)  
    
    
Routes method calls to the referenced remote object.
 - #pretty_print(q)
 - #pretty_print_cycle(q)
 - 
    
      #respond_to?(msg_id, priv = false)  ⇒ Boolean 
    
    
Routes respond_to? to the referenced remote object.
 
Constructor Details
    .new(obj, uri = nil)  ⇒ DRbObject 
  
Create a new remote object stub.
obj is the (local) object we want to create a stub for.  Normally this is nil.  DRb.uri is the URI of the remote object that this will be a stub for.
# File 'lib/drb/drb.rb', line 1093
def initialize(obj, uri=nil) @uri = nil @ref = nil if obj.nil? return if uri.nil? @uri, option = DRbProtocol.uri_option(uri, DRb.config) @ref = DRbURIOption.new(option) unless option.nil? else @uri = uri ? uri : (DRb.uri rescue nil) @ref = obj ? DRb.to_id(obj) : nil end end
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(msg_id, *a, &b)
Routes method calls to the referenced remote object.
# File 'lib/drb/drb.rb', line 1132
def method_missing(msg_id, *a, &b) if DRb.here?(@uri) obj = DRb.to_obj(@ref) DRb.current_server.check_insecure_method(obj, msg_id) return obj.__send__(msg_id, *a, &b) end succ, result = self.class.with_friend(@uri) do DRbConn.open(@uri) do |conn| conn.(self, msg_id, a, b) end end if succ return result elsif DRbUnknown === result raise result else bt = self.class.prepare_backtrace(@uri, result) result.set_backtrace(bt + caller) raise result end end
Class Method Details
._load(s)
Unmarshall a marshalled DRbObject.
If the referenced object is located within the local server, then the object itself is returned.  Otherwise, a new DRbObject is created to act as a stub for the remote referenced object.
.new_with(uri, ref)
Creates a DRbObject given the reference information to the remote host DRb.uri and object ref.
.new_with_uri(uri)
Create a new DRbObject from a URI alone.
.prepare_backtrace(uri, result)
Returns a modified backtrace from result with the DRb.uri where each call in the backtrace came from.
.with_friend(uri)
Given the DRb.uri of another host executes the block provided.
# File 'lib/drb/drb.rb', line 1157
def self.with_friend(uri) # :nodoc: friend = DRb.fetch_server(uri) return yield() unless friend save = Thread.current['DRb'] Thread.current['DRb'] = { 'server' => friend } return yield ensure Thread.current['DRb'] = save if friend end
Instance Method Details
#==(other) Also known as: #eql?
[ GitHub ]#__drbref
Get the reference of the object, if local.
# File 'lib/drb/drb.rb', line 1112
def __drbref @ref end
#__drburi
Get the URI of the remote object.
# File 'lib/drb/drb.rb', line 1107
def __drburi @uri end
#_dump(lv)
Marshall this object.
The URI and ref of the object are marshalled.
#eql?(other)
Alias for #==.
# File 'lib/drb/eq.rb', line 13
alias eql? ==
#hash
[ GitHub ]# File 'lib/drb/eq.rb', line 9
def hash [@uri, @ref].hash end
#pretty_print(q)
[ GitHub ]# File 'lib/drb/drb.rb', line 1184
def pretty_print(q) # :nodoc: q.pp_object(self) end
#pretty_print_cycle(q)
[ GitHub ]# File 'lib/drb/drb.rb', line 1188
def pretty_print_cycle(q) # :nodoc: q.object_address_group(self) { q.breakable q.text '...' } end
    #respond_to?(msg_id, priv = false)  ⇒ Boolean 
  
Routes respond_to? to the referenced remote object.
# File 'lib/drb/drb.rb', line 1120
def respond_to?(msg_id, priv=false) case msg_id when :_dump true when :marshal_dump false else method_missing(:respond_to?, msg_id, priv) end end