Class: CentralNotifications::Notifier
- Inherits:
-
Object
- Object
- CentralNotifications::Notifier
- Defined in:
- lib/notifier.rb
Instance Attribute Summary collapse
-
#klass ⇒ Object
Returns the value of attribute klass.
-
#method ⇒ Object
Returns the value of attribute method.
-
#registrations ⇒ Object
Returns the value of attribute registrations.
Class Method Summary collapse
Instance Method Summary collapse
- #alert(registration, notifier) ⇒ Object
-
#initialize(args = {}) ⇒ Notifier
constructor
A new instance of Notifier.
- #register {|registration, _self| ... } ⇒ Object
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
#klass ⇒ Object
Returns the value of attribute klass.
5 6 7 |
# File 'lib/notifier.rb', line 5 def klass @klass end |
#method ⇒ Object
Returns the value of attribute method.
5 6 7 |
# File 'lib/notifier.rb', line 5 def method @method end |
#registrations ⇒ Object
Returns the value of attribute registrations.
5 6 7 |
# File 'lib/notifier.rb', line 5 def registrations @registrations end |
Class Method Details
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
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 |