Class: ActiveSupport::LogSubscriber::TestHelper::MockLogger

Inherits:
Object
  • Object
show all
Includes:
Severity
Defined in:
lib/active_support/log_subscriber/test_helper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(level = DEBUG) ⇒ MockLogger

Returns a new instance of MockLogger.



59
60
61
62
63
# File 'lib/active_support/log_subscriber/test_helper.rb', line 59

def initialize(level = DEBUG)
  @flush_count = 0
  @level = level
  @logged = Hash.new { |h,k| h[k] = [] }
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(level, message) ⇒ Object



65
66
67
# File 'lib/active_support/log_subscriber/test_helper.rb', line 65

def method_missing(level, message)
  @logged[level] << message
end

Instance Attribute Details

#flush_countObject (readonly)

Returns the value of attribute flush_count.



56
57
58
# File 'lib/active_support/log_subscriber/test_helper.rb', line 56

def flush_count
  @flush_count
end

#levelObject

Returns the value of attribute level.



57
58
59
# File 'lib/active_support/log_subscriber/test_helper.rb', line 57

def level
  @level
end

Instance Method Details

#flushObject



73
74
75
# File 'lib/active_support/log_subscriber/test_helper.rb', line 73

def flush
  @flush_count += 1
end

#logged(level) ⇒ Object



69
70
71
# File 'lib/active_support/log_subscriber/test_helper.rb', line 69

def logged(level)
  @logged[level].compact.map { |l| l.to_s.strip }
end