diff --git a/lib/timeline_fu/fires.rb b/lib/timeline_fu/fires.rb index f4c224e..2bf71c3 100644 --- a/lib/timeline_fu/fires.rb +++ b/lib/timeline_fu/fires.rb @@ -19,11 +19,14 @@ def fires(event_type, opts) method_name = :"fire_#{event_type}_after_#{opts[:on]}" define_method(method_name) do create_options = [:actor, :subject, :secondary_subject].inject({}) do |memo, sym| - case opts[sym] - when :self - memo[sym] = self - else - memo[sym] = send(opts[sym]) if opts[sym] + if opts[sym] + if opts[sym].respond_to?(:call) + memo[sym] = opts[sym].call(self) + elsif opts[sym] == :self + memo[sym] = self + else + memo[sym] = send(opts[sym]) + end end memo end diff --git a/test/test_helper.rb b/test/test_helper.rb index 8db95f4..4312d2e 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -33,7 +33,7 @@ class Person < ActiveRecord::Base attr_accessor :new_watcher, :fire fires :follow_created, :on => :update, - :actor => :new_watcher, + :actor => lambda { |person| person.new_watcher }, :if => lambda { |person| !person.new_watcher.nil? } fires :person_updated, :on => :update, :if => :fire?