From 40e151ecb8ed30bae9a3569539d4ba0e835a629f Mon Sep 17 00:00:00 2001 From: Holger Just Date: Wed, 20 Dec 2017 18:36:57 +0100 Subject: [PATCH] Rename the SkipEvent filter to DropIf to make the intention clearer --- lib/rackstash/filter.rb | 2 +- .../filter/{skip_event.rb => drop_if.rb} | 26 ++++++++++--------- .../{skip_event_spec.rb => drop_if_spec.rb} | 6 ++--- 3 files changed, 18 insertions(+), 16 deletions(-) rename lib/rackstash/filter/{skip_event.rb => drop_if.rb} (63%) rename spec/rackstash/filter/{skip_event_spec.rb => drop_if_spec.rb} (90%) diff --git a/lib/rackstash/filter.rb b/lib/rackstash/filter.rb index d45ff63..f8f515a 100644 --- a/lib/rackstash/filter.rb +++ b/lib/rackstash/filter.rb @@ -8,9 +8,9 @@ require 'rackstash/filter/clear_color' require 'rackstash/filter/default_fields' require 'rackstash/filter/default_tags' +require 'rackstash/filter/drop_if' require 'rackstash/filter/rename' require 'rackstash/filter/replace' -require 'rackstash/filter/skip_event' require 'rackstash/filter/truncate_message' module Rackstash diff --git a/lib/rackstash/filter/skip_event.rb b/lib/rackstash/filter/drop_if.rb similarity index 63% rename from lib/rackstash/filter/skip_event.rb rename to lib/rackstash/filter/drop_if.rb index c846d68..555c673 100644 --- a/lib/rackstash/filter/skip_event.rb +++ b/lib/rackstash/filter/drop_if.rb @@ -7,38 +7,40 @@ module Rackstash module Filter - # Skip the further processing of the event of the condition is `true`. + # Skip the further processing of the event if the provided condition is + # truethy. In that case, the event will be dropped and not be written to the + # log adapter. # # This filter is a basic example of how you can write filters which abort # further processing of an event. You can write your own filters which # provide similar (but probably more useful) behavior. - class SkipEvent - # @param skip_if [#call] a callable object (e.g. a `Proc`) which returns a + class DropIf + # @param drop_if [#call] a callable object (e.g. a `Proc`) which returns a # truethy or falsey value on `call` with an `event` hash. If it returns # something truethy, we abort any further processing of the event. If the - # `skip_if` filter is not given, we expect a block to be provided which + # `drop_if` filter is not given, we expect a block to be provided which # is used instead. - def initialize(skip_if = nil, &block) - if skip_if.respond_to?(:call) - @skip_if = skip_if + def initialize(drop_if = nil, &block) + if drop_if.respond_to?(:call) + @drop_if = drop_if elsif block_given? - @skip_if = block + @drop_if = block else - raise TypeError, 'must provide a skip condition' + raise ArgumentError, 'must provide a condition when to drop the event' end end # Run the filter against the passed `event` hash. # - # We fill call the `skip_if` object with the passed event. If the return + # We will call the `drop_if` object with the passed event. If the return # value is truethy, we abort any further processing of the event. This # filter does not change the `event` hash in any way on its own. # # @param event [Hash] an event hash - # @return [Hash, false] the given `event` or `false` if the `skip_if` + # @return [Hash, false] the given `event` or `false` if the `drop_if` # condition was evaluated def call(event) - return false if @skip_if.call(event) + return false if @drop_if.call(event) event end end diff --git a/spec/rackstash/filter/skip_event_spec.rb b/spec/rackstash/filter/drop_if_spec.rb similarity index 90% rename from spec/rackstash/filter/skip_event_spec.rb rename to spec/rackstash/filter/drop_if_spec.rb index ab6cdc5..311073e 100644 --- a/spec/rackstash/filter/skip_event_spec.rb +++ b/spec/rackstash/filter/drop_if_spec.rb @@ -7,12 +7,12 @@ require 'spec_helper' -require 'rackstash/filter/skip_event' +require 'rackstash/filter/drop_if' -describe Rackstash::Filter::SkipEvent do +describe Rackstash::Filter::DropIf do describe '#initialize' do it 'expects a condition' do - expect { described_class.new }.to raise_error TypeError + expect { described_class.new }.to raise_error ArgumentError end it 'accepts a callable object' do