service_operator 0.2.2 → 0.2.3

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: bbf2f3da24a3a69f4bdb08d13390973c846a732b8b15a46c0857cbf3c638e002
4
- data.tar.gz: 9f9b1b3cd9b7bc9da0d093879aaff4f9b7c94d86bec63a46e640e05e24c17ce1
3
+ metadata.gz: 83016688ff1eb93f3668912441267fe9ee1dc49554d4fbd21d3898c81147e38f
4
+ data.tar.gz: 043a244c0a0526e97622a610ef159b17ea956030e6d0968b34072353b1a7afd7
5
5
  SHA512:
6
- metadata.gz: 1d7ff1d4a0ed6b5102b94c4b852b59afc378596ab9c5f2280407992568b0d5b626c1d143b81dbf6ebfc9e99e628a1001a4c68e26c65c622d51f1f7cd2346c8fc
7
- data.tar.gz: 19f1f61c75495088b1a6e62d89a8c7df6334a8a7f4c7d93b06c7da9bc74bb17a38e7a46ffd37ddf570ae7f8e494413f65a127b4091c351853550bf3e176082db
6
+ metadata.gz: 37543a1d1c319fd3b6bae20d850f769a7aa50171830772b6fe1ef07a55e32702416e816b2cf0d3b4c1384fd4e165d819330217c8d001f382d272331bc226f92d
7
+ data.tar.gz: 97673d31c36181d2d0eba27336e2347c55687f4cd68909700a3cd890b6c4d993ae66eacd9d66a9cbadf22a30db1702d7af6dde64226f9bb16c76e5e69384d2d3
data/.rubocop.yml CHANGED
@@ -23,6 +23,9 @@ Style/Documentation:
23
23
  Style/BlockDelimiters:
24
24
  Enabled: false
25
25
 
26
+ Style/ModuleFunction:
27
+ Enabled: false
28
+
26
29
  Layout/LineLength:
27
30
  Max: 120
28
31
 
data/CHANGELOG.md CHANGED
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5
5
  and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [0.2.3] - 2022-09-18
8
+ ### Modified
9
+ - changing configuration
10
+
7
11
  ## [0.2.2] - 2022-09-12
8
12
  ### Modified
