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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -4
  3. data/lib/rdux/version.rb +1 -1
  4. data/lib/rdux.rb +7 -5
  5. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8afda82ad3e063c5a07eb7c3e8b2a9f86019bb35ccdaa8fc875a9aebcd463a29
4
- data.tar.gz: 2d72f680e8cb5014fb55b003b09ea11cbf23107e54c8e83e2e0b5e7bff44b860
3
+ metadata.gz: d324cf717b31be876266cde5674bca57929719914bfe4b93761b031c555e18de
4
+ data.tar.gz: 1b2d57b63cbed3caa591e5e182633d3d70f58e16e6c5dbf2d304e6b51deba6b2
5
5
  SHA512:
6
- metadata.gz: 982c68f70df4e2c579e88029551a969f54470c0fa328ce5d1cbf89007001ac93fc6f78aec1a2e0096081c852174265c2e3412714d8466b7eb6ee9073273e3d3a
7
- data.tar.gz: 3e63ef96279b424c87f34a23292c70b3cc95d390b63d7f92d83ad1faf95df34b9f18ada2f969a18bf79bb6846da543f5d6b437322453844ea63fbbe21ba13129
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]`, ensuring all necessary information is available for retrying the action.
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]` to store all necessary data incrementally.
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] = { credit_card_create_action_id: create_res.action.id }
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rdux
4
- VERSION = '1.0.0'
4
+ VERSION = '2.0.0'
5
5
  end
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, opts[:result])
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
- action.result = res.result
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, result)
54
+ def handle_exception(exc, action)
53
55
  action.ok = false
54
- action.result ||= result || {}
56
+ action.result ||= {}
55
57
  action.result.merge!({ 'Exception' => {
56
58
  class: exc.class.name,
57
59
  message: exc.message
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rdux
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zbigniew Humeniuk