Skip to content

Commit

Permalink
add support to pass lambda's to fires for subject, secondary_subjec…
Browse files Browse the repository at this point in the history
…t and actor.
  • Loading branch information
Christoph Schiessl committed Jun 23, 2011
1 parent 476d60d commit 8537ffd
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 8537ffd

Please sign in to comment.