class Console::Capture

A general sink which captures all events into a buffer.

Attributes

buffer[R]

Public Class Methods

new() click to toggle source
# File lib/console/capture.rb, line 26
def initialize
        @buffer = []
end

Public Instance Methods

call(subject = nil, *arguments, severity: UNKNOWN, **options) { || ... } click to toggle source
# File lib/console/capture.rb, line 47
def call(subject = nil, *arguments, severity: UNKNOWN, **options, &block)
        message = {
                time: ::Time.now.iso8601,
                severity: severity,
                **options,
        }
        
        if subject
                message[:subject] = subject
        end
        
        if arguments.any?
                message[:arguments] = arguments
        end
        
        if block_given?
                if block.arity.zero?
                        message[:message] = yield
                else
                        buffer = StringIO.new
                        yield buffer
                        message[:message] = buffer.string
                end
        end
        
        @buffer << message
end
clear() click to toggle source
# File lib/console/capture.rb, line 40
def clear
        @buffer.clear
end
include?(pattern) click to toggle source
# File lib/console/capture.rb, line 36
def include?(pattern)
        JSON.dump(@buffer).include?(pattern)
end
last() click to toggle source
# File lib/console/capture.rb, line 32
def last
        @buffer.last
end
verbose!(value = true) click to toggle source
# File lib/console/capture.rb, line 44
def verbose!(value = true)
end