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
51
|
# File 'lib/drb/undumped_attributes.rb', line 16
def UndumpedAttributes.append_features(cl)
super
cl.module_eval do
def _dump(depth)
if self.class.include?(DRb::DRbUndumped)
raise(TypeError, 'can\'t dump')
end
attribs = {}
instance_variables.each do |attr|
obj = instance_variable_get(attr)
begin
attribs[attr] = Marshal.dump(obj)
rescue TypeError
if (defined? LOG) and (not obj.class.include? DRb::DRbUndumped)
LOG.warn("#{self.class}._dump") do
"can't dump a #{attr}:#{obj.class}"
end
end
attribs[attr] = Marshal.dump(DRbObject.new(obj))
end
end
Marshal.dump([self.class, attribs])
end
def self._load(data)
klass, attribs = Marshal.load(data)
obj = klass.new
attribs.each do |attr, value|
obj.instance_variable_set(attr, Marshal.load(value))
end
obj
end
end
end
|