class Sawmill::RecordProcessor::If

An “if” conditional.

Takes a boolean condition processor and executes a processor on true (and optionally another one on false).

For example, this builds a processor that sends formatted log records to STDOUT only if they have a “user” attribute of “daniel”:

processor = Sawmill::RecordProcessor.build do
  If(FilterByAttributes('user' => 'daniel'), Format(STDOUT))
end

Public Class Methods

new(condition_, on_true_, on_false_=nil) click to toggle source

Create an “if” conditional.

The first parameter must be a processor whose methods return a boolean value indicating whether the record should be accepted. The second parameter is a processor to run on accepted records. The optional third parameter is an “else” processor to run on rejected records.

# File lib/sawmill/record_processor/conditionals.rb, line 65
def initialize(condition_, on_true_, on_false_=nil)
  @condition = condition_
  @on_true = on_true_
  @on_false = on_false_
end

Public Instance Methods

extra_entry(entry_) click to toggle source
# File lib/sawmill/record_processor/conditionals.rb, line 79
def extra_entry(entry_)
  if @condition.extra_entry(entry_)
    @on_true.extra_entry(entry_)
  elsif @on_false
    @on_false.extra_entry(entry_)
  end
end
finish() click to toggle source
# File lib/sawmill/record_processor/conditionals.rb, line 87
def finish
  Util::ProcessorTools.collect_finish_values([@on_true, @on_false])
end
record(record_) click to toggle source
# File lib/sawmill/record_processor/conditionals.rb, line 71
def record(record_)
  if @condition.record(record_)
    @on_true.record(record_)
  elsif @on_false
    @on_false.record(record_)
  end
end