convenient_service 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +40 -0
  3. data/ROADMAP.md +12 -1
  4. data/convenient_service.gemspec +2 -1
  5. data/lib/convenient_service/aliases.rb +1 -0
  6. data/lib/convenient_service/common/plugins/has_around_callbacks/middleware.rb +24 -4
  7. data/lib/convenient_service/common/plugins/has_callbacks/container.rb +17 -0
  8. data/lib/convenient_service/common/plugins/has_callbacks/entities/callback.rb +98 -5
  9. data/lib/convenient_service/common/plugins/has_callbacks/middleware.rb +25 -4
  10. data/lib/convenient_service/common/plugins/has_callbacks.rb +1 -0
  11. data/lib/convenient_service/common/plugins.rb +1 -1
  12. data/lib/convenient_service/configs/standard.rb +25 -12
  13. data/lib/convenient_service/dependencies.rb +12 -0
  14. data/lib/convenient_service/examples/dry/gemfile/dry_service/config.rb +1 -1
  15. data/lib/convenient_service/examples/rails/gemfile/rails_service/config.rb +1 -1
  16. data/lib/convenient_service/examples/rails/gemfile/services/format.rb +35 -6
  17. data/lib/convenient_service/examples/rails/gemfile/services/format_header.rb +1 -2
  18. data/lib/convenient_service/examples/rails/gemfile/services/merge_sections.rb +25 -0
  19. data/lib/convenient_service/examples/rails/gemfile/services/replace_file_content.rb +37 -0
  20. data/lib/convenient_service/examples/rails/gemfile/services.rb +8 -4
  21. data/lib/convenient_service/examples/standard/gemfile/services/format.rb +45 -6
  22. data/lib/convenient_service/examples/standard/gemfile/services/merge_sections.rb +52 -0
  23. data/lib/convenient_service/examples/standard/gemfile/services/replace_file_content.rb +48 -0
  24. data/lib/convenient_service/examples/standard/gemfile/services.rb +8 -4
  25. data/lib/convenient_service/factories/arguments.rb +43 -0
  26. data/lib/convenient_service/factories/results.rb +214 -0
  27. data/lib/convenient_service/factories/services.rb +189 -0
  28. data/lib/convenient_service/factories/step/instance.rb +32 -0
  29. data/lib/convenient_service/factories/step.rb +3 -0
  30. data/lib/convenient_service/factories/steps.rb +126 -0
  31. data/lib/convenient_service/factories.rb +22 -0
  32. data/lib/convenient_service/factory.rb +21 -0
  33. data/lib/convenient_service/rspec/matchers/custom/be_descendant_of.rb +2 -2
  34. data/lib/convenient_service/rspec/matchers/custom/be_direct_descendant_of.rb +2 -2
  35. data/lib/convenient_service/rspec/matchers/custom/delegate_to.rb +9 -0
  36. data/lib/convenient_service/rspec/matchers/custom/results/base/commands/find_result_method_step.rb +74 -0
  37. data/lib/convenient_service/rspec/matchers/custom/results/base/commands/find_result_result_method_step.rb +66 -0
  38. data/lib/convenient_service/rspec/matchers/custom/results/base/commands/find_result_service_step.rb +48 -0
  39. data/lib/convenient_service/rspec/matchers/custom/results/base/commands/generate_expected_step_part.rb +42 -0
  40. data/lib/convenient_service/rspec/matchers/custom/results/base/commands/generate_got_step_part.rb +42 -0
  41. data/lib/convenient_service/rspec/matchers/custom/results/base/commands/match_result_step.rb +89 -0
  42. data/lib/convenient_service/rspec/matchers/custom/results/base/commands.rb +10 -0
  43. data/lib/convenient_service/rspec/matchers/custom/results/base/errors.rb +35 -0
  44. data/lib/convenient_service/rspec/matchers/custom/results/base.rb +73 -12
  45. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/can_have_parent_result/concern.rb +85 -0
  46. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/can_have_parent_result/initialize/middleware.rb +27 -0
  47. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/can_have_parent_result/initialize.rb +3 -0
  48. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/can_have_parent_result/to_kwargs/middleware.rb +25 -0
  49. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/can_have_parent_result/to_kwargs.rb +3 -0
  50. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/can_have_parent_result.rb +5 -0
  51. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/concern/instance_methods.rb +7 -1
  52. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/data.rb +4 -0
  53. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_step/concern.rb +27 -0
  54. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_step/initialize/middleware.rb +27 -0
  55. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_step/initialize.rb +3 -0
  56. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_step/to_kwargs/middleware.rb +25 -0
  57. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_step/to_kwargs.rb +3 -0
  58. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_step.rb +5 -0
  59. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins.rb +2 -0
  60. data/lib/convenient_service/service/plugins/has_result_method_steps.rb +0 -2
  61. data/lib/convenient_service/service/plugins/has_result_steps/concern.rb +18 -7
  62. data/lib/convenient_service/service/plugins/has_result_steps/entities/method/commands/define_method_in_container.rb +2 -2
  63. data/lib/convenient_service/service/plugins/has_result_steps/entities/method/entities/callers/reassignment/commands/define_method_in_container.rb +1 -1
  64. data/lib/convenient_service/service/plugins/has_result_steps/entities/step/concern/instance_methods.rb +26 -1
  65. data/lib/convenient_service/service/plugins/has_result_steps/entities/step/plugins/can_have_parent_result/middleware.rb +23 -0
  66. data/lib/convenient_service/service/plugins/has_result_steps/entities/step/plugins/can_have_parent_result.rb +3 -0
  67. data/lib/convenient_service/service/plugins/has_result_steps/entities/step/plugins.rb +1 -0
  68. data/lib/convenient_service/service/plugins/has_result_steps/entities/step_collection.rb +13 -0
  69. data/lib/convenient_service/service/plugins/has_result_steps/middleware.rb +18 -4
  70. data/lib/convenient_service/services/run_method_in_organizer.rb +28 -0
  71. data/lib/convenient_service/services/run_own_method_in_organizer.rb +64 -0
  72. data/lib/convenient_service/{service/plugins/has_result_method_steps/services.rb → services.rb} +0 -1
  73. data/lib/convenient_service/support/copyable.rb +6 -2
  74. data/lib/convenient_service/support/dependency_container/errors.rb +1 -1
  75. data/lib/convenient_service/support/not_passed.rb +3 -1
  76. data/lib/convenient_service/version.rb +1 -1
  77. data/lib/convenient_service.rb +6 -0
  78. data/logo.png +0 -0
  79. metadata +58 -11
  80. data/lib/convenient_service/service/plugins/has_result_method_steps/errors.rb +0 -23
  81. data/lib/convenient_service/service/plugins/has_result_method_steps/services/method_step_config.rb +0 -55
  82. data/lib/convenient_service/service/plugins/has_result_method_steps/services/run_method_in_organizer.rb +0 -30
  83. data/lib/convenient_service/service/plugins/has_result_method_steps/services/run_own_method_in_organizer.rb +0 -52
