Commit 8a929b0
committed
Add
This commit introduces three additional callbacks for the sake of parity
with other lifecycle methods:
* `before_reload` - evaluated before re-fetching the resource's data
with a `GET` request
```ruby
class User < ActiveResource::Base
before_reload -> { throw :abort }, unless: :id?
end
```
* `after_reload` - evaluated after re-fetching the resource's data with
a `GET` request
```ruby
class User < ActiveResource::Base
after_reload -> { Rails.logger.info("Congratulations, the callback has run!") }
end
```
* `around_reload` - evaluated around re-fetching the resource's data
with a `GET` request
```ruby
class User < ActiveResource::Base
around_reload :log_reloading
schema do
attribute :email, :string
end
def log_reloading
Rails.logger.info("Reloading user with email: #{email}")
yield
Rails.logger.info("User reloaded with email: #{email}")
end
end
```reload callbacks1 parent 0019d7d commit 8a929b0
File tree
4 files changed
+83
-6
lines changed- lib/active_resource
- test/cases
4 files changed
+83
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1380 | 1380 | | |
1381 | 1381 | | |
1382 | 1382 | | |
| 1383 | + | |
| 1384 | + | |
| 1385 | + | |
| 1386 | + | |
1383 | 1387 | | |
1384 | 1388 | | |
1385 | 1389 | | |
| |||
1405 | 1409 | | |
1406 | 1410 | | |
1407 | 1411 | | |
1408 | | - | |
| 1412 | + | |
1409 | 1413 | | |
1410 | 1414 | | |
1411 | 1415 | | |
1412 | 1416 | | |
1413 | 1417 | | |
1414 | 1418 | | |
1415 | 1419 | | |
| 1420 | + | |
| 1421 | + | |
| 1422 | + | |
| 1423 | + | |
1416 | 1424 | | |
1417 | 1425 | | |
1418 | 1426 | | |
| |||
1468 | 1476 | | |
1469 | 1477 | | |
1470 | 1478 | | |
1471 | | - | |
1472 | | - | |
1473 | | - | |
| 1479 | + | |
| 1480 | + | |
| 1481 | + | |
1474 | 1482 | | |
1475 | 1483 | | |
1476 | 1484 | | |
| |||
1614 | 1622 | | |
1615 | 1623 | | |
1616 | 1624 | | |
| 1625 | + | |
| 1626 | + | |
| 1627 | + | |
| 1628 | + | |
1617 | 1629 | | |
1618 | 1630 | | |
1619 | 1631 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
6 | 54 | | |
7 | 55 | | |
8 | 56 | | |
9 | 57 | | |
10 | 58 | | |
11 | 59 | | |
12 | | - | |
| 60 | + | |
| 61 | + | |
13 | 62 | | |
14 | 63 | | |
15 | 64 | | |
16 | 65 | | |
17 | 66 | | |
18 | 67 | | |
19 | | - | |
| 68 | + | |
20 | 69 | | |
21 | 70 | | |
22 | 71 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
104 | 119 | | |
105 | 120 | | |
106 | 121 | | |
| |||
0 commit comments