Class: CommandSerializer

Inherits:
Object
  • Object
show all
Defined in:
lib/internal/command_logger.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(io, marshaler) ⇒ CommandSerializer

Returns a new instance of CommandSerializer.



3
4
5
6
7
# File 'lib/internal/command_logger.rb', line 3

def initialize( io, marshaler )
  raise 'Invalid stream' if io.nil? 
  @io, @marshaler = io, marshaler
  @io.binmode
end

Class Method Details

.restore_from_io(io, system, marshaler) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/internal/command_logger.rb', line 16

def self.restore_from_io( io, system, marshaler )
#    Theorically this should work and its more elegant than the current version
#    Marshal.load( io ) { |command|
#      command.execute( system )
#    }
  while( !io.eof? ) 
    command = marshaler.restore( io )
    command.execute( system )
  end
end

Instance Method Details

#<<(command) ⇒ Object



9
10
11
12
13
14
# File 'lib/internal/command_logger.rb', line 9

def <<(command)
  raise 'Invalid command' if command.nil? 
  @marshaler.serialize_to_stream( command, @io )
  @io.flush
  @io.fsync
end

#closeObject



27
28
29
# File 'lib/internal/command_logger.rb', line 27

def close
  @io.close
end