mirror of
https://github.com/meineerde/rackstash.git
synced 2026-04-05 06:31:38 +00:00
Add Rackstash::Buffer#clear to clear all data in a buffer
This commit is contained in:
parent
4db9fd7166
commit
5e37df77e5
@ -60,6 +60,19 @@ module Rackstash
|
|||||||
@allow_empty
|
@allow_empty
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Clear the current buffer from all stored data, just as it was right after
|
||||||
|
# inititialization.
|
||||||
|
#
|
||||||
|
# @return [self]
|
||||||
|
def clear
|
||||||
|
@messages.clear
|
||||||
|
@fields.clear
|
||||||
|
@tags.clear
|
||||||
|
@timestamp = nil
|
||||||
|
|
||||||
|
self
|
||||||
|
end
|
||||||
|
|
||||||
# Return all logged messages on the current buffer.
|
# Return all logged messages on the current buffer.
|
||||||
#
|
#
|
||||||
# @return [Array<Message>] the list of messages of the curent buffer
|
# @return [Array<Message>] the list of messages of the curent buffer
|
||||||
|
|||||||
@ -34,6 +34,42 @@ describe Rackstash::Buffer do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#clear' do
|
||||||
|
it 'removes all fields and tags' do
|
||||||
|
buffer.fields['foo'] = 'bar'
|
||||||
|
buffer.tag 'super_important'
|
||||||
|
|
||||||
|
buffer.clear
|
||||||
|
expect(buffer.tags).to be_empty
|
||||||
|
expect(buffer.fields).to be_empty
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'clears the message buffer' do
|
||||||
|
buffer.add_message double(message: 'Hello World!', time: Time.now)
|
||||||
|
buffer.clear
|
||||||
|
|
||||||
|
expect(buffer.messages).to eql []
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'removes the pending flag' do
|
||||||
|
buffer.add_message double(message: 'raw', time: Time.now)
|
||||||
|
|
||||||
|
expect(buffer.pending?).to be true
|
||||||
|
buffer.clear
|
||||||
|
expect(buffer.pending?).to be false
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'resets the timestamp' do
|
||||||
|
buffer.timestamp(Time.parse('2016-10-17 15:37:00 +02:00'))
|
||||||
|
expect(buffer.timestamp).to eql '2016-10-17T13:37:00.000Z'
|
||||||
|
|
||||||
|
buffer.clear
|
||||||
|
|
||||||
|
expect(Time).to receive(:now).and_call_original
|
||||||
|
expect(buffer.timestamp).not_to eql '2016-10-17T13:37:00.000Z'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe '#fields' do
|
describe '#fields' do
|
||||||
it 'returns a Rackstash::Fields::Hash' do
|
it 'returns a Rackstash::Fields::Hash' do
|
||||||
expect(buffer.fields).to be_a Rackstash::Fields::Hash
|
expect(buffer.fields).to be_a Rackstash::Fields::Hash
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user