Class: ODBA::DRbWrapper

Inherits:
Object show all
Includes:
DRb::DRbUndumped
Defined in:
lib/odba/drbwrapper.rb

Instance Method Summary collapse

Constructor Details

#initialize(obj) ⇒ DRbWrapper

Returns a new instance of DRbWrapper.



16
17
18
# File 'lib/odba/drbwrapper.rb', line 16

def initialize(obj)
  @obj = obj
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/odba/drbwrapper.rb', line 24

def method_missing(sym, *args)
  if block_given?
    res = @obj.__send__(sym, *args) { |*block_args|
      yield(*block_args.collect { |arg| __wrap(arg) })
    }
    __wrap(res)
  else
    res = @obj.__send__(sym, *args)
    if res.is_a?(Array)
      res.collect { |item| __wrap(item) }
    elsif res.is_a?(Hash)
      res.each_with_object({}) { |(key, value), memo|
        memo.store(__wrap(key), __wrap(value))
      }
    else
      __wrap(res)
    end
  end
end

Instance Method Details

#__wrap(obj) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/odba/drbwrapper.rb', line 44

def __wrap(obj)
  if obj.is_a?(ODBA::Persistable)
    DRbWrapper.new(obj.odba_instance)
  else
    obj
  end
end

#__wrappeeObject



52
53
54
# File 'lib/odba/drbwrapper.rb', line 52

def __wrappee
  @obj
end

#respond_to?(sym, *args) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/odba/drbwrapper.rb', line 20

def respond_to?(sym, *args)
  super || @obj.respond_to?(sym, *args)
end