Class: CentralNotifications::Notifier

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Notifier

Returns a new instance of Notifier.



7
8
9
# File 'lib/notifier.rb', line 7

def initialize args={}
  @registrations = {}
end

Instance Attribute Details

#klassObject

Returns the value of attribute klass.



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

def klass
  @klass
end

#methodObject

Returns the value of attribute method.



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

def method
  @method
end

#registrationsObject

Returns the value of attribute registrations.



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

def registrations
  @registrations
end

Class Method Details

.instanceObject



11
12
13
# File 'lib/notifier.rb', line 11

def self.instance
  return @@instance ||= Notifier.new
end

Instance Method Details

#alert(registration, notifier) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/notifier.rb', line 25

def alert(registration, notifier)
  registrations[registration].each do |notified|
    ObjectSpace.each_object(notified[:klass]) do |object|
      object.send(:instance_variable_set, :@registration_result, registration.result)
      object.send(:instance_variable_set, :@notifier_object, notifier)
      object.send(notified[:method])
    end
  end
end

#register {|registration, _self| ... } ⇒ Object

Yields:

  • (registration, _self)

Yield Parameters:



15
16
17
18
19
20
21
22
23
# File 'lib/notifier.rb', line 15

def register
  registration = Registration.new(:notifier => self)
  yield registration, self

  registration = registration_from_stack(registration)
  registrations[registration] ||= []
  registrations[registration] << {:klass => klass, :method => method}
  registration.fork
end