facio 0.1.16 → 0.1.17

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: d340a59ed3ac5e635d5eb4f0ffd36dba7c9f48ac6e46eb2ef9f3b9d1b83c01b2
4
- data.tar.gz: 056cdd8cbc0b68be37615c9077510ec506a7ac89fb18f27072ff9f8a63ad61e9
3
+ metadata.gz: bfe5c1e2738690ffb95ea5b7c301f0929568ee644dc30b566c15bdb0a7a54d65
4
+ data.tar.gz: 39d526d6b864d59834f243dad254658a371da178ccc048c2e6dfdbc4fa8c9d7d
5
5
  SHA512:
6
- metadata.gz: 10e473dbee725d09d3ae2a661aaaaf865941452a49131206b5828401ab0a3d62f45a2d378b7b56a796d981d4d4803c4848399b90f75136b2446beb0fa3cd6584
7
- data.tar.gz: 7178d9571ad1ef46ef5ecc0bdef1574871b872476ff2392cc54da2ddc77abb92b7f7bb76770ff6eb1b6ac9dc164a91204c4f84e0a599ff8b77de34537d01925f
6
+ metadata.gz: d20726eb3af4004911836e38490b4342a81c5e767006d73adc23727b7f64d50b9db18dba143afaf443b84b6a64c3abab759284ac7e84f19c12a6b6cee492c682
7
+ data.tar.gz: a47767c1d0403123bbb5001524613ca1ae459466c32f497602aa62eb60854f9d4eb0d0a7041d923b79c10f4bc1c207818d19057d4ecedb6be2deef608e3eeeb4
data/README.md CHANGED
@@ -4,7 +4,7 @@ Command pattern for Ruby (on Rails). From Wikipedia:
4
4
 
5
5
  > In object-oriented programming, the command pattern is a behavioral design pattern in which an object is used to encapsulate all information needed to perform an action or trigger an event at a later time. This information includes the method name, the object that owns the method and values for the method parameters.
6
6
 
7
- It basically allows you to encapsulate bits of code for a specific purpose. It's also nicely explained by [refactoring.guru](https://refactoring.guru/design-patterns/command)
7
+ It basically allows you to encapsulate bits of code for a specific purpose. It's also nicely explained by [refactoring.guru](https://refactoring.guru/design-patterns/command). It also makes these easier to test in isolation, not cluttering your model and/or controller.
8
8
 
9
9
  ## Installation
10
10
 
@@ -2,36 +2,42 @@ module Callbacks
2
2
  extend ActiveSupport::Concern
3
3
 
4
4
  included do
5
- around_perform do |job, block|
5
+ around_perform :_facio_set_context_and_result_for_perform
6
+ around_enqueue :_facio_set_context_for_enqueue
7
+
8
+ private
9
+
10
+ def _facio_set_context_and_result_for_perform
6
11
  @context = self.class.context_class.new(arguments.first)
7
12
  @result = self.class.result_class&.new
8
13
  @performed = false
9
14
 
10
15
  if @context.valid?
11
16
  result = nil
17
+ @performed = true
18
+
12
19
  if transactional && defined?(ActiveRecord::Base)
13
20
  ActiveRecord::Base.transaction(requires_new: true) do
14
- result = block.call
21
+ result = yield
15
22
  # This will only rollback the changes of the service, SILENTLY, however the context will be failed? already.
16
23
  # This is the most close to expected behaviour this can get.
17
24
  raise ActiveRecord::Rollback if context.failed?
18
25
  end
19
26
  else
20
- result = block.call
27
+ result = yield
21
28
  end
22
29
 
23
- @performed = true
24
30
  # Purely as a convenience, but also to enforce a standard
25
31
  context.result ||= result if @result.nil?
26
32
  end
27
33
  end
28
34
 
29
- around_enqueue do |job, block|
35
+ def _facio_set_context_for_enqueue
30
36
  @performed = false
31
37
  @context = self.class.context_class.new(arguments.first)
32
38
  @result = self.class.result_class&.new
33
39
 
34
- block.call if @context.valid?
40
+ yield if @context.valid?
35
41
  end
36
42
  end
37
43
  end
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.16"
4
+ VERSION = "0.1.17"
5
5
  end
data/mise.toml CHANGED
@@ -1,2 +1,2 @@
1
1
  [tools]
2
- ruby = "3.4.7"
2
+ ruby = "4.0.1"
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.16
4
+ version: 0.1.17
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-16 00:00:00.000000000 Z
11
+ date: 2026-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack