Module: Dizby::WritableStream

Included in:
Messenger
Defined in:
lib/dizby/stream/writable.rb

Instance Method Summary collapse

Instance Method Details

#dump_data(obj, error = false)


12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/dizby/stream/writable.rb', line 12

def dump_data(obj, error = false)
  @server.log.debug("dumping: #{obj.inspect}")

  if obj.is_a?(UndumpableObject)
    @server.log.debug('dumping undumpable')
    obj = make_distributed(obj, error)
  end

  str = dump_obj(obj, error)
  @server.log.debug("dumped: #{str.inspect}")

  [str.size].pack('N') + str
end

#dump_obj(obj, error) (private)


28
29
30
31
32
33
# File 'lib/dizby/stream/writable.rb', line 28

def dump_obj(obj, error)
  Marshal.dump(obj)
rescue
  @server.log.debug('rescuing and dumping pseudo-undumpable...')
  Marshal.dump(make_distributed(obj, error))
end

#make_distributed(obj, error) (private)


35
36
37
# File 'lib/dizby/stream/writable.rb', line 35

def make_distributed(obj, error)
  @server.make_distributed(obj, error)
end

#write(data)


8
9
10
# File 'lib/dizby/stream/writable.rb', line 8

def write(data)
  @stream.write(data)
end