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)


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

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)


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

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)


33
34
35
# File 'lib/dizby/stream/writable.rb', line 33

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

#write(data)


6
7
8
# File 'lib/dizby/stream/writable.rb', line 6

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