Created
September 25, 2008 22:07
-
-
Save djwonk/12957 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
# ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /lib/run_later.rb | |
module DataMapper | |
module Resource | |
def run_later(&blk) | |
Merb::Dispatcher.work_queue << blk | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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