class Sawmill::RecordProcessor::Base

A base class for record processors.

Record 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 RecordProcessor namespace, then it will automatically be available in the build interface. See RecordProcessor#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 record processor. You must pass a method name that begins with a lower-case letter or underscore.

Processors that subclass Sawmill::RecordProcessor::Base and live in the Sawmill::RecordProcessor 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::RecordProcessor#build for more information.

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

# File lib/sawmill/record_processor.rb, line 139
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

extra_entry(entry_) click to toggle source

Receive and process an entry that falls outside a record.

# File lib/sawmill/record_processor.rb, line 80
def extra_entry(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/record_processor.rb, line 107
def finish
  nil
end
record(record_) click to toggle source

Receive and process a Sawmill::Record.

# File lib/sawmill/record_processor.rb, line 73
def record(record_)
  true
end