Class: Epilog::MockLogger

Inherits:
Logger
  • Object
show all
Defined in:
lib/epilog/mock_logger.rb

Instance Method Summary collapse

Constructor Details

#initializeMockLogger

Returns a new instance of MockLogger.



5
6
7
8
# File 'lib/epilog/mock_logger.rb', line 5

def initialize
  super(nil)
  reset
end

Instance Method Details

#[](index) ⇒ Object



33
34
35
# File 'lib/epilog/mock_logger.rb', line 33

def [](index)
  @logs[index].dup || []
end

#add(severity, message = nil, progname = nil) ⇒ Object Also known as: log

rubocop:disable MethodLength



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/epilog/mock_logger.rb', line 11

def add(severity, message = nil, progname = nil)
  severity ||= Logger::UNKNOWN
  return true if severity < level

  prog ||= progname
  if message.nil?
    if block_given?
      message = yield
    else
      message = prog
      prog = progname
    end
  end

  write(format_severity(severity), current_time, prog, message)
end

#freeze_time(time) ⇒ Object



41
42
43
# File 'lib/epilog/mock_logger.rb', line 41

def freeze_time(time)
  @time = time
end

#reopen(_logdev = nil) ⇒ Object



30
31
# File 'lib/epilog/mock_logger.rb', line 30

def reopen(_logdev = nil)
end

#resetObject



45
46
47
# File 'lib/epilog/mock_logger.rb', line 45

def reset
  @logs = []
end

#to_aObject



37
38
39
# File 'lib/epilog/mock_logger.rb', line 37

def to_a
  (0...@logs.size).map { |i| self[i] }
end