123456789_123456789_123456789_123456789_123456789_

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

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Instance Chain:
self, ActiveSupport::Logger::Severity
Inherits: Object
Defined in: activesupport/lib/active_support/log_subscriber/test_helper.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(level = DEBUG) ⇒ MockLogger

[ GitHub ]

  
# 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

#method_missing(level, message = nil)

[ GitHub ]

  
# 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

#flush_count (readonly)

[ GitHub ]

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

attr_reader :flush_count

#level (rw)

[ GitHub ]

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

attr_accessor :level

Instance Method Details

#flush

[ GitHub ]

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

def flush
  @flush_count += 1
end

#logged(level)

[ GitHub ]

  
# 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