@@ -1,17 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "services/run_shell"
4
+
4
5
  require_relative "services/assert_file_exists"
5
6
  require_relative "services/assert_file_not_empty"
6
7
  require_relative "services/assert_node_available"
7
8
  require_relative "services/assert_npm_package_available"
8
9
  require_relative "services/assert_valid_ruby_syntax"
9
- require_relative "services/read_file_content"
10
- require_relative "services/strip_comments"
11
- require_relative "services/parse_content"
12
- require_relative "services/print_shell_command"
13
10
  require_relative "services/format_header"
14
11
  require_relative "services/format_gems_without_envs"
15
12
  require_relative "services/format_gems_with_envs"
16
13
  require_relative "services/format_body"
14
+ require_relative "services/merge_sections"
15
+ require_relative "services/parse_content"
16
+ require_relative "services/print_shell_command"
17
+ require_relative "services/read_file_content"
18
+ require_relative "services/replace_file_content"
19
+ require_relative "services/strip_comments"
20
+
17
21
  require_relative "services/format"
@@ -16,23 +16,62 @@ module ConvenientService
16
16
 
17
17
  attr_reader :path
18
18
 
19
- step Services::ReadFileContent, in: :path, out: :content
20
- step Services::StripComments, in: :content, out: :content_without_comments
21
- step Services::ParseContent, in: {content: :content_without_comments}, out: :parsed_content
22
- step Services::FormatHeader, in: :parsed_content, out: {formatted_content: :formatted_header_content}
23
- step Services::FormatBody, in: :parsed_content, out: {formatted_content: :formatted_body_content}
19
+ step :validate_path,
20
+ in: :path
21
+
22
+ step Services::ReadFileContent,
23
+ in: :path,
24
+ out: :content
25
+
26
+ step Services::StripComments,
27
+ in: :content,
28
+ out: :content_without_comments
29
+
30
+ step Services::ParseContent,
31
+ in: {content: :content_without_comments},
32
+ out: :parsed_content
33
+
34
+ step Services::FormatHeader,
35
+ in: :parsed_content,
36
+ out: {formatted_content: :formatted_header_content}
37
+
38
+ step Services::FormatBody,
39
+ in: :parsed_content,
40
+ out: {formatted_content: :formatted_body_content}
41
+
42
+ step Services::MergeSections,
43
+ in: [
44
+ {header: :formatted_header_content},
45
+ {body: :formatted_body_content}
46
+ ],
47
+ out: :merged_sections
48
+
49
+ step Services::ReplaceFileContent,
50
+ in: [
51
+ :path,
52
+ {content: :merged_sections}
53
+ ]
24
54
 
