Module: Unbreakable::Processors

Defined in:
lib/unbreakable/processors/transform.rb,
lib/unbreakable.rb

Overview

Processors are Dragonfly processors. For example:

class MyProcessor
  def coolify(temp_object, opts = {})
    SomeLib.coolify(temp_object.data, opts)
  end

  def uglify(temp_object, ugliness)
    `uglify -i #{temp_object.path} -u #{ugliness}`
  end

  def conditional(temp_object, format, pages)
    throw :unable_to_handle unless format == :pdf
    # do stuff
  end

private

  def my_helper_method
    # do stuff
  end
end
MyScraper.processor.register MyProcessor

Public methods must return an object with which a TempObject may be initialized (String, File, Tempfile, Pathname or TempObject).

You can raise Dragonfly::Configurable::NotConfigured if a configurable variable is required but missing. If a variable is invalid, you can raise Dragonfly::Configurable::InvalidConfiguration.

If a process has dependencies or conditions, then you can test for these conditions and throw :unable_to_handle to skip processing.

If multiple processors define a public method by the same name, the methods will be run in reverse order from the last processor to define the method until one fails to throw :unable_to_handle. If all raise an error, then Dragonfly::FunctionManager::UnableToHandle will be thrown.

As such, if you are writing a document to plain-text converter, you can write a pdftotext processor, a doctopdf processor, etc. which all define a to_text public method, and use :unable_to_handle to make sure the correct processor runs.

Defined Under Namespace

Classes: Transform