This repository has been archived by the owner on May 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Advance Usages
Stan Lo edited this page May 24, 2020
·
1 revision
Tapping methods like tap_on!
are designed for simple use cases. They're actually short for
device = TappingDevice.new { # tapping action }
device.tap_on!(object)
And if you want to do some more configurations like stopping them manually or setting stop condition, you must have a TappingDevie
instance. You can either get them like the above code or save the return value of tap_*!
method calls.
Once you have a TappingDevice
instance in hand, you will be able to stop the tapping by
- Manually calling
device.stop!
- Setting stop condition with
device.stop_when
, like
device.stop_when do |payload|
device.calls.count >= 10 # stop after gathering 10 calls’ data
end
Each TappingDevice
instance can have 3 states:
-
Initial
- means the instance is initialized but hasn't tapped on anything. -
Enabled
- means the instance is tapping on something (has calledtap_*
methods). -
Disabled
- means the instance has been disabled. It will no longer receive any call info.
When debugging, we may create many device instances and tap objects in several places. Then it'll be quite annoying to manage their states. So TappingDevice
has several class methods that allows you to manage all TappingDevice
instances:
-
TappingDevice.devices
- Lists all registered devices withinitial
orenabled
state. Note that any instance that's been stopped will be removed from the list. -
TappingDevice.stop_all!
- Stops all registered devices and remove them from thedevices
list. -
TappingDevice.suspend_new!
- Suspends any device instance from changing their state frominitial
toenabled
. Which means anytap_*
calls after it will no longer work. -
TappingDevice.reset!
- Cancelssuspend_new
(if called) and stops/removes all created devices. Useful to reset the environment between test cases.