25
55
  before :result do
26
56
  @progressbar = ::ProgressBar.create(title: "Formatting", total: steps.count)
27
57
  end
28
58
 
29
- after :step do |step_result|
59
+ after :step do |step|
30
60
  @progressbar.increment
31
61
  end
32
62
 
33
63
  def initialize(path:)
34
64
  @path = path
35
65
  end
66
+
67
+ private
68
+
69
+ def validate_path
70
+ return failure(path: "Path is `nil`") if path.nil?
71
+ return failure(path: "Path is empty") if path.empty?
72
+
73
+ success
74
+ end
36
75
  end
37
76
  end
38
77
  end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ConvenientService
4
+ module Examples
5
+ module Standard
6
+ module Gemfile
7
+ module Services
8
+ class MergeSections
9
+ include ConvenientService::Standard::Config
10
+
11
+ attr_reader :header, :body
12
+
13
+ step :validate_header,
14
+ in: :header
15
+
16
+ step :validate_body,
17
+ in: :body
18
+
19
+ step :result,
20
+ in: [
21
+ :header,
22
+ :body
23
+ ]
24
+
25
+ def initialize(header:, body:)
26
+ @header = header
27
+ @body = body
28
+ end
29
+
30
+ def result
31
+ success(merged_sections: "#{header}\n#{body}")
32
+ end
33
+
34
+ def validate_header
35
+ return failure(header: "Header is `nil`") if header.nil?
36
+ return failure(header: "Header is empty") if header.empty?
37
+
38
+ success
39
+ end
40
+
41
+ def validate_body
42
+ return failure(body: "Body is `nil`") if body.nil?
43
+ return failure(body: "Body is empty") if body.empty?
44
+
45
+ success
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ConvenientService
4
+ module Examples
5
+ module Standard
6
+ module Gemfile
7
+ module Services
8
+ class ReplaceFileContent
9
+ include ConvenientService::Standard::Config
10
+
11
+ attr_reader :path, :content
12
+
13
+ step :validate_path, in: :path
14
+ step :validate_content, in: :content
15
+ step Services::AssertFileExists, in: :path
16
+ step :result, in: :path
17
+
18
+ def initialize(path:, content:)
19
+ @path = path
20
+ @content = content
21
+ end
22
+
23
+ def result
24
+ ::File.write(path, content)
25
+
26
+ success
27
+ end
28
+
29
+ private
30
+
31
+ def validate_path
32
+ return failure(path: "Path is `nil`") if path.nil?
33
+ return failure(path: "Path is empty") if path.empty?
34
+
35
+ success
36
+ end
37
+
38
+ def validate_content
39
+ return failure(content: "Content is `nil`") if content.nil?
40
+
41
+ success
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -1,17 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "services/run_shell"
4
+
4
5
  require_relative "services/assert_file_exists"
5
6
  require_relative "services/assert_file_not_empty"
6
7
  require_relative "services/assert_node_available"
7
8
  require_relative "services/assert_npm_package_available"
8
9
  require_relative "services/assert_valid_ruby_syntax"
9
- require_relative "services/read_file_content"
10
- require_relative "services/strip_comments"
11
- require_relative "services/parse_content"
12
- require_relative "services/print_shell_command"
13
10
  require_relative "services/format_header"
14
11
  require_relative "services/format_gems_without_envs"
