Module: Emittance::Notifier

Defined in:
lib/emittance/notifier.rb

Overview

Like Emittance::Action, this is a convenience module that you can mix-in to any class that provides a shortuct for a common pattern. An object (usually, a class) that mixes in Emittance::Notifier will watch for all events and call the method on that object with the same name as the event’s identifier. For example:

class MyNotifier
  extend Emittance::Notifier

  def self.something_happened(event)
    puts 'something definitely happened!'
  end
end

Whenever an event whose identifiers include something_happened is emitted, MyNotifier.something_happened will be invoked.

foo.emit :something_happened
# Prints:
# something definitely happened!

foo.emit :something_else_happened
# (nothing)

Notice that (1) MyNotifier doesn’t need to explicitly listen to :something_happened, and (2) no errors or anything occur when an event is emitted for which MyNotifier doesn’t have a method defined.