krisleech/wisper — pull request #43 by jhoffner (2014-03-09 23:38:25+00:00)
Title: Class prefix

Added a class prefix option that allows global (or temporary) listeners to easily be namespaced, without having to define it within each event broadcast.

So for example:

```ruby
class Project
include Wisper::Publisher

def create!
broadcast(:created, self)
end

def complete!
broadcast(:completed, self)
end
end

class NotificationsListener
def project_created(project)
end

def project_completed(project)
end

def project_task_completed(project_item)
end

def project_user_added
end

def user_created
end
end

Wisper.with_listeners(NotificationsListener, class_prefix: true) do
User.create!
project = Project.create!
project.complete!
end
```

Some advantages of dynamically prefixing the event names instead of just defining the fully qualified events manually are:

- You can define common functionality in a base class. For example a commit method. I believe I saw an example of this on a blog article you wrote.
- You can optionally choose to handle the event as a class specific event or not. For example maybe you just want to listen to any :created event and fire off a generic log message, now you don't need to define a handlers for each object that can be created. However you may also want to target a specific created event (like project_completed), you have the flexibility to do both.