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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 303afa88aa6e5fbe4a133816cabd2fb072b3c0c69e9325f3213329e2838722fe
4
- data.tar.gz: 68c158407e5c0443091ca1378b0c99ac24da9a2abc7072398e8eae9f81dffc93
3
+ metadata.gz: e562bf748ebc163661813eed594c0abdecc4bf2027f68cb3cfb389464066fd82
4
+ data.tar.gz: 4fd59f39375881b4c9b04442405318a82f58792a7d759edfef302cc25b2b3107
5
5
  SHA512:
6
- metadata.gz: 47b055c354a17ba2c0c21ed306c97da120b1d3b2511245c6e9a074e4ecd6126f6ae1325ab6f5f492f93deb7ddfedc9f07e40e149d20d04b49c8c700fc505665e
7
- data.tar.gz: 25fb9bc3037fd49e2b48f466098d0299f4bcaa569b320d76dbf351dbc2cb8e665c50c82bb06411223a5dbd327bc2191f24575c8a744037457bc5c07e64f36ad8
6
+ metadata.gz: bb6e535a13645a6831364324459a76808affb02715d6f6f173d3e913058befa03bd7af75828bdf627e54d8daccf060e7d0fae693dda4b65c224573c0afb0a7a5
7
+ data.tar.gz: '0987332c9e58733298f8b7c5c164222d91835492afb2107fb7bffbfaaeeec2b3234d2f34fdf57b6b0fcc7055b95669a42b803449f351f4c8d243a00147ca4a9d'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- yaso (1.0.0)
4
+ yaso (1.1.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Yaso
2
2
  [![Ruby](https://github.com/Ar2emis/yaso/actions/workflows/main.yml/badge.svg?branch=master)](https://github.com/Ar2emis/yaso/actions/workflows/main.yml) ![gem](https://img.shields.io/gem/v/yaso) [![GitHub license](https://img.shields.io/github/license/Ar2emis/yaso)](https://github.com/Ar2emis/yaso/blob/master/LICENSE.txt)
3
3
 
4
- That's my (Yet Another) ServiceObject pattern implementation. I tried to make it fast (the fastest actually) and simple to use.
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)
@@ -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('Decouplio Service') { DecouplioStepsService.call } unless RUBY_VERSION.include?('2.5')
11
- x.report('Yaso Service') { YasoStepsService.call }
12
- x.report('Interactor Service') { InteractorStepsService.call }
13
- x.report('ActiveInteraction Service') { ActiveInteractionStepsService.run }
14
- x.report('Trailblazer Service') { TrailblazerStepsService.call }
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('Decouplio Service') { DecouplioCallablesService.call } unless RUBY_VERSION.include?('2.5')
25
- x.report('Yaso Service') { YasoCallablesService.call }
26
- x.report('Interactor Service') { InteractorCallablesService.call }
27
- x.report('ActiveInteraction Service') { ActiveInteractionCallablesService.run }
28
- x.report('Trailblazer Service') { TrailblazerCallablesService.call }
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
@@ -3,6 +3,7 @@
3
3
  module Yaso
4
4
  class Context
5
5
  attr_writer :success
6
+ attr_reader :data
6
7
 
7
8
  def initialize(kwargs)
8
9
  @success = true
@@ -21,10 +22,6 @@ module Yaso
21
22
  @data.dup
22
23
  end
23
24
 
24
- def to_h!
25
- @data
26
- end
27
-
28
25
  def success?
29
26
  @success
30
27
  end
@@ -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 ->(context, _) { object.call(context.clone).success? }
14
- when CALLABLE then ->(context, _, &block) { object.call(context, **options, &block) }
15
- else ->(context, instance, &block) { instance.send(object, context, **context.to_h!, &block) }
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) || @klass.private_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
- unless @entry
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
- unless @entry
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Yaso
4
- VERSION = '1.0.0'
4
+ VERSION = '1.1.0'
5
5
  end
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.0.0
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-20 00:00:00.000000000 Z
11
+ date: 2022-08-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffaker