Module: Isolate::Events
Overview
Class Method Summary collapse
-
.fire(klass, name, *args) ⇒ Object
:nodoc:.
-
.watch(klass, name, &block) ⇒ Object
Watch for an event called
namefrom an instance ofklass. -
.watchers ⇒ Object
:nodoc:.
Instance Method Summary collapse
Class Method Details
.fire(klass, name, *args) ⇒ Object
:nodoc:
23 24 25 26 27 |
# File 'lib/isolate/events.rb', line 23 def self.fire klass, name, *args #:nodoc: watchers[[klass, name]].each do |block| block[*args] end end |
.watch(klass, name, &block) ⇒ Object
Watch for an event called name from an instance of klass. block will be called when the event occurs. Block args vary by event, but usually an instance of the relevant class is passed.
19 20 21 |
# File 'lib/isolate/events.rb', line 19 def self.watch klass, name, &block watchers[[klass, name]] << block end |
.watchers ⇒ Object
:nodoc:
29 30 31 |
# File 'lib/isolate/events.rb', line 29 def self.watchers #:nodoc: @watchers ||= Hash.new { |h, k| h[k] = [] } end |
Instance Method Details
#fire(name, after = nil, *args, &block) ⇒ Object
:nodoc:
33 34 35 36 37 38 39 40 |
# File 'lib/isolate/events.rb', line 33 def fire name, after = nil, *args, &block #:nodoc: Isolate::Events.fire self.class, name, self, *args if after && block_given? yield self Isolate::Events.fire self.class, after, *args end end |