class Sawmill::EntryProcessor::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 entries to STDOUT only if their level is at least INFO:

processor = Sawmill::EntryProcessor.build do
  If(FilterByBasicFields(:level => :INFO), 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 entry should be accepted. The second parameter is a processor to run on accepted entries. The optional third parameter is an “else” processor to run on rejected entries.

# File lib/sawmill/entry_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

attribute(entry_) click to toggle source
# File lib/sawmill/entry_processor/conditionals.rb, line 95
def attribute(entry_)
  if @condition.attribute(entry_)
    @on_true.attribute(entry_)
  elsif @on_false
    @on_false.attribute(entry_)
  end
end
begin_record(entry_) click to toggle source
# File lib/sawmill/entry_processor/conditionals.rb, line 71
def begin_record(entry_)
  if @condition.begin_record(entry_)
    @on_true.begin_record(entry_)
  elsif @on_false
    @on_false.begin_record(entry_)
  end
end
end_record(entry_) click to toggle source
# File lib/sawmill/entry_processor/conditionals.rb, line 79
def end_record(entry_)
  if @condition.end_record(entry_)
    @on_true.end_record(entry_)
  elsif @on_false
    @on_false.end_record(entry_)
  end
end
finish() click to toggle source
# File lib/sawmill/entry_processor/conditionals.rb, line 111
def finish
  Util::ProcessorTools.collect_finish_values([@on_true, @on_false])
end
message(entry_) click to toggle source
# File lib/sawmill/entry_processor/conditionals.rb, line 87
def message(entry_)
  if @condition.message(entry_)
    @on_true.message(entry_)
  elsif @on_false
    @on_false.message(entry_)
  end
end
unknown_data(entry_) click to toggle source
# File lib/sawmill/entry_processor/conditionals.rb, line 103
def unknown_data(entry_)
  if @condition.unknown_data(entry_)
    @on_true.unknown_data(entry_)
  elsif @on_false
    @on_false.unknown_data(entry_)
  end
end