Class: ActiveSupport::LogSubscriber::TestHelper::MockLogger
- Includes:
- ActiveSupport::Logger::Severity
- Defined in:
- activesupport/lib/active_support/log_subscriber/test_helper.rb
Instance Attribute Summary collapse
-
#flush_count ⇒ Object
readonly
Returns the value of attribute flush_count.
-
#level ⇒ Object
Returns the value of attribute level.
Instance Method Summary collapse
- #flush ⇒ Object
-
#initialize(level = DEBUG) ⇒ MockLogger
constructor
A new instance of MockLogger.
- #logged(level) ⇒ Object
- #method_missing(level, message = nil) ⇒ Object
Constructor Details
#initialize(level = DEBUG) ⇒ MockLogger
Returns a new instance of MockLogger.
60 61 62 63 64 |
# File 'activesupport/lib/active_support/log_subscriber/test_helper.rb', line 60 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) ⇒ Object
66 67 68 69 70 71 72 |
# File 'activesupport/lib/active_support/log_subscriber/test_helper.rb', line 66 def method_missing(level, = nil) if block_given? @logged[level] << yield else @logged[level] << end end |
Instance Attribute Details
#flush_count ⇒ Object (readonly)
Returns the value of attribute flush_count
57 58 59 |
# File 'activesupport/lib/active_support/log_subscriber/test_helper.rb', line 57 def flush_count @flush_count end |
#level ⇒ Object
Returns the value of attribute level
58 59 60 |
# File 'activesupport/lib/active_support/log_subscriber/test_helper.rb', line 58 def level @level end |
Instance Method Details
#flush ⇒ Object
78 79 80 |
# File 'activesupport/lib/active_support/log_subscriber/test_helper.rb', line 78 def flush @flush_count += 1 end |
#logged(level) ⇒ Object
74 75 76 |
# File 'activesupport/lib/active_support/log_subscriber/test_helper.rb', line 74 def logged(level) @logged[level].compact.map { |l| l.to_s.strip } end |