Module Rucola::Notifications::ClassMethods
In: lib/rucola/rucola_support/notifications/notifications.rb

This Notifications module will add a class method called notify_on, which registers your object for the given notification and executes the given block when the notification is posted to the OSX::NSNotificationCenter.defaultCenter.

  class FooController < OSX::NSObject

    notify_on OSX::NSApplicationDidFinishLaunchingNotification do |notification|
      puts "Application did finish launching."
      p notification
    end

    # code

  end

  In addition to notify_on, you also get a method called notify which allows you to specify methods
  to be invoked when a notification is posted.

    class FooController < OSX::NSObject
      notify :some_method, :when => :application_did_finish_launching

      def some_method(notification)
        puts "Application finished launching"
      end
    end

Methods

Public Instance methods

Creates a notification and posts it to the reciever

Add prefix shortcuts as a hash.

  class FooController < OSX::NSObject
    acts_as_notifiable

    # This will make sure that :win_ is expanded to :window_ in the notifications that you register.
    notification_prefix :win => :window

    when :win_did_become_key do |notification|
      # code
    end
  end

By default the shortcut { :app => :application } is registered.

Register a callback when a notification is posted.

    class FooController < OSX::NSObject
      notify :some_method, :when => :application_did_finish_launching

      def some_method(notification)
        puts "Application finished launching"
      end
    end

Registers the object for the given notification and executes the given block when the notification is posted to the OSX::NSNotificationCenter.defaultCenter.

  class FooController < OSX::NSObject

    notify_on OSX::NSApplicationDidFinishLaunchingNotification do |notification|
      puts "Application did finish launching."
      p notification
    end

    # code

  end

You can also pass it a symbol as notification in which case it will be exapnded. It will first check if the name + ‘Notification’ exists, if not it will prepend ‘NS’. So :application_did_finish_launching becomes ‘NSApplicationDidFinishLaunchingNotification’.

You can even register shortcut prefixes. See notification_prefix.

once(notification, &block)

Alias for notify_on

post_notification(notification, obj)

Alias for fire_notification

Protected Instance methods

Given a symbol, attempt to map it to an NSNoficication, otherwise return the symbol if nothing is found.

   :app_finished_launching => NSApplicationFinishLaunchingNotification

[Validate]