Module: RMExtensions::ObjectExtensions::Events
- Defined in:
- lib/motion/events.rb
Instance Method Summary collapse
-
#rmext_cleanup ⇒ Object
remove all event callbacks from other objects in this object’s “self”.
- #rmext_events_from_proxy ⇒ Object
- #rmext_events_from_proxy? ⇒ Boolean
- #rmext_events_to_proxy ⇒ Object
- #rmext_events_to_proxy? ⇒ Boolean
- #rmext_now_and_on(event, opts = {}, &block) ⇒ Object
-
#rmext_off(event = nil, context = nil, &block) ⇒ Object
@model.rmext_off(:fire, self) # remove :fire in context “self” @model.rmext_off(:fire, &block) # remove :fire for specific handler @model.rmext_off(:fire) # remove all :fire in all knowns contexts @model.rmext_off(self) # remove all events in context “self”.
-
#rmext_on(event, opts = {}, &block) ⇒ Object
register a callback when an event is triggered on this object.
-
#rmext_once(event, opts = {}, &block) ⇒ Object
register a callback when an event is triggered on this object and remove it after it fires once.
-
#rmext_trigger(event, value = nil) ⇒ Object
trigger an event with value on this object.
Instance Method Details
#rmext_cleanup ⇒ Object
remove all event callbacks from other objects in this object’s “self”
50 51 52 53 54 |
# File 'lib/motion/events.rb', line 50 def rmext_cleanup if rmext_events_to_proxy? rmext_events_to_proxy.cleanup end end |
#rmext_events_from_proxy ⇒ Object
7 8 9 |
# File 'lib/motion/events.rb', line 7 def rmext_events_from_proxy @rmext_events_from_proxy ||= EventsFromProxy.new(self) end |
#rmext_events_from_proxy? ⇒ Boolean
11 12 13 |
# File 'lib/motion/events.rb', line 11 def rmext_events_from_proxy? !!@rmext_events_from_proxy end |
#rmext_events_to_proxy ⇒ Object
15 16 17 |
# File 'lib/motion/events.rb', line 15 def rmext_events_to_proxy @rmext_events_to_proxy ||= EventsToProxy.new(self) end |
#rmext_events_to_proxy? ⇒ Boolean
19 20 21 |
# File 'lib/motion/events.rb', line 19 def rmext_events_to_proxy? !!@rmext_events_to_proxy end |
#rmext_now_and_on(event, opts = {}, &block) ⇒ Object
28 29 30 |
# File 'lib/motion/events.rb', line 28 def rmext_now_and_on(event, opts={}, &block) rmext_events_from_proxy.now_and_on(event, opts, &block) end |
#rmext_off(event = nil, context = nil, &block) ⇒ Object
@model.rmext_off(:fire, self) # remove :fire in context “self” @model.rmext_off(:fire, &block) # remove :fire for specific handler @model.rmext_off(:fire) # remove all :fire in all knowns contexts @model.rmext_off(self) # remove all events in context “self”
43 44 45 46 47 |
# File 'lib/motion/events.rb', line 43 def rmext_off(event=nil, context=nil, &block) if rmext_events_from_proxy? rmext_events_from_proxy.off(event, context, &block) end end |
#rmext_on(event, opts = {}, &block) ⇒ Object
register a callback when an event is triggered on this object.
24 25 26 |
# File 'lib/motion/events.rb', line 24 def rmext_on(event, opts={}, &block) rmext_events_from_proxy.on(event, opts, &block) end |
#rmext_once(event, opts = {}, &block) ⇒ Object
register a callback when an event is triggered on this object and remove it after it fires once
33 34 35 36 |
# File 'lib/motion/events.rb', line 33 def rmext_once(event, opts={}, &block) opts[:limit] = 1 rmext_events_from_proxy.on(event, opts, &block) end |
#rmext_trigger(event, value = nil) ⇒ Object
trigger an event with value on this object
57 58 59 60 61 |
# File 'lib/motion/events.rb', line 57 def rmext_trigger(event, value=nil) if rmext_events_from_proxy? rmext_events_from_proxy.trigger(event, value) end end |