yaso 1.0.0 → 1.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/Gemfile.lock +1 -1
- data/README.md +1 -1
- data/benchmark/step/benchmark.rb +10 -10
- data/lib/yaso/context.rb +1 -4
- data/lib/yaso/invokable.rb +11 -3
- data/lib/yaso/logic/step_builder.rb +2 -6
- data/lib/yaso/service.rb +1 -4
- data/lib/yaso/stepable.rb +0 -4
- data/lib/yaso/version.rb +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: e562bf748ebc163661813eed594c0abdecc4bf2027f68cb3cfb389464066fd82
|
4
|
+
data.tar.gz: 4fd59f39375881b4c9b04442405318a82f58792a7d759edfef302cc25b2b3107
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bb6e535a13645a6831364324459a76808affb02715d6f6f173d3e913058befa03bd7af75828bdf627e54d8daccf060e7d0fae693dda4b65c224573c0afb0a7a5
|
7
|
+
data.tar.gz: '0987332c9e58733298f8b7c5c164222d91835492afb2107fb7bffbfaaeeec2b3234d2f34fdf57b6b0fcc7055b95669a42b803449f351f4c8d243a00147ca4a9d'
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Yaso
|
2
2
|
[](https://github.com/Ar2emis/yaso/actions/workflows/main.yml)  [](https://github.com/Ar2emis/yaso/blob/master/LICENSE.txt)
|
3
3
|
|
4
|
-
That's my (Yet Another) ServiceObject pattern implementation. I
|
4
|
+
That's my (Yet Another) ServiceObject pattern implementation. I made it fast ([the fastest actually](https://github.com/Ar2emis/yaso/wiki/Benchmarks)) and simple to use.
|
5
5
|
I was inspired by those alternatives and I hope this will encourage them to be even better:
|
6
6
|
- [Trailblazer](https://github.com/trailblazer/trailblazer)
|
7
7
|
- [Decouplio](https://github.com/differencialx/decouplio)
|
data/benchmark/step/benchmark.rb
CHANGED
@@ -7,11 +7,11 @@ Benchmark.ips do |x|
|
|
7
7
|
x.config(stats: :bootstrap, confidence: 95)
|
8
8
|
|
9
9
|
x.report('Pure Service') { PureStepsService.call }
|
10
|
-
x.report('
|
11
|
-
x.report('
|
12
|
-
x.report('Interactor
|
13
|
-
x.report('ActiveInteraction
|
14
|
-
x.report('Trailblazer
|
10
|
+
x.report('Yaso') { YasoStepsService.call }
|
11
|
+
x.report('Decouplio') { DecouplioStepsService.call } unless RUBY_VERSION.include?('2.5')
|
12
|
+
x.report('Interactor') { InteractorStepsService.call }
|
13
|
+
x.report('ActiveInteraction') { ActiveInteractionStepsService.run }
|
14
|
+
x.report('Trailblazer') { TrailblazerStepsService.call }
|
15
15
|
|
16
16
|
x.compare!
|
17
17
|
end
|
@@ -21,11 +21,11 @@ Benchmark.ips do |x|
|
|
21
21
|
x.config(stats: :bootstrap, confidence: 95)
|
22
22
|
|
23
23
|
x.report('Pure Service') { PureCallablesService.call }
|
24
|
-
x.report('
|
25
|
-
x.report('
|
26
|
-
x.report('Interactor
|
27
|
-
x.report('ActiveInteraction
|
28
|
-
x.report('Trailblazer
|
24
|
+
x.report('Yaso') { YasoCallablesService.call }
|
25
|
+
x.report('Decouplio') { DecouplioCallablesService.call } unless RUBY_VERSION.include?('2.5')
|
26
|
+
x.report('Interactor') { InteractorCallablesService.call }
|
27
|
+
x.report('ActiveInteraction') { ActiveInteractionCallablesService.run }
|
28
|
+
x.report('Trailblazer') { TrailblazerCallablesService.call }
|
29
29
|
|
30
30
|
x.compare!
|
31
31
|
end
|
data/lib/yaso/context.rb
CHANGED
data/lib/yaso/invokable.rb
CHANGED
@@ -10,9 +10,9 @@ module Yaso
|
|
10
10
|
def call(object, options: {}, **)
|
11
11
|
type = object_type(object)
|
12
12
|
invokable = case type
|
13
|
-
when YASO then
|
14
|
-
when CALLABLE then
|
15
|
-
else
|
13
|
+
when YASO then proc { |context, _| object.call(context.clone).success? }
|
14
|
+
when CALLABLE then proc { |context, _, &block| object.call(context, **options, &block) }
|
15
|
+
else method_invokable(object)
|
16
16
|
end
|
17
17
|
[type, invokable]
|
18
18
|
end
|
@@ -24,6 +24,14 @@ module Yaso
|
|
24
24
|
|
25
25
|
object < ::Yaso::Service ? Invokable::YASO : Invokable::CALLABLE
|
26
26
|
end
|
27
|
+
|
28
|
+
def method_invokable(object)
|
29
|
+
instance_eval <<-RUBY, __FILE__, __LINE__ + 1
|
30
|
+
proc { |context, instance, &block| # proc { |context, instance, &block|
|
31
|
+
instance.#{object}(context, **context.data, &block) # instance.<method_name>(context, **context.data, &block)
|
32
|
+
} # }
|
33
|
+
RUBY
|
34
|
+
end
|
27
35
|
end
|
28
36
|
end
|
29
37
|
end
|
@@ -37,11 +37,10 @@ module Yaso
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def build_method(name, &block)
|
40
|
-
return name if @klass.method_defined?(name)
|
40
|
+
return name if @klass.method_defined?(name)
|
41
41
|
raise StepIsNotImplementedError.new(@klass, name) unless block
|
42
42
|
|
43
43
|
@klass.define_method(name, &block)
|
44
|
-
@klass.instance_eval { private name }
|
45
44
|
end
|
46
45
|
|
47
46
|
def build_wrapper(&block)
|
@@ -53,10 +52,7 @@ module Yaso
|
|
53
52
|
|
54
53
|
def build_wrapper_call(wrapper_class, service_class)
|
55
54
|
wrapper_class.define_singleton_method(:call) do |context, instance|
|
56
|
-
|
57
|
-
@entry = Logic::Classic.call(service_class, steps)
|
58
|
-
clear_steps!
|
59
|
-
end
|
55
|
+
@entry ||= Logic::Classic.call(service_class, steps)
|
60
56
|
step = @entry
|
61
57
|
step = step.call(context, instance) while step
|
62
58
|
context
|
data/lib/yaso/service.rb
CHANGED
@@ -6,10 +6,7 @@ module Yaso
|
|
6
6
|
|
7
7
|
def self.call(context = {})
|
8
8
|
context = context.is_a?(Context) ? context : Context.new(context)
|
9
|
-
|
10
|
-
@entry = Logic::Classic.call(self, steps)
|
11
|
-
clear_steps!
|
12
|
-
end
|
9
|
+
@entry ||= Logic::Classic.call(self, steps)
|
13
10
|
step = @entry
|
14
11
|
instance = new
|
15
12
|
step = step.call(context, instance) while step
|
data/lib/yaso/stepable.rb
CHANGED
@@ -6,10 +6,6 @@ module Yaso
|
|
6
6
|
@steps ||= []
|
7
7
|
end
|
8
8
|
|
9
|
-
def clear_steps!
|
10
|
-
remove_instance_variable(:@steps)
|
11
|
-
end
|
12
|
-
|
13
9
|
%i[step pass failure wrap switch].each do |category|
|
14
10
|
define_method(category) do |object, options = {}, &block|
|
15
11
|
raise InvalidFirstStepError, category if category == :failure && steps.empty?
|
data/lib/yaso/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yaso
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Artem Shevchenko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-08-
|
11
|
+
date: 2022-08-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffaker
|