rdux 0.8.0 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rdux/version.rb +1 -1
  3. data/lib/rdux.rb +30 -9
  4. metadata +2 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f85ae2c3b4fb14d506d70e48c26cf1e64c84bb6ae4a75aea68adf84511097033
4
- data.tar.gz: 9166c1c160fb34fd0eb8b4b0b0b0f686b7d0fb739a2bfffae0e91007696f8b3d
3
+ metadata.gz: fb70d8633e88f42179223f60bfe5634273591875f0e3d104fb076128af8811ba
4
+ data.tar.gz: 375487c3f51b78803b9d610877edb5e5fcec70918e86e376cf2601188a9e4358
5
5
  SHA512:
6
- metadata.gz: c55c97c8f354115046bbea7aef96797c40dd4089a61f0ad9c97ceaf7f6078b0267111c23822773367dca441f55c90c2f7a53da253872f1465fa5beef7c725a28
7
- data.tar.gz: a307c6f2cc36b33cace288e5a7788a45ad0db2409b6e1296adcacf677c3fc63aaa2f56583321ff386b9030ab6a0f6f4d7c96243daa448846ebee3cbb1ac0e98f
6
+ metadata.gz: 4fbd330495ba4b140f828dc2e5184e27f4abd653c9e8d314d8a576c4612294c8baca8aceeeeccdab1e8be184a566544daaf1a75bc2dab2f1bba1801aab7f11cd
7
+ data.tar.gz: da3820133a5d277e1b5a20eee3876efb13e7cd434105585a3b2da5a014062072e17a77a93b35f35bb601d1f7d6c30dc4b930adb9e0f56e99aaeb358f1b9629e8
data/lib/rdux/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rdux
4
- VERSION = '0.8.0'
4
+ VERSION = '0.9.1'
5
5
  end
data/lib/rdux.rb CHANGED
@@ -9,9 +9,13 @@ module Rdux
9
9
  class << self
10
10
  def dispatch(action_name, payload, opts = {}, meta: nil)
11
11
  (opts[:ars] || {}).each { |k, v| payload["#{k}_id"] = v.id }
12
- action = Action.create!(name: action_name, up_payload: payload, meta:)
12
+ action = Action.new(name: action_name, up_payload: payload, meta:)
13
13
  sanitize(action)
14
- call_call_or_up_on_action(action, opts)
14
+ action.save!
15
+ res = call_call_or_up_on_action(action, opts)
16
+ assign_and_persist(res, action)
17
+ res.after_save&.call(res.action)
18
+ res
15
19
  end
16
20
 
17
21
  alias perform dispatch
@@ -21,14 +25,18 @@ module Rdux
21
25
  def call_call_or_up_on_action(action, opts)
22
26
  res = action.call(opts)
23
27
  if res
24
- res[:val] ||= res.down_payload
25
- res.down_payload = nil
26
- else
27
- res = action.up(opts)
28
+ no_down(res)
29
+ return res
28
30
  end
29
- assign_and_persist(res, action)
30
- res.after_save.call(res.action) if res.after_save && res.action
31
- res
31
+
32
+ action.up(opts)
33
+ rescue StandardError => e
34
+ handle_exception(e, action)
35
+ end
36
+
37
+ def no_down(res)
38
+ res[:val] ||= res.down_payload
39
+ res.down_payload = nil
32
40
  end
33
41
 
34
42
  def assign_and_persist(res, action)
@@ -71,5 +79,18 @@ module Rdux
71
79
  action.up_payload_unsanitized = action.up_payload if action.up_payload_sanitized
72
80
  action.up_payload = up_payload_sanitized
73
81
  end
82
+
83
+ def handle_exception(exc, action)
84
+ failed_action = action.to_failed_action
85
+ failed_action.up_result = {
86
+ 'Exception' => {
87
+ class: exc.class.name,
88
+ message: exc.message
89
+ }
90
+ }
91
+ failed_action.save!
92
+ action.destroy
93
+ raise exc
94
+ end
74
95
  end
75
96
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rdux
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zbigniew Humeniuk
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-05-21 00:00:00.000000000 Z
11
+ date: 2024-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -88,9 +88,6 @@ dependencies:
88
88
  version: 1.7.0
89
89
  description: |
90
90
  Write apps that are easy to test.
91
- Rdux gives you a possibility to centralize your app's state modification logic (DB changes).
92
- It does it via introducing a new architectural layer - actions.
93
- Rdux enables powerful capabilities like undo/redo.
94
91
  It makes it easy to trace when, where, why, and how your application's state changed.
95
92
  email:
96
93
  - hello@artofcode.co