Module: CallbacksAttachable::RegistryOwnable
- Defined in:
- lib/all/callbacks_attachable.rb
Instance Method Summary collapse
- #__callbacks__ ⇒ Object
- #extended(object) ⇒ Object
- #included(klass) ⇒ Object
- #on(*events, &callback) ⇒ Object
- #on?(event) ⇒ Boolean
- #once_on(*events, &callback) ⇒ Object
- #trigger_for_instance(inst, event, args) ⇒ Object
Instance Method Details
#__callbacks__ ⇒ Object
34 35 36 |
# File 'lib/all/callbacks_attachable.rb', line 34 def __callbacks__ @__callbacks__ ||= CallbackRegistry.new self end |
#extended(object) ⇒ Object
3 4 5 |
# File 'lib/all/callbacks_attachable.rb', line 3 def extended(object) CallbacksAttachable.extended object end |
#included(klass) ⇒ Object
7 8 9 |
# File 'lib/all/callbacks_attachable.rb', line 7 def included(klass) CallbacksAttachable.included klass end |
#on(*events, &callback) ⇒ Object
11 12 13 |
# File 'lib/all/callbacks_attachable.rb', line 11 def on(*events, &callback) __callbacks__.register(*events, @on_opts ? @on_opts : {}, callback) end |
#on?(event) ⇒ Boolean
22 23 24 |
# File 'lib/all/callbacks_attachable.rb', line 22 def on?(event) @__callbacks__ ? (@__callbacks__.registered? event) : false end |
#once_on(*events, &callback) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/all/callbacks_attachable.rb', line 15 def once_on(*events, &callback) @on_opts = {once?: true} on *events, &callback ensure @on_opts = nil end |
#trigger_for_instance(inst, event, args) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/all/callbacks_attachable.rb', line 26 def trigger_for_instance(inst, event, args) if superclass.respond_to? :trigger_for_instance superclass.trigger_for_instance(inst, event, args) end @__callbacks__ and @__callbacks__.trigger(inst, event, args) :triggered end |