From cdc237897fcb2b8358ac360cbfb75fda05906824 Mon Sep 17 00:00:00 2001 From: Holger Just Date: Wed, 16 May 2018 20:46:59 +0200 Subject: [PATCH] Add a shortcut to enable auto_flush on a Flow with Flow#auto_flush! --- lib/rackstash/flow.rb | 8 ++++++++ spec/rackstash/flow_spec.rb | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/lib/rackstash/flow.rb b/lib/rackstash/flow.rb index 9271122..b5b3611 100644 --- a/lib/rackstash/flow.rb +++ b/lib/rackstash/flow.rb @@ -137,6 +137,14 @@ module Rackstash @auto_flush end + # Enable the {#auto_flush} feature for the current flow. + # + # @return [true] + # @see #auto_flush + def auto_flush! + self.auto_flush = true + end + # @param bool [Bool] `true` to cause buffering Buffers to write their added # messages and fields to the flow as soon as they are logged, `false` to # write the whole event only on an explicit call to {Buffer#flush}. diff --git a/spec/rackstash/flow_spec.rb b/spec/rackstash/flow_spec.rb index 40e561d..5aca13b 100644 --- a/spec/rackstash/flow_spec.rb +++ b/spec/rackstash/flow_spec.rb @@ -113,6 +113,13 @@ RSpec.describe Rackstash::Flow do end end + describe '#auto_flush!' do + it 'enables the auto_flush property' do + flow.auto_flush! + expect(flow.auto_flush?).to eql true + end + end + describe '#close!' do it 'calls adapter#close' do expect(adapter).to receive(:close).and_return(true)