rdux 1.0.0 β 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +3 -4
- data/lib/rdux/version.rb +1 -1
- data/lib/rdux.rb +7 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d324cf717b31be876266cde5674bca57929719914bfe4b93761b031c555e18de
|
4
|
+
data.tar.gz: 1b2d57b63cbed3caa591e5e182633d3d70f58e16e6c5dbf2d304e6b51deba6b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f324e2366c6bcdfed6d8e2ae7e786d60eead983e7a842d4ee5ad843342224bb46a3d5500ee996b8145e0bd2a0f39a8892ddb804cc6bc94f4e5c3c79e64568988
|
7
|
+
data.tar.gz: e824ef36d9d639af4e4b8ef729c2eeb4c72b27070dbd0a3f0a5edb7c2198e5e00c2c07c1fbb1d3a6fd86dea3c9a1ce04d576423772ee65816a24befa120251da
|
data/README.md
CHANGED
@@ -17,7 +17,7 @@ Rdux is a lightweight, minimalistic Rails plugin designed to introduce event sou
|
|
17
17
|
|
18
18
|
* **Audit Logging** π Rdux stores sanitized input data, the name of module or class (action performer) responsible for processing them, processing results, and additional metadata in the database.
|
19
19
|
* **Model Representation** π Before action is executed it gets stored in the database through the `Rdux::Action` model. This model can be nested, allowing for complex action structures.
|
20
|
-
* **Exception Handling and Recovery** π Rdux automatically creates a `Rdux::Action` record when an exception occurs during action execution. It retains the `payload` and allows you to capture additional data using `opts[:result
|
20
|
+
* **Exception Handling and Recovery** π Rdux automatically creates a `Rdux::Action` record when an exception occurs during action execution. It retains the `payload` and allows you to capture additional data using `opts[:action].result`, ensuring all necessary information is available for retrying the action.
|
21
21
|
* **Metadata** π Metadata can include the ID of the authenticated resource responsible for performing a given action, as well as resource IDs from external systems related to the action. This creates a clear audit trail of who executed each action and on whose behalf.
|
22
22
|
|
23
23
|
Rdux is designed to integrate seamlessly with your existing Rails application, offering a straightforward and powerful solution for managing and auditing key actions.
|
@@ -244,8 +244,7 @@ end
|
|
244
244
|
Rdux captures exceptions raised during the execution of an action and sets the `Rdux::Action#ok` attribute to `false`.
|
245
245
|
The `payload` is retained, but having only the input data is often not enough to retry an action.
|
246
246
|
It is crucial to capture data obtained during the actionβs execution, up until the exception occurred.
|
247
|
-
This can be done by using `opts[:result
|
248
|
-
The assigned data will then be available as the `Rdux::Action#result` attribute.
|
247
|
+
This can be done by using `opts[:action].result` attribute to store all necessary data incrementally.
|
249
248
|
|
250
249
|
Example:
|
251
250
|
|
@@ -257,7 +256,7 @@ class CreditCard
|
|
257
256
|
create_res = create(payload.slice('user_id', 'credit_card'), opts.slice(:user))
|
258
257
|
return create_res unless create_res.ok
|
259
258
|
|
260
|
-
opts[:result
|
259
|
+
opts[:action].result = { credit_card_create_action_id: create_res.action.id }
|
261
260
|
charge_id = PaymentGateway.charge(create_res.val[:credit_card].token, payload['amount'])[:id]
|
262
261
|
if charge_id.nil?
|
263
262
|
Rdux::Result[ok: false, val: { errors: { base: 'Invalid credit card' } }, save: true,
|
data/lib/rdux/version.rb
CHANGED
data/lib/rdux.rb
CHANGED
@@ -19,14 +19,13 @@ module Rdux
|
|
19
19
|
|
20
20
|
def process(action, opts = {})
|
21
21
|
res = action.call(opts)
|
22
|
-
res.result ||= opts[:result]
|
23
22
|
return res if destroy_action(res, action)
|
24
23
|
|
25
24
|
assign_to_action(res, action)
|
26
25
|
persist(res, action)
|
27
26
|
res
|
28
27
|
rescue StandardError => e
|
29
|
-
handle_exception(e, action
|
28
|
+
handle_exception(e, action)
|
30
29
|
end
|
31
30
|
|
32
31
|
alias perform dispatch
|
@@ -41,7 +40,10 @@ module Rdux
|
|
41
40
|
|
42
41
|
def assign_to_action(res, action)
|
43
42
|
action.ok = res.ok
|
44
|
-
|
43
|
+
return unless res.result
|
44
|
+
|
45
|
+
action.result ||= {}
|
46
|
+
action.result.merge!(res.result)
|
45
47
|
end
|
46
48
|
|
47
49
|
def persist(res, action)
|
@@ -49,9 +51,9 @@ module Rdux
|
|
49
51
|
res.nested&.each { |nested_res| action.rdux_actions << nested_res.action }
|
50
52
|
end
|
51
53
|
|
52
|
-
def handle_exception(exc, action
|
54
|
+
def handle_exception(exc, action)
|
53
55
|
action.ok = false
|
54
|
-
action.result ||=
|
56
|
+
action.result ||= {}
|
55
57
|
action.result.merge!({ 'Exception' => {
|
56
58
|
class: exc.class.name,
|
57
59
|
message: exc.message
|