Class: BMF::Alert

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/bmf/lib/alert.rb

Instance Method Summary collapse

Constructor Details

#initializeAlert

Returns a new instance of Alert.



7
8
9
10
# File 'lib/bmf/lib/alert.rb', line 7

def initialize
  @alerts = []
  @new_messages = 0
end

Instance Method Details

#<<(alert) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/bmf/lib/alert.rb', line 12

def << alert
  Mutex.new.synchronize do
    if !@alerts.include? alert
      @alerts << alert
    end
  end
end

#add_new_messages(i) ⇒ Object



34
35
36
37
38
# File 'lib/bmf/lib/alert.rb', line 34

def add_new_messages i
  Mutex.new.synchronize do
    @new_messages += i
  end
end

#peekObject



20
21
22
23
24
# File 'lib/bmf/lib/alert.rb', line 20

def peek
  Mutex.new.synchronize do
    @alerts.dup.freeze
  end
end

#peek_new_messagesObject



40
41
42
43
44
# File 'lib/bmf/lib/alert.rb', line 40

def peek_new_messages
  Mutex.new.synchronize do
    @new_messages
  end
end

#popObject



26
27
28
29
30
31
32
# File 'lib/bmf/lib/alert.rb', line 26

def pop
  Mutex.new.synchronize do
    alerts = @alerts.dup.freeze
    @alerts = []
    alerts
  end
end

#pop_new_messagesObject



46
47
48
49
50
51
52
# File 'lib/bmf/lib/alert.rb', line 46

def pop_new_messages
  Mutex.new.synchronize do
    i = @new_messages
    @new_messages = 0
    i
  end
end