9
13
  - generating arguments for method call in Step
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- service_operator (0.2.2)
4
+ service_operator (0.2.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -15,15 +15,21 @@ $ bundle install
15
15
 
16
16
  ## Usage
17
17
 
18
- First you need create ApplicationOperator - basis class for your operators
18
+ ### Initializer
19
+
20
+ Add configuration to config/initializers/service_operator.rb:
19
21
  ```ruby
20
- class ApplicationOperator
21
- include ServiceOperator
22
+ ServiceOperator.configure do |config|
23
+ config.call_parameters_method_name = :call_parameters
24
+ end
25
+ ```
22
26
 
23
- # configuration
24
- configure do |config|
25
- config.call_parameters_method_name = :call_parameters
26
- end
27
+ ### ApplicationOperator
28
+
29
+ You can create ApplicationOperator - basis class for your operators
30
+ ```ruby
31
+ class ApplicationOperator
32
+ include ServiceOperator::Helpers
27
33
 
28
34
  private
29
35
 
@@ -9,7 +9,7 @@ module ServiceOperator
9
9
  @call_method_name = :call
10
10
 
11
11
  # Operator tries to run this method on step's service for fetching arguments list.
12
- @call_parameters_method_name = :call
12
+ @call_parameters_method_name = nil
13
13
 
14
14
  # Operator tries to run this method on step's service for checking failure status.
15
15
  @failure_method_name = nil
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'steps'
4
+ require_relative 'step'
5
+ require_relative 'hooks'
6
+ require_relative 'context'
7
+
8
+ module ServiceOperator
9
+ module Helpers
10
+ def self.included(base)
11
+ base.class_eval do
12
+ extend ClassMethods
13
+ include Steps
14
+ include Hooks
15
+
16
+ attr_reader :context
17
+ end
18
+ end
19
+
20
+ module ClassMethods
21
+ def required_params
22
+ @required_params ||= []
23
+ end
24
+
25
+ # Examples
26
+ #
27
+ # class MyOperator
28
+ # include ServiceOperator::Helpers
29
+ #
30
+ # required_context :week
31
+ # end
32
+ #
33
+ def required_context(*args)
34
+ @required_params = args.flatten
35
+ end
36
+
37
+ def call(args={})
38
+ new(**args).call
39
+ end
40
+ end
41
+
42
+ def initialize(args={})
43
+ @context = Context.build(args)
44
+ @context.validate(required_params: self.class.required_params)
45
+ end
46
+
47
+ def call
48
+ with_hooks { run_steps(self.class.steps) }
49
+ context
50
+ # rescue catches errors in before and after steps and stops execution
51
+ rescue StandardError
52
+ context
53
+ end
54
+
55
+ def configuration
56
+ ServiceOperator.instance
57
+ end
58
+ end
59
+ end
@@ -16,7 +16,7 @@ module ServiceOperator
16
16
  # Examples
17
17
  #
18
18
  # class MyOperator
19
- # include ServiceOperator
19
+ # include ServiceOperator::Helpers
20
20
  #
21
21
  # around :use_transaction
22
22
  #
@@ -43,15 +43,23 @@ module ServiceOperator
43
43
  # Then generate hash with these parameters from operator.context.
44
44
  # Then overwrite some of them from step's args.
45
45
  def fetch_service_call_arguments(service_object)
46
- parameters_list =
47
- service_object
48
- .method(@operator.configuration.call_parameters_method_name)
49
- .parameters
50
- return if parameters_list.empty?
46
+ parameters_list = fetch_parameters_list(service_object)
47
+ return if parameters_list.nil? || parameters_list.empty?
51
48
 
52
49
  generate_argument_for_method_call(parameters_list)
53
50
  end
54
51
 
52
+ def fetch_parameters_list(service_object)
53
+ if @operator.configuration.call_parameters_method_name
54
+ service_object
55
+ .public_send(@operator.configuration.call_parameters_method_name)
56
+ else
57
+ service_object
58
+ .method(@operator.configuration.call_method_name)
59
+ .parameters
60
+ end
61
+ end
62
+
55
63
  def generate_argument_for_method_call(parameters_list, positional_arguments=[], keyword_arguments={})
56
64
  parameters_list.each { |type, name|
57
65
  case type
@@ -64,7 +72,7 @@ module ServiceOperator
64
72
  end
65
73
 
66
74
  def fetch_value(name)
67
- args[name] ? @operator.send(name) : @operator.context[name]
75
+ args[name] ? @operator.send(args[name]) : @operator.context[name]
68
76
  end
69
77
  end
70
78
  end
@@ -24,7 +24,7 @@ module ServiceOperator
24
24
  # Examples
25
25
  #
26
26
  # class MyOperator
27
- # include ServiceOperator
27
+ # include ServiceOperator::Helpers
28
28
  #
29
29
  # before :set_start_time
30
30
  # before :initial, service: SomeService
@@ -47,7 +47,7 @@ module ServiceOperator
47
47
  # Examples
48
48
  #
49
49
  # class MyOperator
50
- # include ServiceOperator
50
+ # include ServiceOperator::Helpers
51
51
  #
52
52
  # step :set_initiated
53
53
  # step :perform_work, service: AnotherService
@@ -70,7 +70,7 @@ module ServiceOperator
70
70
  # Examples
71
71
  #
72
72
  # class MyOperator
73
- # include ServiceOperator
73
+ # include ServiceOperator::Helpers
74
74
  #
75
75
  # after :set_finish_time
76
76
  # after :finishing, service: SomeService
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ServiceOperator
4
- VERSION = '0.2.2'
4
+ VERSION = '0.2.3'
5
5
  end
@@ -1,75 +1,30 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'service_operator/version'
4
- require_relative 'service_operator/steps'
5
- require_relative 'service_operator/step'
6
- require_relative 'service_operator/hooks'
7
- require_relative 'service_operator/context'
8
- require_relative 'service_operator/configuration'
3
+ require 'service_operator/version'
4
+ require 'service_operator/configuration'
5
+ require 'service_operator/helpers'
9
6
 
10
7
  module ServiceOperator
11
- def self.included(base)
12
- base.class_eval do
13
- extend ClassMethods
14
- include Steps
15
- include Hooks
8
+ extend self
16
9
 
17
- attr_reader :configuration
18
- attr_reader :context
19
- end
10
+ def configuration
11
+ @configuration ||= Configuration.new
20
12
  end
21
13
 
22
- module ClassMethods
23
- def configuration
24
- @configuration ||= Configuration.new
25
- end
26
-
27
- # Examples
28
- #
29
- # class MyOperator
30
- # include ServiceOperator
31
- #
32
- # configure do |config|
33
- # config.call_method_name = :call
34
- # config.call_parameters_method_name = :call
35
- # end
36
- # end
37
- #
38
- def configure
39
- yield(configuration)
40
- end
41
-
42
- def required_params
43
- @required_params ||= []
44
- end
45
-
46
- # Examples
47
- #
48
- # class MyOperator
49
- # include ServiceOperator
50
- #
51
- # required_context :week
52
- # end
53
- #
54
- def required_context(*args)
55
- @required_params = args.flatten
56
- end
57
-
58
- def call(args={})
59
- new(**args).call
60
- end
61
- end
62
-
63
- def initialize(args={})
64
- @context = Context.build(args)
65
- @context.validate(required_params: self.class.required_params)
14
+ # Examples
15
+ #
16
+ # ServiceOperator.configure do |config|
17
+ # config.call_parameters_method_name = :call_parameters
18
+ # config.failure_method_name = :failure?
19
+ # end
20
+ #
21
+ def configure
22
+ yield(configuration)
66
23
  end
67
24
 
68
- def call
69
- with_hooks { run_steps(self.class.steps) }
70
- context
71
- # rescue catches errors in before and after steps and stops execution
72
- rescue StandardError
73
- context
25
+ # Public: Default per thread service_operator instance if configured.
26
+ # Returns ServiceOperator::Configuration instance.
27
+ def instance
28
+ Thread.current[:service_operator_configuration] ||= configuration
74
29
  end
75
30
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: service_operator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bogdanov Anton
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-09-12 00:00:00.000000000 Z
11
+ date: 2022-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -102,6 +102,7 @@ files:
102
102
  - lib/service_operator.rb
103
103
  - lib/service_operator/configuration.rb
104
104
  - lib/service_operator/context.rb
105
+ - lib/service_operator/helpers.rb
105
106
  - lib/service_operator/hooks.rb
106
107
  - lib/service_operator/step.rb
107
108
  - lib/service_operator/steps.rb