Module: DRb::UndumpedIndexedObject

Defined in:
lib/drb/undumped_indexed_object.rb

Class Method Summary collapse

Class Method Details

.append_features(cl) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/drb/undumped_indexed_object.rb', line 16

def UndumpedIndexedObject.append_features(cl)
  super
  cl.module_eval do

    def _dump(depth)
      if self.class.include?(DRb::DRbUndumped)
        raise(TypeError, 'can\'t dump')
      end
      attribs = {}
      each_pair do |k, v|
        begin
          attribs[k] = Marshal.dump(v)
        rescue TypeError
          if (defined? LOG) and (not v.class.include? DRb::DRbUndumped)
            LOG.warn("#{self.class}._dump") do
              "can't dump a #{k}:#{v.class}"
            end
          end
          attribs[k] = Marshal.dump(DRbObject.new(v))
        end
      end
      Marshal.dump([self.class, attribs])
    end

    def self._load(data)
      klass, attribs = Marshal.load(data)
      obj = klass.new
      attribs.each do |key, value|
        obj[key] = Marshal.load(value)
      end
      obj
    end
  end

end