Class: Log::File

Inherits:
Object
  • Object
show all
Includes:
Converter, FakeIO, Methods
Defined in:
lib/log/file.rb

Instance Method Summary collapse

Methods included from Methods

#debug, #error, #fail, #info, #log, #warn

Methods included from FakeIO

#<<, #printf, #process_buffer, #puts, #write

Constructor Details

#initialize(out) ⇒ File

Returns a new instance of File.



26
27
28
29
30
31
# File 'lib/log/file.rb', line 26

def initialize(out)
  @out          = nil
  @default_type = :error
  @buffer       = ""
  reopen(out)
end

Instance Method Details

#closeObject



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

def close
  @out.close if @out.respond_to?(:close)
  self
end

#closed?Boolean

Returns:

  • (Boolean)


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

def closed?
  @out.respond_to?(:close) ? @out.closed? : true
end

#process(obj) ⇒ Object



33
34
35
36
# File 'lib/log/file.rb', line 33

def process(obj)
  @out.puts(obj.serialize)
  @out.flush
end

#reopen(out) ⇒ Object

Raises:

  • (TypeError)


38
39
40
41
42
43
# File 'lib/log/file.rb', line 38

def reopen(out)
  close
  @out = out.respond_to?(:to_str) ? ::File.open(out, "a") : out
  raise TypeError, "out #{@out} does not respond to 'puts'." unless @out.respond_to?(:puts)
  self
end