Module: Publisher

Defined in:
lib/publisher.rb,
lib/publisher/version.rb

Overview

See README.rdoc for synopsis

Defined Under Namespace

Modules: InstanceMethods

Constant Summary collapse

VERSION =
"1.1.2"

Instance Method Summary collapse

Instance Method Details

#has_any_eventObject Also known as: can_fire_anything

Use this method to allow subscription and firing of arbitrary events. This is convenient if, eg, your class has dynamic event names. Don’t use this unless you have to; it’s better to declare your events if you can.



31
32
33
34
# File 'lib/publisher.rb', line 31

def has_any_event
	include InstanceMethods unless @published_events
	@published_events = :any_event_is_ok
end

#has_events(*args) ⇒ Object Also known as: has_event, can_fire

Use this method (or one of the aliases) to declare which events you support Once invoked, your class will have the neccessary supporting methods for subscribing and firing.



5
6
7
8
9
10
# File 'lib/publisher.rb', line 5

def has_events(*args)
	include InstanceMethods unless @published_events
	@published_events ||= []
	@published_events << args
	@published_events.flatten!
end

#published_eventsObject



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/publisher.rb', line 14

def published_events
  return @published_events if @published_events == :any_event_is_ok
  my_events = @published_events || []
  if self.superclass.respond_to?(:published_events)
    inherited = self.superclass.published_events
    if inherited == :any_event_is_ok
      return :any_event_is_ok
    end
    my_events += self.superclass.published_events
  end
  my_events
end