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



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

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

#printf(*args) ⇒ Object



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

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

#process_bufferObject



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

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

#puts(*objs) ⇒ Object



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

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

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



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

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