Class: Notification

Inherits:
Object
  • Object
show all
Defined in:
lib/kwala/notification.rb

Direct Known Subclasses

EmailNotification, RSSNotification

Constant Summary collapse

@@notifications =
[]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.add_notification(obj) ⇒ Object



17
18
19
# File 'lib/kwala/notification.rb', line 17

def self.add_notification(obj)
  self.notifications << obj
end

.contextObject



9
10
11
# File 'lib/kwala/notification.rb', line 9

def self.context
  @context
end

.context=(context) ⇒ Object



5
6
7
# File 'lib/kwala/notification.rb', line 5

def self.context=(context)
  @context = context
end

.notificationsObject



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/kwala/notification.rb', line 21

def self.notifications
  if @@notifications.empty?
    Dir.glob(NOTIFICATION_DIR + "/*.rb").sort.each do |file|
      begin
        require file
      rescue Exception => err
        $stderr.puts "Notification error loading #{file}", err.class, err.message
      end
    end
  end
  @@notifications
end

.notify(event, result, data) ⇒ Object



13
14
15
# File 'lib/kwala/notification.rb', line 13

def self.notify(event, result, data)
  self.notifications.each { |n| n.notify(event, result, data) }
end

Instance Method Details

#notify(event, result = nil, data = nil) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/kwala/notification.rb', line 34

def notify(event, result = nil, data = nil)
  if self.respond_to?(event)
    self.send(event, result, data, Notification.context)
  else
    undefined_event(event, result, data, Notification.context)
  end
end

#undefined_event(event, result, data, context) ⇒ Object



42
43
# File 'lib/kwala/notification.rb', line 42

def undefined_event(event, result, data, context)
end