Module: Cura::Attributes::HasEvents
- Included in:
- Cura::Application, Component::Base, Window
- Defined in:
- lib/cura/attributes/has_events.rb
Overview
Adds an ‘event_handler` attribute as well as `callbacks` and `on_event` class methods. When subclassed, the callbacks are inherited. TODO: Rename to HasEventHandler
Defined Under Namespace
Modules: ClassMethods
Instance Attribute Summary collapse
-
#event_handler ⇒ Event::Handler
readonly
Get the event handler for this object.
Class Method Summary collapse
Instance Method Summary collapse
- #initialize(attributes = {}) ⇒ Object
-
#on_event(event_name = :default, *arguments) { ... } ⇒ Proc
Register a callback for an event to this instance.
Instance Attribute Details
#event_handler ⇒ Event::Handler (readonly)
Get the event handler for this object.
59 60 61 |
# File 'lib/cura/attributes/has_events.rb', line 59 def event_handler @event_handler end |
Class Method Details
.included(base) ⇒ Object
44 45 46 |
# File 'lib/cura/attributes/has_events.rb', line 44 def included(base) base.send(:extend, ClassMethods) end |
Instance Method Details
#initialize(attributes = {}) ⇒ Object
49 50 51 52 53 54 |
# File 'lib/cura/attributes/has_events.rb', line 49 def initialize(attributes={}) @event_handler = Event::Handler.new(self) register_class_callbacks super end |
#on_event(event_name = :default, *arguments) { ... } ⇒ Proc
Register a callback for an event to this instance.
66 67 68 |
# File 'lib/cura/attributes/has_events.rb', line 66 def on_event(event_name=:default, *arguments, &block) event_handler.register(event_name, *arguments, &block) end |