Class: Gloo::Core::EventManager
- Inherits:
-
Object
- Object
- Gloo::Core::EventManager
- Defined in:
- lib/gloo/core/event_manager.rb
Instance Method Summary collapse
-
#initialize(engine) ⇒ EventManager
constructor
Set up the event manager.
-
#on_error(msg, backtrace) ⇒ Object
Run the on_error scripts in any open objects.
-
#on_load(obj = nil, in_heap = false) ⇒ Object
Run on_load scripts in the recently loaded object If no obj is given the script will be run in root.
-
#on_quit ⇒ Object
Run on_quit scripts in any open objets.
-
#on_reload(obj) ⇒ Object
Run on_reload scripts in the object that will be reloaded.
-
#on_save(obj) ⇒ Object
Run on_save scripts in the object that is being saved.
-
#on_unload(obj) ⇒ Object
Run on_unload scripts in the object that will be unloaded.
Constructor Details
#initialize(engine) ⇒ EventManager
Set up the event manager.
15 16 17 18 |
# File 'lib/gloo/core/event_manager.rb', line 15 def initialize( engine ) @engine = engine @engine.log.debug 'event manager intialized...' end |
Instance Method Details
#on_error(msg, backtrace) ⇒ Object
Run the on_error scripts in any open objects. For each on_error script found, look for the error_data container and set the error message and backtrace.
80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/gloo/core/event_manager.rb', line 80 def on_error msg, backtrace @engine.log.debug 'on_error event' arr = Gloo::Core::ObjFinder.by_name( @engine, 'on_error' ) arr.each do |o| data = o.parent.find_child 'error_data' if data data.find_child( 'message' ).set_value msg data.find_child( 'backtrace' ).set_value backtrace end Gloo::Exec::Dispatch.( @engine, 'run', o ) end end |
#on_load(obj = nil, in_heap = false) ⇒ Object
Run on_load scripts in the recently loaded object If no obj is given the script will be run in root.
24 25 26 27 28 29 30 |
# File 'lib/gloo/core/event_manager.rb', line 24 def on_load( obj = nil, in_heap = false ) return unless obj || in_heap @engine.log.debug 'on_load event' arr = Gloo::Core::ObjFinder.by_name( @engine, 'on_load', obj ) arr.each { |o| Gloo::Exec::Dispatch.( @engine, 'run', o ) } end |
#on_quit ⇒ Object
Run on_quit scripts in any open objets. If no obj is given the script will be run in root.
69 70 71 72 73 |
# File 'lib/gloo/core/event_manager.rb', line 69 def on_quit @engine.log.debug 'on_quit event' arr = Gloo::Core::ObjFinder.by_name( @engine, 'on_quit' ) arr.each { |o| Gloo::Exec::Dispatch.( @engine, 'run', o ) } end |
#on_reload(obj) ⇒ Object
Run on_reload scripts in the object that will be reloaded.
46 47 48 49 50 51 52 |
# File 'lib/gloo/core/event_manager.rb', line 46 def on_reload( obj ) return unless obj @engine.log.debug 'on_reload event' arr = Gloo::Core::ObjFinder.by_name( @engine, 'on_reload', obj ) arr.each { |o| Gloo::Exec::Dispatch.( @engine, 'run', o ) } end |
#on_save(obj) ⇒ Object
Run on_save scripts in the object that is being saved.
57 58 59 60 61 62 63 |
# File 'lib/gloo/core/event_manager.rb', line 57 def on_save( obj ) return unless obj @engine.log.debug 'on_save event' arr = Gloo::Core::ObjFinder.by_name( @engine, 'on_save', obj ) arr.each { |o| Gloo::Exec::Dispatch.( @engine, 'run', o ) } end |
#on_unload(obj) ⇒ Object
Run on_unload scripts in the object that will be unloaded.
35 36 37 38 39 40 41 |
# File 'lib/gloo/core/event_manager.rb', line 35 def on_unload( obj ) return unless obj @engine.log.debug 'on_unload event' arr = Gloo::Core::ObjFinder.by_name( @engine, 'on_unload', obj ) arr.each { |o| Gloo::Exec::Dispatch.( @engine, 'run', o ) } end |