Module: Log::FakeIO

Included in:
File, Forward
Defined in:
lib/log/fakeio.rb

Overview

Description

Fakes most IO methods and forwards the converted data to #process

Requisites

  • @buffer initialized to “”

  • #process method present (this should write to the storage)

  • #convert method present (see Log::Converter)

Notes

Following methods might be useful to be implemented:

binmode, fcntl, fileno, flush, fsync, isatty, lineno, lineno=, pid, pos,
pos=, , scanf, seek, soak_up_spaces, stat, sync, sync=, sysread, tell, to_i,
to_io, tty?

Following write methods are NOT implemented:

puts, syswrite, write_nonblock

All read methods must be implemented by the including class

Instance Method Summary collapse

Instance Method Details

#<<(obj) ⇒ Object



36
37
38
# File 'lib/log/fakeio.rb', line 36

def <<(obj)
	process(convert(obj))
end

#printf(*args) ⇒ Object



50
51
52
53
# File 'lib/log/fakeio.rb', line 50

def printf(*args)
	@buffer << sprintf(*args)
	process_buffer
end

#process_bufferObject



30
31
32
33
34
# File 'lib/log/fakeio.rb', line 30

def process_buffer
	while line = @buffer.slice!(/.*?\n/)
		process(convert(line))
	end
end

#puts(*objs) ⇒ Object



40
41
42
# File 'lib/log/fakeio.rb', line 40

def puts(*objs)
	objs.each { |obj| process(convert(obj)) }
end

#write(*objs) ⇒ Object Also known as: print



44
45
46
47
# File 'lib/log/fakeio.rb', line 44

def write(*objs)
	@buffer << objs.join("")
	process_buffer
end