Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
66 lines (44 sloc) 1.6 KB

DataMapper Async

An optionally-asynchronous special case for Ruby on Rails models, backed by DataMapper.


To use dm-async in one of your resource, simply include DataMapper::Asynchronous::Resource instead of DataMapper::Resource:

 class MyModel
   include DataMapper::Asynchronous::Resource
   # ... your model here


Adding callbacks

dm-async is simple:

mine =
mine.after { |objects| 
  # `Objects` is an array of the asynchronously-loaded records.

The after command adds a block of code that will be called after the data is loaded asynchronously.

Or, if you want to add it after a specific stage (update, delete, validate, etc):

mine =
mine.after_delete { |objects| 
  # `Objects` is an array of the asynchronously-loaded records.

# after_delete's code will execute here.

Providing for callbacks params

Include a module in your code that defines the methods outlined in DataMapper::Asynchronous::RemoteHandlers.

# Handler
module MyHandler
  def remote_after_save

# Model
class Model
  include DataMapper::Asynchronous::Resource
  include MyHandler      

Special note on server configuration

The server will pass along all ordering information from Datamapper. You should expect a params-array of order_by[] values, separated by a (URL-encoded) colon: