rdux 3.0.0 → 3.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7d08bba313e7358c9ab679919bffa752086205e61c3884285da3cca786b1c63e
4
- data.tar.gz: 6aa632159bdc20f99fb82686374bc0cf72359a08219485168d5be3fe2e4441bc
3
+ metadata.gz: 06fb78e021c9f1647140a5f4cb71922f66f1ae7ba6afff88b90e7b9c7652c496
4
+ data.tar.gz: 2982c9a2492d22c4ad7f5d05eb33fe7f9dc5af4e31fdefb79e759901ceaf147a
5
5
  SHA512:
6
- metadata.gz: 6420dd96aa5f4c5f51e8bd4ef1d5b689892a7693405b5f27045bbaa5af57a8c09237a9213eb30a85907d7fd7bd4af926c85494843ff32d0330f36dc39c8e375e
7
- data.tar.gz: 873fe11556fff66df5290cb3f9aaa9414c39d28299b2f8a1a207a5351853de70e5801fd8d654d9022d1864a243eab4b12f2727be6d866ce7731877d96727a712
6
+ metadata.gz: e1743dbffc779a50010de16d3eccf6038ddc6ffa5646bc75fc3cabc8e3931f239f9609e8a1523f92df1b83340eb0d131b06818b0b80f774f207f6182ffe81d5b
7
+ data.tar.gz: 11ffa6637ccf91b868ba80800e60d0ddf7e718f0e441b29a09fbb6cb383bc37da77ebb35605aea1e935c610354386656a595889a863041a655a3c25ca32a821e
data/README.md CHANGED
@@ -150,11 +150,7 @@ Definition:
150
150
 
151
151
  ```ruby
152
152
  module Rdux
153
- Result = Struct.new(:ok, :val, :result, :save, :nested, :action) do
154
- def save_failed?
155
- ok == false && save ? true : false
156
- end
157
- end
153
+ Result = Struct.new(:ok, :val, :result, :save, :nested, :action)
158
154
  end
159
155
  ```
160
156
 
data/Rakefile CHANGED
@@ -6,16 +6,6 @@ rescue LoadError
6
6
  puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
7
7
  end
8
8
 
9
- require 'rdoc/task'
10
-
11
- RDoc::Task.new(:rdoc) do |rdoc|
12
- rdoc.rdoc_dir = 'rdoc'
13
- rdoc.title = 'Rdux'
14
- rdoc.options << '--line-numbers'
15
- rdoc.rdoc_files.include('README.md')
16
- rdoc.rdoc_files.include('lib/**/*.rb')
17
- end
18
-
19
9
  require 'bundler/gem_tasks'
20
10
 
21
11
  require 'rake/testtask'
@@ -26,6 +16,4 @@ Rake::TestTask.new(:test) do |t|
26
16
  t.verbose = false
27
17
  end
28
18
 
29
- Dir.glob('lib/tasks/**/*.rake').each { |r| import r }
30
-
31
19
  task default: :test
@@ -16,6 +16,7 @@ module Rdux
16
16
  scope :ok, ->(val = true) { where(ok: val) }
17
17
  scope :failed, -> { where(ok: false) }
18
18
 
19
+ # has_attribute? keeps Rdux working when the rdux_process_id migration has not been run
19
20
  def process_defined?
20
21
  has_attribute?(:rdux_process_id) && rdux_process_id
21
22
  end
@@ -24,8 +25,10 @@ module Rdux
24
25
  return false if performed?
25
26
  return false if only_sanitized_payload?
26
27
 
27
- opts.merge!(action: self)
28
- perform_action(opts)
28
+ performer = name.to_s.constantize
29
+ return performer.call(safe_payload) if performer.method(:call).arity == 1
30
+
31
+ performer.call(safe_payload, opts.merge(action: self))
29
32
  end
30
33
 
31
34
  private
@@ -33,16 +36,5 @@ module Rdux
33
36
  def performed?
34
37
  !ok.nil?
35
38
  end
36
-
37
- def perform_action(opts)
38
- performer = name.to_s.constantize
39
- return if performer.nil?
40
-
41
- if performer.method(:call).arity.abs == 2
42
- performer.call(safe_payload, opts)
43
- else
44
- performer.call(safe_payload)
45
- end
46
- end
47
39
  end
48
40
  end
@@ -13,6 +13,7 @@ module Rdux
13
13
  action = Action.new(name:, payload:, meta:)
14
14
  action.process = process if process
15
15
  Sanitize.call(action)
16
+ action.save!
16
17
  action
17
18
  end
18
19
 
@@ -61,14 +62,13 @@ module Rdux
61
62
  end
62
63
 
63
64
  def handle_exception(exc, action)
64
- raise(action.destroy && exc) if ENV['RDUX_DEV']
65
+ if ENV['RDUX_DEV']
66
+ action.destroy
67
+ raise exc
68
+ end
65
69
 
66
70
  action.ok = false
67
- action.result ||= {}
68
- action.result.merge!({ 'Exception' => {
69
- class: exc.class.name,
70
- message: exc.message
71
- } })
71
+ action.result = (action.result || {}).merge('Exception' => { class: exc.class.name, message: exc.message })
72
72
  action.save!
73
73
  raise exc
74
74
  end
@@ -5,6 +5,7 @@ module Rdux
5
5
  def start(performer, payload)
6
6
  process = Process.new(name: performer, payload:)
7
7
  Sanitize.call(process)
8
+ process.save!
8
9
  res = process.resume(Rdux::Result[ok: true, val: :start])
9
10
  process.update!(ok: res.ok) unless res.ok.nil?
10
11
  Result[ok: res.ok, val: { process: }]
data/lib/rdux/result.rb CHANGED
@@ -1,9 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rdux
4
- Result = Struct.new(:ok, :val, :result, :save, :nested, :action) do
5
- def save_failed?
6
- ok == false && save ? true : false
7
- end
8
- end
4
+ Result = Struct.new(:ok, :val, :result, :save, :nested, :action)
9
5
  end
data/lib/rdux/sanitize.rb CHANGED
@@ -8,7 +8,6 @@ module Rdux
8
8
  aro.payload_sanitized = aro.payload != payload_sanitized
9
9
  aro.payload_unsanitized = aro.payload if aro.payload_sanitized
10
10
  aro.payload = payload_sanitized
11
- aro.save! if aro.changed?
12
11
  end
13
12
  end
14
13
  end
data/lib/rdux/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rdux
4
- VERSION = '3.0.0'
4
+ VERSION = '3.1.0'
5
5
  end
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: 3.0.0
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zbigniew Humeniuk