Commit 8032db6
committed
Add SSHKit::Backend.current
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.1 parent 67eb3a0 commit 8032db6
3 files changed
Lines changed: 42 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
20 | 24 | | |
21 | 25 | | |
22 | 26 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
7 | 20 | | |
8 | 21 | | |
9 | 22 | | |
| |||
12 | 25 | | |
13 | 26 | | |
14 | 27 | | |
| 28 | + | |
15 | 29 | | |
| 30 | + | |
| 31 | + | |
16 | 32 | | |
17 | 33 | | |
18 | 34 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
131 | 131 | | |
132 | 132 | | |
133 | 133 | | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
134 | 156 | | |
135 | 157 | | |
136 | 158 | | |
| |||
0 commit comments