class Sawmill::EntryProcessor::Base

A base class for entry processors.

Entry processors need not necessarily subclass this class, but should at least duck-type the methods.

If a class subclasses this class, and lives in the EntryProcessor namespace, then it will automatically be available in the build interface. See EntryProcessor#build.

Public Class Methods

add_dsl_method(name_) click to toggle source

Add a method to the processor building DSL. You may call this method in the DSL to create an instance of this entry processor. You must pass a method name that begins with a lower-case letter or underscore.

Processors that subclass Sawmill::EntryProcessor::Base and live in the Sawmill::EntryProcessor namespace will have their class name automatically added to the DSL. This method is primarily for other processors that do not live in that module namespace.

See Sawmill::EntryProcessor#build for more information.

Raises Sawmill::Errors::DSLMethodError if the given name is already taken.

# File lib/sawmill/entry_processor.rb, line 160
def self.add_dsl_method(name_)
  klass_ = self
  if name_.to_s !~ %r^[a-z_]/
    raise ::ArgumentError, "Method name must begin with a lower-case letter or underscore"
  end
  if Builder.method_defined?(name_)
    raise Errors::DSLMethodError, "Method #{name_} already defined"
  end
  Builder.class_eval do
    define_method(name_) do |*args_|
      klass_.new(*args_)
    end
  end
end

Public Instance Methods

attribute(entry_) click to toggle source

Receive and process a Sawmill::Entry::Attribute.

# File lib/sawmill/entry_processor.rb, line 94
def attribute(entry_)
  true
end
begin_record(entry_) click to toggle source

Receive and process a Sawmill::Entry::BeginRecord.

# File lib/sawmill/entry_processor.rb, line 73
def begin_record(entry_)
  true
end
end_record(entry_) click to toggle source

Receive and process a Sawmill::Entry::EndRecord.

# File lib/sawmill/entry_processor.rb, line 80
def end_record(entry_)
  true
end
finish() click to toggle source

Close down the processor, perform any finishing tasks, and return any final calculated value.

After this is called, the processor should ignore any further entries.

The return value can be used to communicate a final computed value, analysis report, or other data back to the caller. It may also be nil, signalling no finish value.

Note that some processors function to multiplex other processors. In such a case, their finish value needs to be an aggregate of the values returned by their descendants. To handle these cases, we define a protocol for finish values. A finish value may be nil, an Array, or another kind of object. Nil means “no value” and thus can be ignored by a processor that aggregates other values. An Array indicates an aggregation; if finish returns an array, it is always an aggregation of actual values. Any other kind of object is to be interpreted as a single value. This means that if you want to actually return an array as a value, you must wrap it in another array, indicating “an array of one finish value, and that finish value also happens to be an array itself”.

# File lib/sawmill/entry_processor.rb, line 128
def finish
  nil
end
message(entry_) click to toggle source

Receive and process a Sawmill::Entry::Message.

# File lib/sawmill/entry_processor.rb, line 87
def message(entry_)
  true
end
unknown_data(entry_) click to toggle source

Receive and process a Sawmill::Entry::UnknownData.

# File lib/sawmill/entry_processor.rb, line 101
def unknown_data(entry_)
  true
end