Class: Console::Capture
- Inherits:
-
Object
- Object
- Console::Capture
- Defined in:
- lib/console/capture.rb
Overview
A general sink which captures all events into a buffer.
Instance Attribute Summary collapse
-
#buffer ⇒ Object
readonly
Returns the value of attribute buffer.
Instance Method Summary collapse
- #call(subject = nil, *arguments, severity: UNKNOWN, **options, &block) ⇒ Object
- #clear ⇒ Object
- #include?(pattern) ⇒ Boolean
-
#initialize ⇒ Capture
constructor
A new instance of Capture.
- #last ⇒ Object
- #verbose!(value = true) ⇒ Object
Constructor Details
#initialize ⇒ Capture
Returns a new instance of Capture.
28 29 30 |
# File 'lib/console/capture.rb', line 28 def initialize @buffer = [] end |
Instance Attribute Details
#buffer ⇒ Object (readonly)
Returns the value of attribute buffer.
32 33 34 |
# File 'lib/console/capture.rb', line 32 def buffer @buffer end |
Instance Method Details
#call(subject = nil, *arguments, severity: UNKNOWN, **options, &block) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/console/capture.rb', line 49 def call(subject = nil, *arguments, severity: UNKNOWN, **, &block) = { time: ::Time.now.iso8601, severity: severity, **, } if subject [:subject] = subject end if arguments.any? [:arguments] = arguments end if block_given? if block.arity.zero? [:message] = yield else buffer = StringIO.new yield buffer [:message] = buffer.string end end @buffer << end |
#clear ⇒ Object
42 43 44 |
# File 'lib/console/capture.rb', line 42 def clear @buffer.clear end |
#include?(pattern) ⇒ Boolean
38 39 40 |
# File 'lib/console/capture.rb', line 38 def include?(pattern) JSON.dump(@buffer).include?(pattern) end |
#last ⇒ Object
34 35 36 |
# File 'lib/console/capture.rb', line 34 def last @buffer.last end |
#verbose!(value = true) ⇒ Object
46 47 |
# File 'lib/console/capture.rb', line 46 def verbose!(value = true) end |