Module: RecordLoader::Adapter

Defined in:
lib/record_loader/adapter.rb,
lib/record_loader/adapter/basic.rb,
lib/record_loader/adapter/rails.rb

Overview

Adapters provide a means of wrapping various framework methods in order to use RecordLoader outside of Rails and ActiveRecord.

Existing Adapters

There are currently two adapters available

A simple general purpose adapter which provides no support for transactions and only basic logging.

An adapter designed for use with Rails applications. Automatically wraps Base.create! in an active record transaction, and directs logging to the configure rails logger.

Custom Adapters

It is possible to create custom adapters to use with your own frameworks. It is suggested that you inherit from Basic to provide forward compatibility with future versions of RecordLoader.

Custom adapters should support three instance methods:

  • transaction(&block)

Wraps the Base.create! and allows you to handle transactional rollbacks in the event that something goes wrong. This method recieves a block and should be yielded to to generate the records.

  • logger

Should return a logger object which impliments: debug, info, warn, error, fatal methods

  • development?

Returns true if we are running in development mode.

Examples:

my_adapter.rb

class MyAdapter < RecordLoader::Adapter::Basic
  def transaction
    Database.open_transaction
    yield
    Database.commit_transaction
  rescue StandardError
    Database.abort_transaction
  end

  def logger
    DistributedLoggingSystem.logger
  end
end

application_record_loader.rb

class ApplicationRecordLoader
  adapter MyAdapter.new
end

Defined Under Namespace

Classes: Basic, Rails