Skip to content

Commit

Permalink
subscribe to multiple events, each subscription with its own handler …
Browse files Browse the repository at this point in the history
…identifier #13
  • Loading branch information
Paco Guzman committed Nov 18, 2011
1 parent 0ea43c3 commit 68b8d62
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 4 additions & 2 deletions lib/eventwire/subscriber.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ def self.included(base)
end

module DSL
def on(event_name, &handler)
Eventwire.subscribe event_name, "#{name}::#{increment_handler_counter}", &handler
def on(*event_names, &handler)
event_names.each do |event_name|
Eventwire.subscribe event_name, "#{name}::#{increment_handler_counter}", &handler
end
end

private
Expand Down
8 changes: 7 additions & 1 deletion spec/unit/subscriber_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@

ThisModule.parent.send :remove_const, :ThisModule
end


it 'should subscribe to multiple events' do
Eventwire.driver.should_receive(:subscribe).with(:task_completed, anything)
Eventwire.driver.should_receive(:subscribe).with(:project_completed, anything)

subject.on(:task_completed, :project_completed) { }
end
end

end

0 comments on commit 68b8d62

Please sign in to comment.