rdux 0.8.0 → 0.9.0

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 +32 -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: 273465473611ad7e7498f183191d7bb29b31a9e69af497ae0905cfd1a41d4781
4
+ data.tar.gz: 6e423cb95ef75e5d5a78288a14332bc8971ffa50cfe1c409d0b2997f17418cc0
5
5
  SHA512:
6
- metadata.gz: c55c97c8f354115046bbea7aef96797c40dd4089a61f0ad9c97ceaf7f6078b0267111c23822773367dca441f55c90c2f7a53da253872f1465fa5beef7c725a28
7
- data.tar.gz: a307c6f2cc36b33cace288e5a7788a45ad0db2409b6e1296adcacf677c3fc63aaa2f56583321ff386b9030ab6a0f6f4d7c96243daa448846ebee3cbb1ac0e98f
6
+ metadata.gz: 13de207f08f81118a33e7d4d849194a064d068f9b4a8b55f59f4bb5e6f7b47a66ac797982ecba2726cc558794e2aca22a3b15f5cc40f0ae6c1faae78ac710efe
7
+ data.tar.gz: 2ae59b96d2917a17891c9dc442040ae5068b1689926cc7495c6957615c95a6a0738c4b54a890057a7d426375335330dbbfd92b1d617c714981e2fb819d18d795
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.0'
5
5
  end
data/lib/rdux.rb CHANGED
@@ -9,9 +9,15 @@ 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
+ return res if res.ok == false
18
+
19
+ res.after_save&.call(res.action)
20
+ res
15
21
  end
16
22
 
17
23
  alias perform dispatch
@@ -21,14 +27,18 @@ module Rdux
21
27
  def call_call_or_up_on_action(action, opts)
22
28
  res = action.call(opts)
23
29
  if res
24
- res[:val] ||= res.down_payload
25
- res.down_payload = nil
26
- else
27
- res = action.up(opts)
30
+ no_down(res)
31
+ return res
28
32
  end
29
- assign_and_persist(res, action)
30
- res.after_save.call(res.action) if res.after_save && res.action
31
- res
33
+
34
+ action.up(opts)
35
+ rescue StandardError => e
36
+ handle_exception(e, action)
37
+ end
38
+
39
+ def no_down(res)
40
+ res[:val] ||= res.down_payload
41
+ res.down_payload = nil
32
42
  end
33
43
 
34
44
  def assign_and_persist(res, action)
@@ -71,5 +81,18 @@ module Rdux
71
81
  action.up_payload_unsanitized = action.up_payload if action.up_payload_sanitized
72
82
  action.up_payload = up_payload_sanitized
73
83
  end
84
+
85
+ def handle_exception(exc, action)
86
+ failed_action = action.to_failed_action
87
+ failed_action.up_result = {
88
+ 'Exception' => {
89
+ class: exc.class.name,
90
+ message: exc.message
91
+ }
92
+ }
93
+ failed_action.save!
94
+ action.destroy
95
+ raise exc
96
+ end
74
97
  end
75
98
  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.0
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