Module: NotificationCenter
- Extended by:
- Configuration
- Defined in:
- lib/notification_center.rb,
lib/notification_center/cache.rb,
lib/notification_center/configuration.rb,
lib/notification_center/rspec_helpers.rb,
lib/notification_center/core_ext/module.rb
Defined Under Namespace
Modules: Configuration, CoreExt, RspecHelpers
Classes: Cache
Constant Summary
Configuration::DEFAULT_ENABLE_CACHE, Configuration::DEFAULT_ENABLE_NOTIFICATIONS, Configuration::DEFAULT_METHOD_SUFFIX, Configuration::VALID_OPTIONS_KEYS
Class Method Summary
collapse
extended, reset
Class Method Details
._initialize_event_store ⇒ Object
Also known as:
forget_observers!
11
12
13
|
# File 'lib/notification_center.rb', line 11
def _initialize_event_store
@@events = Hash.new Array.new
end
|
._notify!(event, *args) ⇒ Object
23
24
25
26
27
28
|
# File 'lib/notification_center.rb', line 23
def _notify! event, *args
event_handler = "#{event}_#{method_suffix}"
receivers = @@events[event]
result = receivers.map{|receiver| receiver.send(event_handler, *args)}
return (result.size == 1 ? result[0] : result)
end
|
._with_cache(event) ⇒ Object
.events ⇒ Object
8
|
# File 'lib/notification_center.rb', line 8
def events; @@events end
|
.events=(hash) ⇒ Object
9
|
# File 'lib/notification_center.rb', line 9
def events= hash; @@events = hash end
|
.post_notification(*args) ⇒ Object
16
17
18
19
20
21
|
# File 'lib/notification_center.rb', line 16
def post_notification *args
event = args.shift
if enable_notifications
enable_cache ? _with_cache(event){ _notify! event, *args } : _notify!(event, *args)
end
end
|