Method: Refile.processor

Defined in:
lib/refile.rb

.processor(name, processor = nil) {|Refile::File| ... }

This method returns an undefined value.

Adds a processor. The processor must respond to call, both receiving and returning an IO-like object. Alternatively a block can be given to this method which also receives and returns an IO-like object.

An IO-like object is recommended to be an instance of the IO class or one of its subclasses, like File or a StringIO, or a Refile::File. It can also be any other object which responds to size, read, eof? and close and mimics the behaviour of IO objects for these methods.

Examples:

With processor class

class Reverse
  def call(file)
    StringIO.new(file.read.reverse)
  en
end
Refile.processor(:reverse, Reverse)

With block

Refile.processor(:reverse) do |file|
  StringIO.new(file.read.reverse)
end

Parameters:

  • name (#to_s)

    The name of the processor

  • processor (Proc, nil) (defaults to: nil)

    The processor, must respond to call and.

Yields:

Yield Returns:

  • (IO)

    An IO-like object representing the processed file



129
130
131
132
# File 'lib/refile.rb', line 129

def processor(name, processor = nil, &block)
  processor ||= block
  processors[name.to_s] = processor
end