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

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

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (MockLogger) initialize(level = DEBUG)

Returns a new instance of MockLogger



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

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

- (Object) method_missing(level, message = nil)



64
65
66
67
68
69
70
# File 'activesupport/lib/active_support/log_subscriber/test_helper.rb', line 64

def method_missing(level, message = nil)
   if block_given?
     @logged[level] << yield
   else
     @logged[level] << message
   end
end

Instance Attribute Details

- (Object) flush_count (readonly)

Returns the value of attribute flush_count



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

def flush_count
  @flush_count
end

- (Object) level

Returns the value of attribute level



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

def level
  @level
end

Instance Method Details

- (Object) flush



76
77
78
# File 'activesupport/lib/active_support/log_subscriber/test_helper.rb', line 76

def flush
  @flush_count += 1
end

- (Object) logged(level)



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

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