Module: RMExtensions::ObjectExtensions::Observation
- Defined in:
- lib/motion/observation.rb
Instance Method Summary collapse
-
#rmext_cleanup ⇒ Object
remove all observations and event callbacks on this object.
- #rmext_observation_proxy ⇒ Object
-
#rmext_observe(object, key, &block) ⇒ Object
like
rmext_observe_passivebut additionally fires the callback immediately. -
#rmext_observe_passive(object, key, &block) ⇒ Object
observe an object.key.
-
#rmext_off(event, &block) ⇒ Object
remove a specific callback for an event on this object.
-
#rmext_off_all ⇒ Object
remove all event callbacks on this object.
-
#rmext_on(event, &block) ⇒ Object
register a callback when an event is trigger on this object.
-
#rmext_trigger(event, *args) ⇒ Object
trigger an event with args on this object.
-
#rmext_unobserve(object, key) ⇒ Object
unobserve an existing observation.
-
#rmext_unobserve_all ⇒ Object
unobserve all existing observations.
Instance Method Details
#rmext_cleanup ⇒ Object
remove all observations and event callbacks on this object
68 69 70 71 72 |
# File 'lib/motion/observation.rb', line 68 def rmext_cleanup if @rmext_observation_proxy @rmext_observation_proxy.cleanup end end |
#rmext_observation_proxy ⇒ Object
7 8 9 |
# File 'lib/motion/observation.rb', line 7 def rmext_observation_proxy @rmext_observation_proxy ||= ObservationProxy.new(self) end |
#rmext_observe(object, key, &block) ⇒ Object
like rmext_observe_passive but additionally fires the callback immediately.
22 23 24 25 |
# File 'lib/motion/observation.rb', line 22 def rmext_observe(object, key, &block) rmext_observe_passive(object, key, &block) block.call(object.send(key)) unless block.nil? end |
#rmext_observe_passive(object, key, &block) ⇒ Object
observe an object.key. takes a block that will be called with the new value upon change.
rmext_observe_passive(@model, “name”) do |val|
p "name is #{val}"
end
17 18 19 |
# File 'lib/motion/observation.rb', line 17 def rmext_observe_passive(object, key, &block) rmext_observation_proxy.observe(object, key, &block) end |
#rmext_off(event, &block) ⇒ Object
remove a specific callback for an event on this object
47 48 49 50 51 |
# File 'lib/motion/observation.rb', line 47 def rmext_off(event, &block) if @rmext_observation_proxy @rmext_observation_proxy.off(event, &block) end end |
#rmext_off_all ⇒ Object
remove all event callbacks on this object
54 55 56 57 58 |
# File 'lib/motion/observation.rb', line 54 def rmext_off_all if @rmext_observation_proxy @rmext_observation_proxy.off_all end end |
#rmext_on(event, &block) ⇒ Object
register a callback when an event is trigger on this object
42 43 44 |
# File 'lib/motion/observation.rb', line 42 def rmext_on(event, &block) rmext_observation_proxy.on(event, &block) end |
#rmext_trigger(event, *args) ⇒ Object
trigger an event with args on this object
61 62 63 64 65 |
# File 'lib/motion/observation.rb', line 61 def rmext_trigger(event, *args) if @rmext_observation_proxy @rmext_observation_proxy.trigger(event, *args) end end |
#rmext_unobserve(object, key) ⇒ Object
unobserve an existing observation
28 29 30 31 32 |
# File 'lib/motion/observation.rb', line 28 def rmext_unobserve(object, key) if @rmext_observation_proxy @rmext_observation_proxy.unobserve(object, key) end end |
#rmext_unobserve_all ⇒ Object
unobserve all existing observations
35 36 37 38 39 |
# File 'lib/motion/observation.rb', line 35 def rmext_unobserve_all if @rmext_observation_proxy @rmext_observation_proxy.unobserve_all end end |