facio 0.1.12 → 0.1.14

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: 99ced5156dfed002640561b1846a1b2d82b8e23609950263471db3b96bd4d71b
4
- data.tar.gz: b8116348cfa5a5d0dc90b31eed2fddf8631f39b1b1ac284710e0e501bfed6873
3
+ metadata.gz: 10945c2001644123fab9a3fd062a9e453cb4985c75e4ade7aecc231c8fa85bd0
4
+ data.tar.gz: 39515646a753db54c9512ac7523490c9425e145dd2625a97ad89234369049216
5
5
  SHA512:
6
- metadata.gz: 96021902f31a30839e09ecaa278cc904f4706f00773917cd22ef18c7fee60b64bd993d982b83f9dbb2faedb7387195327ac6b50b8268cf98534a56d7f6958462
7
- data.tar.gz: a95fd855b90eec2e46cbefeca94d5cfde676344b7241adffb9360f04bbb876a013954e4c791710bff82698405acbc73710997966d761fe72212415857331fef3
6
+ metadata.gz: cd61d66feb81d6f7369dcc542bb39edb4d330252aafbf77b215790f7d0de04af0d33cb68720e475fe0b53dde3c12d1e3e8e70e9417be3b183e3ca7d9a67265e3
7
+ data.tar.gz: 7cb6c5fb5866a4634f60bfa8a9a2e816dfb21c4ddafa6b862bef972ff4c3cb5adbbc57195a705f4f2f2daf20c2cc505f3eb9f556991606e258e1df0b81463030
@@ -1,8 +1,32 @@
1
1
  module Execution
2
2
  extend ActiveSupport::Concern
3
3
 
4
+ # Facio doesn't support arguments in the perform method, that's done with the context object.
5
+ # This is why we override perform here.
4
6
  def facio_perform_with_arguments(*args)
5
- facio_perform_without_arguments
7
+ @context = self.class.context_class.new(arguments.first)
8
+ @result = self.class.result_class&.new
9
+ @performed = false
10
+
11
+ if @context.valid?
12
+ result = nil
13
+ if transactional && defined?(ActiveRecord::Base)
14
+ ActiveRecord::Base.transaction(requires_new: true) do
15
+ # result = block.call
16
+ result = facio_perform_without_arguments
17
+ # This will only rollback the changes of the service, SILENTLY, however the context will be failed? already.
18
+ # This is the most close to expected behaviour this can get.
19
+ raise ActiveRecord::Rollback if context.failed?
20
+ end
21
+
22
+ else
23
+ result = facio_perform_without_arguments
24
+ end
25
+
26
+ @performed = true
27
+ # Purely as a convenience, but also to enforce a standard
28
+ context.result ||= result if @result.nil?
29
+ end
6
30
  end
7
31
 
8
32
  included do
data/lib/facio/context.rb CHANGED
@@ -8,6 +8,14 @@ module Facio
8
8
  raise Facio::ContextFailure, self
9
9
  end
10
10
 
11
+ def failed?
12
+ errors.any?
13
+ end
14
+
15
+ def success?
16
+ errors.none?
17
+ end
18
+
11
19
  private
12
20
 
13
21
  def merge_errors!(attr, message = :invalid, options = {})
data/lib/facio/service.rb CHANGED
@@ -11,7 +11,6 @@ module Facio
11
11
  include ServiceResult
12
12
  include Transactional
13
13
  include Translations
14
- include Callbacks
15
14
  include Execution
16
15
 
17
16
  class << self
@@ -21,6 +20,19 @@ module Facio
21
20
  job
22
21
  end
23
22
 
23
+ def perform_later(...)
24
+ job = job_or_instantiate(...)
25
+ job.instance_variable_set(:@performed, false)
26
+ job.instance_variable_set(:@context, context_class.new(job.arguments.first))
27
+ job.instance_variable_set(:@result, result_class&.new)
28
+
29
+ enqueue_result = job.enqueue
30
+
31
+ yield job if block_given?
32
+
33
+ enqueue_result
34
+ end
35
+
24
36
  alias_method :perform_now, :perform
25
37
  end
26
38
 
data/lib/facio/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Facio
4
- VERSION = "0.1.12"
4
+ VERSION = "0.1.14"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: facio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.12
4
+ version: 0.1.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom de Grunt
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-01-13 00:00:00.000000000 Z
11
+ date: 2026-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack