convenient_service 0.6.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +58 -0
- data/ROADMAP.md +14 -1
- data/convenient_service.gemspec +2 -1
- data/lib/convenient_service/aliases.rb +10 -0
- data/lib/convenient_service/common/plugins/has_around_callbacks/middleware.rb +24 -4
- data/lib/convenient_service/common/plugins/has_callbacks/container.rb +17 -0
- data/lib/convenient_service/common/plugins/has_callbacks/entities/callback.rb +98 -5
- data/lib/convenient_service/common/plugins/has_callbacks/middleware.rb +25 -4
- data/lib/convenient_service/common/plugins/has_callbacks.rb +1 -0
- data/lib/convenient_service/common/plugins/has_constructor_without_initialize/concern.rb +19 -0
- data/lib/convenient_service/common/plugins.rb +1 -1
- data/lib/convenient_service/configs/minimal.rb +176 -0
- data/lib/convenient_service/configs/standard.rb +30 -105
- data/lib/convenient_service/configs.rb +1 -0
- data/lib/convenient_service/dependencies.rb +20 -0
- data/lib/convenient_service/examples/dry/gemfile/dry_service/config.rb +5 -5
- data/lib/convenient_service/examples/rails/gemfile/rails_service/config.rb +7 -7
- data/lib/convenient_service/examples/rails/gemfile/services/format.rb +35 -6
- data/lib/convenient_service/examples/rails/gemfile/services/format_header.rb +1 -2
- data/lib/convenient_service/examples/rails/gemfile/services/merge_sections.rb +25 -0
- data/lib/convenient_service/examples/rails/gemfile/services/replace_file_content.rb +37 -0
- data/lib/convenient_service/examples/rails/gemfile/services.rb +8 -4
- data/lib/convenient_service/examples/standard/gemfile/services/format.rb +45 -6
- data/lib/convenient_service/examples/standard/gemfile/services/merge_sections.rb +52 -0
- data/lib/convenient_service/examples/standard/gemfile/services/replace_file_content.rb +48 -0
- data/lib/convenient_service/examples/standard/gemfile/services.rb +8 -4
- data/lib/convenient_service/factories/arguments.rb +43 -0
- data/lib/convenient_service/factories/results.rb +214 -0
- data/lib/convenient_service/factories/services.rb +189 -0
- data/lib/convenient_service/factories/step/instance.rb +32 -0
- data/lib/convenient_service/factories/step.rb +3 -0
- data/lib/convenient_service/factories/steps.rb +126 -0
- data/lib/convenient_service/factories.rb +22 -0
- data/lib/convenient_service/factory.rb +21 -0
- data/lib/convenient_service/rspec/helpers/custom/ignoring_error.rb +3 -0
- data/lib/convenient_service/rspec/helpers/custom/wrap_method/entities/wrapped_method.rb +29 -3
- data/lib/convenient_service/rspec/matchers/custom/be_descendant_of.rb +2 -2
- data/lib/convenient_service/rspec/matchers/custom/be_direct_descendant_of.rb +2 -2
- data/lib/convenient_service/rspec/matchers/custom/delegate_to.rb +9 -0
- data/lib/convenient_service/rspec/matchers/custom/results/base/commands/find_result_method_step.rb +74 -0
- data/lib/convenient_service/rspec/matchers/custom/results/base/commands/find_result_result_method_step.rb +66 -0
- data/lib/convenient_service/rspec/matchers/custom/results/base/commands/find_result_service_step.rb +48 -0
- data/lib/convenient_service/rspec/matchers/custom/results/base/commands/generate_expected_step_part.rb +42 -0
- data/lib/convenient_service/rspec/matchers/custom/results/base/commands/generate_got_step_part.rb +42 -0
- data/lib/convenient_service/rspec/matchers/custom/results/base/commands/match_result_step.rb +89 -0
- data/lib/convenient_service/rspec/matchers/custom/results/base/commands.rb +10 -0
- data/lib/convenient_service/rspec/matchers/custom/results/base/errors.rb +35 -0
- data/lib/convenient_service/rspec/matchers/custom/results/base.rb +78 -12
- data/lib/convenient_service/service/plugins/has_result/concern/class_methods.rb +3 -3
- data/lib/convenient_service/service/plugins/has_result/constants.rb +0 -3
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/can_have_parent_result/concern.rb +85 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/can_have_parent_result/initialize/middleware.rb +27 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/can_have_parent_result/initialize.rb +3 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/can_have_parent_result/to_kwargs/middleware.rb +25 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/can_have_parent_result/to_kwargs.rb +3 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/can_have_parent_result.rb +5 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/concern/instance_methods.rb +7 -1
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/data.rb +17 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_step/concern.rb +27 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_step/initialize/middleware.rb +27 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_step/initialize.rb +3 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_step/to_kwargs/middleware.rb +25 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_step/to_kwargs.rb +3 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_step.rb +5 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins.rb +2 -0
- data/lib/convenient_service/service/plugins/has_result_method_steps.rb +0 -2
- data/lib/convenient_service/service/plugins/has_result_steps/concern.rb +18 -7
- data/lib/convenient_service/service/plugins/has_result_steps/entities/method/commands/define_method_in_container.rb +2 -2
- data/lib/convenient_service/service/plugins/has_result_steps/entities/method/entities/callers/reassignment/commands/define_method_in_container.rb +1 -1
- data/lib/convenient_service/service/plugins/has_result_steps/entities/step/concern/instance_methods.rb +26 -1
- data/lib/convenient_service/service/plugins/has_result_steps/entities/step/plugins/can_have_parent_result/middleware.rb +23 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/step/plugins/can_have_parent_result.rb +3 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/step/plugins.rb +1 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/step_collection.rb +13 -0
- data/lib/convenient_service/service/plugins/has_result_steps/middleware.rb +18 -4
- data/lib/convenient_service/service/plugins/raises_on_double_result/middleware.rb +37 -2
- data/lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions/commands/format_backtrace.rb +80 -0
- data/lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions/commands/format_cause.rb +78 -0
- data/lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions/commands/format_exception.rb +169 -0
- data/lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions/commands/format_line.rb +40 -0
- data/lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions/commands.rb +7 -0
- data/lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions/constants.rb +13 -0
- data/lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions/middleware.rb +58 -0
- data/lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions.rb +5 -0
- data/lib/convenient_service/services/run_method_in_organizer.rb +28 -0
- data/lib/convenient_service/services/run_own_method_in_organizer.rb +64 -0
- data/lib/convenient_service/{service/plugins/has_result_method_steps/services.rb → services.rb} +0 -1
- data/lib/convenient_service/support/copyable.rb +6 -2
- data/lib/convenient_service/support/dependency_container/errors.rb +1 -1
- data/lib/convenient_service/support/not_passed.rb +3 -1
- data/lib/convenient_service/support/undefined.rb +9 -0
- data/lib/convenient_service/support.rb +2 -0
- data/lib/convenient_service/version.rb +1 -1
- data/lib/convenient_service.rb +6 -0
- data/logo.png +0 -0
- metadata +68 -11
- data/lib/convenient_service/service/plugins/has_result_method_steps/errors.rb +0 -23
- data/lib/convenient_service/service/plugins/has_result_method_steps/services/method_step_config.rb +0 -55
- data/lib/convenient_service/service/plugins/has_result_method_steps/services/run_method_in_organizer.rb +0 -30
- 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"
|
@@ -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,126 @@
|
|
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 Steps
|
9
|
+
##
|
10
|
+
# @return [Class]
|
11
|
+
#
|
12
|
+
# @example Default.
|
13
|
+
#
|
14
|
+
# class Step
|
15
|
+
# include ConvenienService::Standard::Config
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
# class Service
|
19
|
+
# include ConvenienService::Standard::Config
|
20
|
+
# # ...
|
21
|
+
# step Step # `step` is `args.first`
|
22
|
+
# # ...
|
23
|
+
# end
|
24
|
+
#
|
25
|
+
def create_step(...)
|
26
|
+
create_service_step_class(...)
|
27
|
+
end
|
28
|
+
|
29
|
+
##
|
30
|
+
# @return [Integer]
|
31
|
+
#
|
32
|
+
# @example Default.
|
33
|
+
#
|
34
|
+
# class Service
|
35
|
+
# include ConvenienService::Standard::Config
|
36
|
+
# # ...
|
37
|
+
# step 42 # `step` is `args.first`
|
38
|
+
# # ...
|
39
|
+
# end
|
40
|
+
#
|
41
|
+
def create_invalid_step(...)
|
42
|
+
42
|
43
|
+
end
|
44
|
+
|
45
|
+
##
|
46
|
+
# @return [Class]
|
47
|
+
#
|
48
|
+
# @example Default.
|
49
|
+
#
|
50
|
+
# class Step
|
51
|
+
# include ConvenienService::Standard::Config
|
52
|
+
# end
|
53
|
+
#
|
54
|
+
# class Service
|
55
|
+
# include ConvenienService::Standard::Config
|
56
|
+
# # ...
|
57
|
+
# step Step # `step` is `args.first`
|
58
|
+
# # ...
|
59
|
+
# end
|
60
|
+
#
|
61
|
+
def create_service_step(...)
|
62
|
+
create_service_step_class(...)
|
63
|
+
end
|
64
|
+
|
65
|
+
##
|
66
|
+
# @return [Symbol]
|
67
|
+
#
|
68
|
+
# @example Default.
|
69
|
+
#
|
70
|
+
# class Step
|
71
|
+
# include ConvenienService::Standard::Config
|
72
|
+
# end
|
73
|
+
#
|
74
|
+
# class Service
|
75
|
+
# include ConvenienService::Standard::Config
|
76
|
+
# # ...
|
77
|
+
# step :validate # `step` is `args.first`
|
78
|
+
# # ...
|
79
|
+
# end
|
80
|
+
#
|
81
|
+
def create_method_step
|
82
|
+
::Faker::Verb.unique.base.to_sym
|
83
|
+
end
|
84
|
+
|
85
|
+
##
|
86
|
+
# @return [Symbol]
|
87
|
+
#
|
88
|
+
# @example Default.
|
89
|
+
#
|
90
|
+
# class Step
|
91
|
+
# include ConvenienService::Standard::Config
|
92
|
+
# end
|
93
|
+
#
|
94
|
+
# class Service
|
95
|
+
# include ConvenienService::Standard::Config
|
96
|
+
# # ...
|
97
|
+
# step :result # `step` is `args.first`
|
98
|
+
# # ...
|
99
|
+
# end
|
100
|
+
#
|
101
|
+
def create_result_method_step
|
102
|
+
:result
|
103
|
+
end
|
104
|
+
|
105
|
+
##
|
106
|
+
# @return [Class]
|
107
|
+
#
|
108
|
+
# @example Default.
|
109
|
+
#
|
110
|
+
# class Step
|
111
|
+
# include ConvenienService::Standard::Config
|
112
|
+
# end
|
113
|
+
#
|
114
|
+
# class Service
|
115
|
+
# include ConvenienService::Standard::Config
|
116
|
+
# # ...
|
117
|
+
# step Step # `step` is `args.first`
|
118
|
+
# # ...
|
119
|
+
# end
|
120
|
+
#
|
121
|
+
def create_service_step_class
|
122
|
+
create_service_class
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "factories/arguments"
|
4
|
+
require_relative "factories/services"
|
5
|
+
require_relative "factories/results"
|
6
|
+
require_relative "factories/steps"
|
7
|
+
|
8
|
+
require_relative "factories/step"
|
9
|
+
|
10
|
+
##
|
11
|
+
# WIP: Factory API is NOT well-thought yet. It will be revisited and completely refactored at any time.
|
12
|
+
#
|
13
|
+
module ConvenientService
|
14
|
+
module Factories
|
15
|
+
extend Arguments
|
16
|
+
extend Services
|
17
|
+
extend Results
|
18
|
+
extend Steps
|
19
|
+
|
20
|
+
extend Step::Instance
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "factories"
|
4
|
+
|
5
|
+
##
|
6
|
+
# WIP: Factory API is NOT well-thought yet. It will be revisited and completely refactored at any time.
|
7
|
+
#
|
8
|
+
module ConvenientService
|
9
|
+
module Factory
|
10
|
+
class << self
|
11
|
+
##
|
12
|
+
# @param method [String, Symbol]
|
13
|
+
# @param kwargs [Hash]
|
14
|
+
# @return [Object] Can be any type.
|
15
|
+
#
|
16
|
+
def create(method, **kwargs)
|
17
|
+
Factories.public_send("create_#{method}", **kwargs)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|