rdux 0.4.1 → 0.5.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/app/models/rdux/action.rb +11 -9
- data/lib/rdux/version.rb +1 -1
- data/lib/rdux.rb +17 -25
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4d8b2deb7d13b8061c8996ccb5389ee374f7822aeb9973e50c7723688caf1c1d
|
4
|
+
data.tar.gz: 4d5fd29c0b67e4c3d01a326b2b34e7e7ee8a5599485b2ea76c48cfd445147ad6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a27f19dba3623c4e9da1f0c802d3d62f44a5d9a20a75fc7af1ac14a597e9f203b2237ada8930ca22c10e626e756d77b601041e820668485ec3c25b325c744f40
|
7
|
+
data.tar.gz: e5603781b011cd5fd8e215083be8165c3665a5071b7a148d91cfd247e6e0be3875d5289ed89f5ec593b4e26aece21f2e7b05f19d5334ccb569c8c574272e2838
|
data/app/models/rdux/action.rb
CHANGED
@@ -4,6 +4,8 @@ module Rdux
|
|
4
4
|
class Action < ApplicationRecord
|
5
5
|
include Actionable
|
6
6
|
|
7
|
+
attr_accessor :up_payload_unsanitized
|
8
|
+
|
7
9
|
belongs_to :rdux_failed_action, optional: true, class_name: 'Rdux::FailedAction'
|
8
10
|
belongs_to :rdux_action, optional: true, class_name: 'Rdux::Action'
|
9
11
|
has_many :rdux_actions, class_name: 'Rdux::Action', foreign_key: 'rdux_action_id'
|
@@ -14,14 +16,14 @@ module Rdux
|
|
14
16
|
scope :down, -> { where.not(down_at: nil) }
|
15
17
|
|
16
18
|
def call(opts = {})
|
17
|
-
perform_action(:call, up_payload, opts)
|
19
|
+
perform_action(:call, up_payload_unsanitized || up_payload, opts)
|
18
20
|
end
|
19
21
|
|
20
22
|
def up(opts = {})
|
21
|
-
return false if up_payload_sanitized
|
23
|
+
return false if up_payload_sanitized && up_payload_unsanitized.nil?
|
22
24
|
return false unless down_at.nil?
|
23
25
|
|
24
|
-
perform_action(:up, up_payload, opts)
|
26
|
+
perform_action(:up, up_payload_unsanitized || up_payload, opts)
|
25
27
|
end
|
26
28
|
|
27
29
|
def down
|
@@ -42,13 +44,13 @@ module Rdux
|
|
42
44
|
def can_down?
|
43
45
|
q = self.class.where('created_at > ?', created_at)
|
44
46
|
.where(down_at: nil)
|
45
|
-
.where('
|
47
|
+
.where('rdux_action_id IS NULL OR rdux_action_id != ?', id)
|
46
48
|
q = q.where(stream_hash: stream_hash) unless stream_hash.nil?
|
47
49
|
!q.count.positive?
|
48
50
|
end
|
49
51
|
|
50
52
|
def action_performer(meth)
|
51
|
-
name_const = name.to_s.
|
53
|
+
name_const = name.to_s.constantize
|
52
54
|
return name_const if name_const.respond_to?(meth)
|
53
55
|
return unless name_const.is_a?(Class)
|
54
56
|
|
@@ -57,13 +59,13 @@ module Rdux
|
|
57
59
|
end
|
58
60
|
|
59
61
|
def perform_action(meth, payload, opts)
|
60
|
-
|
61
|
-
return if
|
62
|
+
performer = action_performer(meth)
|
63
|
+
return if performer.nil?
|
62
64
|
|
63
65
|
if opts.any?
|
64
|
-
|
66
|
+
performer.public_send(meth, payload, opts)
|
65
67
|
else
|
66
|
-
|
68
|
+
performer.public_send(meth, payload)
|
67
69
|
end
|
68
70
|
end
|
69
71
|
|
data/lib/rdux/version.rb
CHANGED
data/lib/rdux.rb
CHANGED
@@ -9,58 +9,49 @@ 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.
|
13
|
-
|
12
|
+
action = Action.create!(name: action_name, up_payload: payload, meta: meta)
|
13
|
+
sanitize(action)
|
14
|
+
call_call_or_up_on_action(action, opts)
|
14
15
|
end
|
15
16
|
|
16
17
|
alias perform dispatch
|
17
18
|
|
18
19
|
private
|
19
20
|
|
20
|
-
def
|
21
|
+
def call_call_or_up_on_action(action, opts)
|
21
22
|
res = action.call(opts)
|
22
|
-
|
23
|
-
|
24
|
-
unless res.down_payload.nil?
|
25
|
-
res.resp = res.down_payload.deep_stringify_keys
|
23
|
+
if res
|
24
|
+
res.resp ||= res.down_payload
|
26
25
|
res.down_payload = nil
|
26
|
+
else
|
27
|
+
res = action.up(opts)
|
27
28
|
end
|
28
29
|
assign_and_persist(res, action)
|
29
30
|
end
|
30
31
|
|
31
|
-
def call_up_meth_on_action(action, opts)
|
32
|
-
res = action.up(opts)
|
33
|
-
res.down_payload&.deep_stringify_keys!
|
34
|
-
action.down_payload = res.down_payload
|
35
|
-
assign_and_persist(res, action)
|
36
|
-
end
|
37
|
-
|
38
32
|
def assign_and_persist(res, action)
|
33
|
+
action.down_payload = res.down_payload&.deep_stringify_keys!
|
39
34
|
if res.ok
|
40
35
|
assign_and_persist_for_ok(res, action)
|
41
36
|
elsif res.save_failed?
|
42
37
|
assign_and_persist_for_failed(res, action)
|
38
|
+
else
|
39
|
+
action.destroy
|
43
40
|
end
|
44
|
-
res.action ||= action
|
45
41
|
res
|
46
42
|
end
|
47
43
|
|
48
|
-
def assign_and_persist_common(res, action)
|
49
|
-
sanitize(action)
|
50
|
-
action.up_result = res.up_result
|
51
|
-
end
|
52
|
-
|
53
44
|
def assign_and_persist_for_ok(res, action)
|
54
|
-
|
45
|
+
action.up_result = res.up_result
|
46
|
+
res.action = action.tap(&:save!)
|
55
47
|
res.nested&.each { |nested_res| action.rdux_actions << nested_res.action }
|
56
|
-
action.save!
|
57
48
|
end
|
58
49
|
|
59
50
|
def assign_and_persist_for_failed(res, action)
|
60
|
-
|
61
|
-
action.up_result ||= res.resp
|
51
|
+
action.up_result = res.up_result
|
62
52
|
res.action = action.to_failed_action.tap(&:save!)
|
63
|
-
|
53
|
+
action.destroy
|
54
|
+
assign_nested_responses_to_failed_action(res.action, res.nested) if res.nested
|
64
55
|
end
|
65
56
|
|
66
57
|
def assign_nested_responses_to_failed_action(failed_action, nested)
|
@@ -76,6 +67,7 @@ module Rdux
|
|
76
67
|
def sanitize(action)
|
77
68
|
up_payload_sanitized = Sanitize.call(action.up_payload)
|
78
69
|
action.up_payload_sanitized = action.up_payload != up_payload_sanitized
|
70
|
+
action.up_payload_unsanitized = action.up_payload if action.up_payload_sanitized
|
79
71
|
action.up_payload = up_payload_sanitized
|
80
72
|
end
|
81
73
|
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.
|
4
|
+
version: 0.5.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: 2023-
|
11
|
+
date: 2023-12-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -131,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
131
131
|
- !ruby/object:Gem::Version
|
132
132
|
version: '0'
|
133
133
|
requirements: []
|
134
|
-
rubygems_version: 3.4.
|
134
|
+
rubygems_version: 3.4.21
|
135
135
|
signing_key:
|
136
136
|
specification_version: 4
|
137
137
|
summary: Rdux adds a new layer to Rails apps - actions.
|