You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The point of SSHKit::Backend.current is to give code access to the current
Backend without having to pass around a reference to it. For example, consider
a `git` helper that executes a git command:
def git(*args)
SSHKit::Backend.current.execute(:git, *args)
end
Thanks to `current`, we can use this git method wherever we are in an `on`
block, without having to pass a reference to `self`:
on release_roles(:all) do
git "status"
end
Without the thread local, the same task would be much more awkward due to the
necessary passing of `self`:
def git(backend, *args)
backend.execute(:git, *args)
end
on release_roles(:all) do
git self, "status"
end
To someone not intimately familiar with SSHKit, what `self` in this context is
confusing and not obvious at all. It is because SSHKit uses `instance_exec`
within the `on` block that `self` magically transforms.
Better to avoid using `self` altogether and prefer the thread local.
0 commit comments