15
12
  require_relative "services/format_gems_with_envs"
16
13
  require_relative "services/format_body"
14
+ require_relative "services/merge_sections"
15
+ require_relative "services/parse_content"
16
+ require_relative "services/print_shell_command"
17
+ require_relative "services/read_file_content"
18
+ require_relative "services/replace_file_content"
19
+ require_relative "services/strip_comments"
20
+
17
21
  require_relative "services/format"
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ ##
4
+ # WIP: Factory API is NOT well-thought yet. It will be revisited and completely refactored at any time.
5
+ #
6
+ module ConvenientService
7
+ module Factories
8
+ module Arguments
9
+ ##
10
+ # @return [Array]
11
+ #
12
+ # @example Default.
13
+ #
14
+ # hello(*args)
15
+ #
16
+ def create_args
17
+ [:foo, :bar]
18
+ end
19
+
20
+ ##
21
+ # @return [Hash]
22
+ #
23
+ # @example Default.
24
+ #
25
+ # hello(**kwargs)
26
+ #
27
+ def create_kwargs
28
+ {foo: :bar, baz: :qux}
29
+ end
30
+
31
+ ##
32
+ # @return [Hash]
33
+ #
34
+ # @example Default.
35
+ #
36
+ # hello(&block)
37
+ #
38
+ def create_block
39
+ proc { :foo }
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,214 @@
1
+ # frozen_string_literal: true
2
+
3
+ ##
4
+ # WIP: Factory API is NOT well-thought yet. It will be revisited and completely refactored at any time.
5
+ #
6
+ module ConvenientService
7
+ module Factories
8
+ module Results
9
+ ##
10
+ # @return [ConvenientService::Service::Plugins::HasResult::Entities::Result]
11
+ #
12
+ # @example Default.
13
+ #
14
+ # class Service
15
+ # include ConvenientService::Standard::Config
16
+ #
17
+ # def result
18
+ # success # `result` is return value
19
+ # end
20
+ # end
21
+ #
22
+ def create_result
23
+ service_class = create_service_class
24
+
25
+ service_class.result
26
+ end
27
+
28
+ ##
29
+ # @return [ConvenientService::Service::Plugins::HasResult::Entities::Result]
30
+ #
31
+ # @example Default.
32
+ #
33
+ # class Service
34
+ # include ConvenientService::Standard::Config
35
+ #
36
+ # def result
37
+ # success # `result` is return value
38
+ # end
39
+ # end
40
+ #
41
+ def create_result_without_step
42
+ service_class = create_service_class
43
+
44
+ service_class.result
45
+ end
46
+
47
+ ##
48
+ # @return [ConvenientService::Service::Plugins::HasResult::Entities::Result]
49
+ #
50
+ # @example Default.
51
+ #
52
+ # class Service
53
+ # include ConvenientService::Standard::Config
54
+ #
55
+ # step Step # `result` is return value
56
+ # end
57
+ #
58
+ def create_result_with_step(...)
59
+ create_result_with_service_step(...)
60
+ end
61
+
62
+ ##
63
+ # @param service_step [Class]
64
+ # @return [ConvenientService::Service::Plugins::HasResult::Entities::Result]
65
+ #
66
+ # @example Default.
67
+ #
68
+ # class Service
69
+ # include ConvenientService::Standard::Config
70
+ #
71
+ # step Step # `result` is return value
72
+ # end
73
+ #
74
+ # @example When `service_step` is passed.
75
+ #
76
+ # class Service
77
+ # include ConvenientService::Standard::Config
78
+ #
79
+ # step service_step # `result` is return value
80
+ # end
81
+ #
82
+ def create_result_with_service_step(service_step: Support::NOT_PASSED)
83
+ service_step_class = (service_step == Support::NOT_PASSED) ? create_service_step_class : service_step
84
+
85
+ service_class = create_service_class(steps: [service_step_class])
86
+
87
+ service_class.result
88
+ end
89
+
90
+ ##
91
+ # @param method_step [Symbol]
92
+ # @return [ConvenientService::Service::Plugins::HasResult::Entities::Result]
93
+ #
94
+ # @example Default.
95
+ #
96
+ # class Service
97
+ # include ConvenientService::Standard::Config
98
+ #
99
+ # step :validate # `result` is return value
100
+ # end
101
+ #
102
+ # @example When `method_step` is passed.
103
+ #
104
+ # class Service
105
+ # include ConvenientService::Standard::Config
106
+ #
107
+ # step method_step # `result` is return value
108
+ # end
109
+ #
110
+ def create_result_with_method_step(method_step: Support::NOT_PASSED)
111
+ method_step = (method_step == Support::NOT_PASSED) ? create_method_step : method_step
112
+
113
+ service_class = create_service_class(steps: [method_step])
114
+
115
+ service_class.result
116
+ end
117
+
118
+ ##
119
+ # @return [ConvenientService::Service::Plugins::HasResult::Entities::Result]
120
+ #
121
+ # @example Default.
122
+ #
123
+ # class Service
124
+ # include ConvenientService::Standard::Config
125
+ #
126
+ # step :result # `result` is return value
127
+ # end
128
+ #
129
+ def create_result_with_result_method_step
130
+ service_class = create_service_class(steps: [:result])
131
+
132
+ service_class.result
133
+ end
134
+
135
+ ##
136
+ # @return [Hash]
137
+ #
138
+ # @example Default.
139
+ #
140
+ # {
141
+ # service: result.service,
142
+ # status: :success,
143
+ # data: {foo: :bar},
144
+ # message: "",
145
+ # code: :default_success
146
+ # }
147
+ #
148
+ def create_result_attributes
149
+ create_result.jsend_attributes.to_h
150
+ end
151
+
152
+ ##
153
+ # @return [Hash]
154
+ #
155
+ # @example Default.
156
+ #
157
+ # {
158
+ # service: result.service,
159
+ # status: :success,
160
+ # data: {foo: :bar},
161
+ # message: "",
162
+ # code: :default_success,
163
+ # parent: result.parent
164
+ # }
165
+ #
166
+ def create_result_attributes_with_parent(parent: Support::NOT_PASSED)
167
+ parent = (parent == Support::NOT_PASSED) ? create_result_parent : parent
168
+
169
+ result_attributes = create_result_attributes
170
+
171
+ result_attributes.merge(parent: parent)
172
+ end
173
+
174
+ ##
175
+ # @return [Hash]
176
+ #
177
+ # @example Default.
178
+ #
179
+ # {
180
+ # service: result.service,
181
+ # status: :success,
182
+ # data: {foo: :bar},
183
+ # message: "",
184
+ # code: :default_success,
185
+ # step: result.step
186
+ # }
187
+ #
188
+ def create_result_attributes_with_step(step: Support::NOT_PASSED)
189
+ step = (step == Support::NOT_PASSED) ? create_result_step : step
190
+
191
+ result_attributes = create_result_attributes
192
+
193
+ result_attributes.merge(step: step)
194
+ end
195
+
196
+ ##
197
+ # @return [ConvenientService::Service::Plugins::HasResult::Entities::Result]
198
+ #
199
+ # @example Default.
200
+ #
201
+ # class Service
202
+ # include ConvenientService::Standard::Config
203
+ #
204
+ # def result
205
+ # success # `result_parent` is return value
206
+ # end
207
+ # end
208
+ #
209
+ def create_result_parent
210
+ create_result
211
+ end
212
+ end
213
+ end
214
+ end
@@ -0,0 +1,189 @@
1
+ # frozen_string_literal: true
2
+
3
+ ##
4
+ # WIP: Factory API is NOT well-thought yet. It will be revisited and completely refactored at any time.
5
+ #
6
+ module ConvenientService
7
+ module Factories
8
+ module Services
9
+ ##
10
+ # @return [Class]
11
+ #
12
+ # @example Default.
13
+ # class Service # `service` is class.
14
+ # include ConvenientService::Standard::Config
15
+ #
16
+ # def result
17
+ # success
18
+ # end
19
+ # end
20
+ #
21
+ def create_service_with_success_result
22
+ ::Class.new do
23
+ include ::ConvenientService::Configs::Standard
24
+
25
+ def result
26
+ success
27
+ end
28
+ end
29
+ end
30
+
31
+ ##
32
+ # @return [Class]
33
+ #
34
+ # @example Default.
35
+ # class Service # `service` is class.
36
+ # include ConvenientService::Standard::Config
37
+ #
38
+ # def result
39
+ # error("foo")
40
+ # end
41
+ # end
42
+ #
43
+ def create_service_with_not_success_result
44
+ create_service_with_error_result
45
+ end
46
+
47
+ ##
48
+ # @return [Class]
49
+ #
50
+ # @example Default.
51
+ # class Service # `service` is class.
52
+ # include ConvenientService::Standard::Config
53
+ #
54
+ # def result
55
+ # failure(foo: "bar")
56
+ # end
57
+ # end
58
+ #
59
+ def create_service_with_failure_result
60
+ ::Class.new do
61
+ include ::ConvenientService::Configs::Standard
62
+
63
+ def result
64
+ failure(data)
65
+ end
66
+
67
+ private
68
+
69
+ def data
70
+ @data ||= {::Faker::Lorem.word => ::Faker::Lorem.sentence}
71
+ end
72
+ end
73
+ end
74
+
75
+ ##
76
+ # @return [Class]
77
+ #
78
+ # @example Default.
79
+ # class Service # `service` is class.
80
+ # include ConvenientService::Standard::Config
81
+ #
82
+ # def result
83
+ # error("foo")
84
+ # end
85
+ # end
86
+ #
87
+ def create_service_with_error_result
88
+ ::Class.new do
89
+ include ::ConvenientService::Configs::Standard
90
+
91
+ def result
92
+ error(message)
93
+ end
94
+
95
+ private
96
+
97
+ def message
98
+ @message ||= ::Faker::Lorem.sentence
99
+ end
100
+ end
101
+ end
102
+
103
+ ##
104
+ # @return [Class]
105
+ #
106
+ # @example Default.
107
+ # class Service # `service` is class.
108
+ # include ConvenientService::Standard::Config
109
+ #
110
+ # def result
111
+ # success
112
+ # end
113
+ # end
114
+ #
115
+ def create_service(...)
116
+ create_service_class(...)
117
+ end
118
+
119
+ ##
120
+ # @param steps [<Class, Symbol>]
121
+ # @return [Class]
122
+ #
123
+ # @example Default.
124
+ # class Service # `service` is class.
125
+ # include ConvenientService::Standard::Config
126
+ #
127
+ # def result
128
+ # success
129
+ # end
130
+ # end
131
+ #
132
+ # @example One step.
133
+ # class Service # `service` is class.
134
+ # include ConvenientService::Standard::Config
135
+ #
136
+ # step Step # `steps.first` is `args.first`.
137
+ # end
138
+ #
139
+ # @example One method step.
140
+ # class Service # `service` is class.
141
+ # include ConvenientService::Standard::Config
142
+ #
143
+ # step :validate # `steps.first` is `args.first`.
144
+ #
145
+ # def validate
146
+ # success
147
+ # end
148
+ # end
149
+ #
150
+ # @example Multiple steps.
151
+ # class Service # `service` is class.
152
+ # include ConvenientService::Standard::Config
153
+ #
154
+ # step Step # `steps[0]` is `args.first`.
155
+ # step OtherStep # `steps[1]` is `args.first`.
156
+ # step :result # `steps[2]` is `args.first`.
157
+ #
158
+ # def result
159
+ # success
160
+ # end
161
+ # end
162
+ #
163
+ def create_service_class(steps: [])
164
+ ::Class.new.tap do |klass|
165
+ klass.class_exec(steps: steps) do
166
+ include ::ConvenientService::Configs::Standard
167
+
168
+ steps.each do |step_name|
169
+ case step_name
170
+ when ::Class
171
+ step step_name
172
+ when ::Symbol
173
+ step step_name
174
+
175
+ define_method(step_name) { success }
176
+ end
177
+ end
178
+
179
+ if steps.none?
180
+ def result
181
+ success
182
+ end
183
+ end
184
+ end
185
+ end
186
+ end
187
+ end
188
+ end
189
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ ##
4
+ # WIP: Factory API is NOT well-thought yet. It will be revisited and completely refactored at any time.
5
+ #
6
+ module ConvenientService
7
+ module Factories
8
+ module Step
9
+ module Instance
10
+ ##
11
+ # @return [ConvenientService::Service::Plugins::HasResultSteps::Entities::Step]
12
+ #
13
+ def create_step_instance
14
+ service_class =
15
+ ::Class.new do
16
+ include ::ConvenientService::Configs::Standard
17
+
18
+ step :result
19
+
20
+ def result
21
+ success
22
+ end
23
+ end
24
+
25
+ service_instance = service_class.new
26
+
27
+ service_instance.steps.first
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "step/instance"