Module: Rucola::Notifications

Defined in:
lib/rucola/rucola_support/notifications/notifications.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

:nodoc



126
127
128
129
130
131
132
133
134
# File 'lib/rucola/rucola_support/notifications/notifications.rb', line 126

def self.included(base) # :nodoc
  base.extend(ClassMethods)
  
  # register the initialize hook which actually registers the notifications for the instance.
  base._rucola_register_initialize_hook lambda { self._register_notifications }
  
  # register default shortcut
  base.notification_prefix :app => :application
end

Instance Method Details

#_register_notificationsObject

this instance method is called after object initialization by the initialize hook



137
138
139
140
141
142
143
144
# File 'lib/rucola/rucola_support/notifications/notifications.rb', line 137

def _register_notifications # :nodoc:
  notifications = self.class.instance_variable_get(:@_registered_notifications)
  return if notifications.nil?
  center = OSX::NSNotificationCenter.defaultCenter
  notifications.each do |notification_name, notification_handler|
    center.addObserver_selector_name_object(self, notification_handler, notification_name, nil)
  end
end