zen-service 2.0.0 → 2.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 +4 -4
- data/README.md +3 -1
- data/lib/zen/service/plugins/callable.rb +0 -2
- data/lib/zen/service/plugins/persisted_result.rb +8 -4
- data/lib/zen/service/plugins/pluggable.rb +11 -3
- data/lib/zen/service/plugins/result_yielding.rb +0 -2
- data/lib/zen/service/plugins.rb +14 -8
- data/lib/zen/service/version.rb +1 -1
- data/lib/zen/service.rb +0 -2
- 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: 83f9ef4ebaca920508cb7aa96f3ce4eea6b899338b000c5a38edc6cacf342473
|
|
4
|
+
data.tar.gz: 86a27632c1fc83f7ba7c735bea83c41a1b0d9e52b2d546bfdd3054e4766c447d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 755c8e023bed8067af7fd509018ff8a001cb5618cde43fc00aa6b0244165482d58fadea79becc7b4ebb9f6a1e87aef9d9901aebd54e2218390553c2fcd71edbc
|
|
7
|
+
data.tar.gz: 55ae83ddff091119dff6b1448e37e704dcdf39cdc616fcc11b51cccd3c979113e41df8396c1cb5688c459dcc3002534ea2f512c54815a3ceecf85cc74e89d8b5
|
data/README.md
CHANGED
|
@@ -98,7 +98,9 @@ simplicity.
|
|
|
98
98
|
However, `zen-service` still provides a couple of helpfull plugins out-of-the-box:
|
|
99
99
|
|
|
100
100
|
- `:persisted_result` - provides `#result` method that returns value of the latest `#call`
|
|
101
|
-
method call. Also provides `#called?` helper method.
|
|
101
|
+
method call. Also provides `#called?` helper method. Supports `call_unless_called` option.
|
|
102
|
+
When set to `true`, calling `service.result` method will call `#call` method if it has
|
|
103
|
+
not yet been called. Default value is `false`.
|
|
102
104
|
|
|
103
105
|
- `:result_yielding` - can be used in junction with nested service calls to result with
|
|
104
106
|
block-provided value instead of nested service `call` return value. For example:
|
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "ostruct"
|
|
4
|
-
|
|
5
3
|
module Zen
|
|
6
4
|
module Service::Plugins
|
|
7
5
|
module PersistedResult
|
|
8
6
|
extend Plugin
|
|
9
7
|
|
|
8
|
+
default_options call_unless_called: false
|
|
9
|
+
|
|
10
10
|
module Extension
|
|
11
11
|
def call
|
|
12
12
|
@result = super
|
|
13
13
|
end
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
-
attr_reader :result
|
|
17
|
-
|
|
18
16
|
def initialize(*, **)
|
|
19
17
|
super
|
|
20
18
|
extend(Extension)
|
|
@@ -23,6 +21,12 @@ module Zen
|
|
|
23
21
|
def called?
|
|
24
22
|
defined?(@result)
|
|
25
23
|
end
|
|
24
|
+
|
|
25
|
+
def result
|
|
26
|
+
call if self.class.plugins[:persisted_result].options[:call_unless_called] && !called?
|
|
27
|
+
|
|
28
|
+
@result
|
|
29
|
+
end
|
|
26
30
|
end
|
|
27
31
|
end
|
|
28
32
|
end
|
|
@@ -11,7 +11,7 @@ module Zen
|
|
|
11
11
|
defaults = extension.config[:default_options]
|
|
12
12
|
opts = defaults.merge(opts) unless defaults.nil?
|
|
13
13
|
|
|
14
|
-
if
|
|
14
|
+
if service_plugins.key?(name)
|
|
15
15
|
extension.configure(self, **opts, &block) if extension.respond_to?(:configure)
|
|
16
16
|
return extension
|
|
17
17
|
end
|
|
@@ -23,8 +23,16 @@ module Zen
|
|
|
23
23
|
plugins.key?(name)
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
+
def service_plugins
|
|
27
|
+
@service_plugins ||= {}
|
|
28
|
+
end
|
|
29
|
+
|
|
26
30
|
def plugins
|
|
27
|
-
|
|
31
|
+
ancestors
|
|
32
|
+
.select { |klass| klass <= ::Zen::Service }
|
|
33
|
+
.flat_map(&:service_plugins)
|
|
34
|
+
.reverse
|
|
35
|
+
.reduce(&:merge)
|
|
28
36
|
end
|
|
29
37
|
alias extensions plugins
|
|
30
38
|
|
|
@@ -37,7 +45,7 @@ module Zen
|
|
|
37
45
|
extension.used(self, **opts, &block) if extension.respond_to?(:used)
|
|
38
46
|
extension.configure(self, **opts, &block) if extension.respond_to?(:configure)
|
|
39
47
|
|
|
40
|
-
|
|
48
|
+
service_plugins[name] = Reflection.new(extension, opts.merge(block:))
|
|
41
49
|
|
|
42
50
|
extension
|
|
43
51
|
end
|
data/lib/zen/service/plugins.rb
CHANGED
|
@@ -8,15 +8,21 @@ module Zen
|
|
|
8
8
|
plugins[name] || raise("extension `#{name}` is not registered")
|
|
9
9
|
end
|
|
10
10
|
|
|
11
|
-
def self.register(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
if (old_name = plugins.key(extension))
|
|
16
|
-
plugins.delete(old_name)
|
|
17
|
-
else
|
|
18
|
-
extension
|
|
11
|
+
def self.register(name_or_hash, extension = nil)
|
|
12
|
+
if name_or_hash.is_a?(Hash)
|
|
13
|
+
name_or_hash.each do |name, ext|
|
|
14
|
+
register(name, ext)
|
|
19
15
|
end
|
|
16
|
+
else
|
|
17
|
+
raise ArgumentError, "extension must be given" if extension.nil?
|
|
18
|
+
|
|
19
|
+
plugins[name_or_hash] =
|
|
20
|
+
if (old_name = plugins.key(extension))
|
|
21
|
+
plugins.delete(old_name)
|
|
22
|
+
else
|
|
23
|
+
extension
|
|
24
|
+
end
|
|
25
|
+
end
|
|
20
26
|
end
|
|
21
27
|
|
|
22
28
|
def self.plugins
|
data/lib/zen/service/version.rb
CHANGED
data/lib/zen/service.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: zen-service
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Artem Kuzko
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2025-12-
|
|
11
|
+
date: 2025-12-20 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: pry
|