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 +4 -4
- data/README.md +1 -1
- data/lib/facio/concerns/callbacks.rb +12 -6
- data/lib/facio/version.rb +1 -1
- data/mise.toml +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bfe5c1e2738690ffb95ea5b7c301f0929568ee644dc30b566c15bdb0a7a54d65
|
|
4
|
+
data.tar.gz: 39d526d6b864d59834f243dad254658a371da178ccc048c2e6dfdbc4fa8c9d7d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
|
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 =
|
|
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 =
|
|
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
|
-
|
|
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
|
-
|
|
40
|
+
yield if @context.valid?
|
|
35
41
|
end
|
|
36
42
|
end
|
|
37
43
|
end
|
data/lib/facio/version.rb
CHANGED
data/mise.toml
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
[tools]
|
|
2
|
-
ruby = "
|
|
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.
|
|
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-
|
|
11
|
+
date: 2026-01-19 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: actionpack
|