Skip to content

Commit

Permalink
Merge pull request jamesgolick#4 from cs/master
Browse files Browse the repository at this point in the history
Support for passing lambdas to `fires` as :actor, :secondary_subject and :subject
  • Loading branch information
francois committed Jun 23, 2011
2 parents 476d60d + 8537ffd commit 1472e5f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 8 additions & 5 deletions lib/timeline_fu/fires.rb
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/test_helper.rb
Expand Up @@ -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?
Expand Down

0 comments on commit 1472e5f

Please sign in to comment.