Skip to content

Commit

Permalink
allow symbols for AR async callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
terry committed May 21, 2009
1 parent 60a7b79 commit 6d02819
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/async_observer/extend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,17 @@ def async_each(rcv, selector, *extra)

class << ActiveRecord::Base
HOOKS.each do |hook|
code = %Q{def async_#{hook}(&b) add_async_hook(#{hook.inspect}, b) end}
code = %Q{def async_#{hook}(*methods, &b) add_async_hook(#{hook.inspect}, *methods, &b) end}
class_eval(code, __FILE__, __LINE__ - 1)
end

def add_async_hook(hook, block)
async_hooks[hook] << block
def add_async_hook(hook, *args, &block)
if args && args.first.is_a?(Symbol)
method = args.shift
async_hooks[hook] << lambda{|o| o.send(method)}
else
async_hooks[hook] << block
end
end

def async_hooks
Expand Down

0 comments on commit 6d02819

Please sign in to comment.