Skip to content

Instantly share code, notes, and snippets.

@djwonk
Created September 25, 2008 22:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djwonk/12957 to your computer and use it in GitHub Desktop.
Save djwonk/12957 to your computer and use it in GitHub Desktop.
This is a way to use run_later from Merb in a DataMapper model.
It runs the code in the block at some unspecified point in the
future.
I don't like that I copied and pasted run_later from Merb, but
run_later was defined at the controller level and this seemed
like a quick and easy way to do it.
# Merb's init.rb
# ...
Merb::BootLoader.before_app_loads do
# Add dependencies here that must load before the application loads:
require 'lib/run_later'
end
# ...
# /lib/run_later.rb
module DataMapper
module Resource
def run_later(&blk)
Merb::Dispatcher.work_queue << blk
end
end
end
class TheModel
include DataMapper::Resource
# ...
after :create, :create_hook
def create_hook
run_later do
# ...
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment