convenient_service 0.5.0 → 0.7.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 +49 -0
- data/LICENSE.txt +1 -1
- data/README.md +1 -1
- data/ROADMAP.md +26 -4
- data/Taskfile.yml +30 -0
- data/convenient_service.gemspec +5 -2
- data/lib/convenient_service/aliases.rb +2 -0
- data/lib/convenient_service/common/plugins/assigns_attributes_in_constructor/using_active_model_attribute_assignment/concern.rb +0 -2
- data/lib/convenient_service/common/plugins/assigns_attributes_in_constructor/using_dry_initializer/concern.rb +0 -2
- 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.rb +1 -1
- data/lib/convenient_service/configs/standard.rb +25 -12
- data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/container/commands/resolve_methods_middlewares_callers.rb +1 -24
- data/lib/convenient_service/dependencies.rb +19 -0
- data/lib/convenient_service/examples/dry/gemfile/dry_service/config.rb +4 -2
- data/lib/convenient_service/examples/rails/gemfile/rails_service/config.rb +4 -2
- 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/examples/standard/request_params/constants.rb +15 -0
- data/lib/convenient_service/examples/standard/request_params/entities/description.rb +40 -0
- data/lib/convenient_service/examples/standard/request_params/entities/format.rb +40 -0
- data/lib/convenient_service/examples/standard/request_params/entities/id.rb +47 -0
- data/lib/convenient_service/examples/standard/request_params/entities/logger.rb +21 -0
- data/lib/convenient_service/examples/standard/request_params/entities/request.rb +23 -0
- data/lib/convenient_service/examples/standard/request_params/entities/source.rb +40 -0
- data/lib/convenient_service/examples/standard/request_params/entities/tag.rb +40 -0
- data/lib/convenient_service/examples/standard/request_params/entities/title.rb +40 -0
- data/lib/convenient_service/examples/standard/request_params/entities.rb +11 -0
- data/lib/convenient_service/examples/standard/request_params/services/apply_default_param_values.rb +26 -0
- data/lib/convenient_service/examples/standard/request_params/services/cast_params.rb +38 -0
- data/lib/convenient_service/examples/standard/request_params/services/extract_params_from_body.rb +70 -0
- data/lib/convenient_service/examples/standard/request_params/services/extract_params_from_path.rb +62 -0
- data/lib/convenient_service/examples/standard/request_params/services/filter_out_unpermitted_params.rb +26 -0
- data/lib/convenient_service/examples/standard/request_params/services/log_request_params.rb +54 -0
- data/lib/convenient_service/examples/standard/request_params/services/merge_params.rb +26 -0
- data/lib/convenient_service/examples/standard/request_params/services/prepare.rb +65 -0
- data/lib/convenient_service/examples/standard/request_params/services/validate_casted_params.rb +94 -0
- data/lib/convenient_service/examples/standard/request_params/services/validate_uncasted_params.rb +72 -0
- data/lib/convenient_service/examples/standard/request_params/services.rb +13 -0
- data/lib/convenient_service/examples/standard/request_params/utils/array/wrap.rb +46 -0
- data/lib/convenient_service/examples/standard/request_params/utils/array.rb +21 -0
- data/lib/convenient_service/examples/standard/request_params/utils/http/request/parse_body.rb +42 -0
- data/lib/convenient_service/examples/standard/request_params/utils/http/request/parse_path.rb +40 -0
- data/lib/convenient_service/examples/standard/request_params/utils/http/request.rb +28 -0
- data/lib/convenient_service/examples/standard/request_params/utils/http.rb +3 -0
- data/lib/convenient_service/examples/standard/request_params/utils/integer/safe_parse.rb +31 -0
- data/lib/convenient_service/examples/standard/request_params/utils/integer.rb +25 -0
- data/lib/convenient_service/examples/standard/request_params/utils/json/safe_parse.rb +40 -0
- data/lib/convenient_service/examples/standard/request_params/utils/json.rb +21 -0
- data/lib/convenient_service/examples/standard/request_params/utils/object/blank.rb +34 -0
- data/lib/convenient_service/examples/standard/request_params/utils/object/present.rb +31 -0
- data/lib/convenient_service/examples/standard/request_params/utils/object.rb +26 -0
- data/lib/convenient_service/examples/standard/request_params/utils.rb +7 -0
- data/lib/convenient_service/examples/standard/request_params.rb +48 -0
- 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/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/entities/matcher/commands/generate_printable_method.rb +50 -0
- data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities/matcher/commands.rb +3 -0
- data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities/matcher/entities/chainings/sub_matchers/arguments/commands/apply_stub_to_track_delegations.rb +78 -0
- data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities/matcher/entities/chainings/sub_matchers/arguments/commands/generate_printable_arguments.rb +100 -0
- data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities/matcher/entities/chainings/sub_matchers/arguments/commands.rb +4 -0
- data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities/matcher/entities/chainings/sub_matchers/arguments.rb +95 -0
- data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities/matcher/entities/chainings/sub_matchers/base.rb +87 -0
- data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities/matcher/entities/chainings/sub_matchers/return_its_value.rb +129 -0
- data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities/matcher/entities/chainings/sub_matchers/with_any_arguments.rb +37 -0
- data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities/matcher/entities/chainings/sub_matchers/with_concrete_arguments.rb +37 -0
- data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities/matcher/entities/chainings/sub_matchers/without_arguments.rb +37 -0
- data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities/matcher/entities/chainings/values/base.rb +41 -0
- data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities/matcher/entities/chainings/values/with_calling_original.rb +30 -0
- data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities/matcher/entities/chainings/values/without_calling_original.rb +30 -0
- data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities/matcher/entities/chainings.rb +12 -0
- data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities/matcher/entities/chainings_collection/errors.rb +57 -0
- data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities/matcher/entities/chainings_collection.rb +171 -0
- data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities/matcher/entities/delegation.rb +79 -0
- data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities/matcher/entities.rb +5 -0
- data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities/matcher.rb +276 -0
- data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities.rb +3 -0
- data/lib/convenient_service/rspec/matchers/custom/delegate_to.rb +66 -233
- 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 +73 -12
- data/lib/convenient_service/rspec/matchers/custom/singleton_prepend_module.rb +79 -0
- data/lib/convenient_service/rspec/matchers/custom.rb +1 -0
- data/lib/convenient_service/rspec/matchers/singleton_prepend_module.rb +13 -0
- data/lib/convenient_service/rspec/matchers.rb +2 -0
- 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 +4 -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 +40 -4
- data/lib/convenient_service/service/plugins/has_result_steps/entities/method/commands/cast_method.rb +3 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/method/commands/cast_method_caller.rb +8 -1
- data/lib/convenient_service/service/plugins/has_result_steps/entities/method/commands/cast_method_direction.rb +3 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/method/commands/cast_method_key.rb +8 -1
- data/lib/convenient_service/service/plugins/has_result_steps/entities/method/commands/cast_method_name.rb +9 -5
- 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/concern/instance_methods.rb +4 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/method/entities/callers/base.rb +4 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/method/entities/callers/reassignment/commands/define_method_in_container.rb +74 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/method/entities/callers/reassignment/commands.rb +3 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/method/entities/callers/reassignment.rb +50 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/method/entities/callers.rb +1 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/method/entities/values/reassignment.rb +43 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/method/entities/values.rb +3 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/method/entities.rb +1 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/method/errors.rb +22 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/step/concern/instance_methods.rb +39 -3
- 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/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/arguments/null_arguments.rb +28 -0
- data/lib/convenient_service/support/arguments.rb +87 -0
- data/lib/convenient_service/support/copyable.rb +6 -2
- data/lib/convenient_service/support/dependency_container/commands/assert_valid_scope.rb +32 -0
- data/lib/convenient_service/support/dependency_container/commands/import_method.rb +13 -23
- data/lib/convenient_service/support/dependency_container/commands.rb +1 -0
- data/lib/convenient_service/support/dependency_container/constants.rb +4 -2
- data/lib/convenient_service/support/dependency_container/entities/method.rb +2 -9
- data/lib/convenient_service/support/dependency_container/entities/namespace_collection.rb +0 -9
- data/lib/convenient_service/support/dependency_container/errors.rb +26 -1
- data/lib/convenient_service/support/dependency_container/export.rb +8 -0
- data/lib/convenient_service/support/dependency_container/import.rb +3 -1
- data/lib/convenient_service/support/not_passed.rb +3 -1
- data/lib/convenient_service/support/version/null_version.rb +7 -0
- data/lib/convenient_service/support/version.rb +11 -1
- data/lib/convenient_service/support.rb +1 -0
- data/lib/convenient_service/utils/object/instance_variable_delete.rb +41 -0
- data/lib/convenient_service/utils/object/instance_variable_fetch.rb +4 -0
- data/lib/convenient_service/utils/object.rb +9 -0
- data/lib/convenient_service/utils/proc/display.rb +43 -0
- data/lib/convenient_service/utils/proc.rb +5 -0
- data/lib/convenient_service/version.rb +1 -1
- data/lib/convenient_service.rb +6 -0
- data/logo.png +0 -0
- metadata +154 -10
- 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
@@ -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
|
@@ -30,7 +30,7 @@ module ConvenientService
|
|
30
30
|
end
|
31
31
|
|
32
32
|
##
|
33
|
-
# NOTE: `failure_message` is only called when `
|
33
|
+
# NOTE: `failure_message` is only called when `matches?` returns `false`.
|
34
34
|
# https://rubydoc.info/github/rspec/rspec-expectations/RSpec/Matchers/MatcherProtocol#failure_message-instance_method
|
35
35
|
#
|
36
36
|
def failure_message
|
@@ -38,7 +38,7 @@ module ConvenientService
|
|
38
38
|
end
|
39
39
|
|
40
40
|
##
|
41
|
-
# NOTE: `failure_message_when_negated` is only called when `
|
41
|
+
# NOTE: `failure_message_when_negated` is only called when `matches?` returns `false`.
|
42
42
|
# https://rubydoc.info/github/rspec/rspec-expectations/RSpec/Matchers/MatcherProtocol#failure_message-instance_method
|
43
43
|
#
|
44
44
|
def failure_message_when_negated
|
@@ -30,7 +30,7 @@ module ConvenientService
|
|
30
30
|
end
|
31
31
|
|
32
32
|
##
|
33
|
-
# NOTE: `failure_message` is only called when `
|
33
|
+
# NOTE: `failure_message` is only called when `matches?` returns `false`.
|
34
34
|
# https://rubydoc.info/github/rspec/rspec-expectations/RSpec/Matchers/MatcherProtocol#failure_message-instance_method
|
35
35
|
#
|
36
36
|
def failure_message
|
@@ -38,7 +38,7 @@ module ConvenientService
|
|
38
38
|
end
|
39
39
|
|
40
40
|
##
|
41
|
-
# NOTE: `failure_message_when_negated` is only called when `
|
41
|
+
# NOTE: `failure_message_when_negated` is only called when `matches?` returns `false`.
|
42
42
|
# https://rubydoc.info/github/rspec/rspec-expectations/RSpec/Matchers/MatcherProtocol#failure_message-instance_method
|
43
43
|
#
|
44
44
|
def failure_message_when_negated
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ConvenientService
|
4
|
+
module RSpec
|
5
|
+
module Matchers
|
6
|
+
module Custom
|
7
|
+
class DelegateTo
|
8
|
+
module Entities
|
9
|
+
class Matcher
|
10
|
+
module Commands
|
11
|
+
class GeneratePrintableMethod < Support::Command
|
12
|
+
##
|
13
|
+
# @!attribute [r] object
|
14
|
+
# @return [Object] Can be any type.
|
15
|
+
#
|
16
|
+
attr_reader :object
|
17
|
+
|
18
|
+
##
|
19
|
+
# @!attribute [r] method
|
20
|
+
# @return [Symbol, String]
|
21
|
+
#
|
22
|
+
attr_reader :method
|
23
|
+
|
24
|
+
##
|
25
|
+
# @param object [Object] Can by any type.
|
26
|
+
# @param method [Symbol, String]
|
27
|
+
# @return [void]
|
28
|
+
#
|
29
|
+
def initialize(object:, method:)
|
30
|
+
@object = object
|
31
|
+
@method = method
|
32
|
+
end
|
33
|
+
|
34
|
+
def call
|
35
|
+
case Utils::Object.resolve_type(object)
|
36
|
+
when "class", "module"
|
37
|
+
"#{object}.#{method}"
|
38
|
+
when "instance"
|
39
|
+
"#{object.class}##{method}"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ConvenientService
|
4
|
+
module RSpec
|
5
|
+
module Matchers
|
6
|
+
module Custom
|
7
|
+
class DelegateTo
|
8
|
+
module Entities
|
9
|
+
class Matcher
|
10
|
+
module Entities
|
11
|
+
module Chainings
|
12
|
+
module SubMatchers
|
13
|
+
class Arguments < Chainings::SubMatchers::Base
|
14
|
+
module Commands
|
15
|
+
class ApplyStubToTrackDelegations < Support::Command
|
16
|
+
##
|
17
|
+
# @internal
|
18
|
+
# NOTE: `include ::RSpec::Mocks::ExampleMethods`.
|
19
|
+
# - https://github.com/rspec/rspec-mocks/blob/v3.11.1/lib/rspec/mocks/example_methods.rb
|
20
|
+
# - https://github.com/rspec/rspec-mocks/blob/main/lib/rspec/mocks/example_methods.rb
|
21
|
+
#
|
22
|
+
include ::RSpec::Mocks::ExampleMethods
|
23
|
+
|
24
|
+
##
|
25
|
+
# @return [ConvenientService::RSpec::Matchers::Custom::DelegateTo]
|
26
|
+
#
|
27
|
+
attr_reader :matcher
|
28
|
+
|
29
|
+
##
|
30
|
+
# @param matcher [ConvenientService::RSpec::Matchers::Custom::DelegateTo]
|
31
|
+
# @return [void]
|
32
|
+
#
|
33
|
+
def initialize(matcher:)
|
34
|
+
@matcher = matcher
|
35
|
+
end
|
36
|
+
|
37
|
+
def call
|
38
|
+
##
|
39
|
+
# NOTE: RSpec `allow(object).to receive(method).with(*args, **kwargs)` does NOT support block.
|
40
|
+
# https://github.com/rspec/rspec-mocks/issues/1182#issuecomment-679820352
|
41
|
+
#
|
42
|
+
# NOTE: RSpec `allow(object).to receive(method) do` does NOT support `and_call_original`.
|
43
|
+
# https://github.com/rspec/rspec-mocks/issues/774#issuecomment-54245277
|
44
|
+
#
|
45
|
+
# NOTE: That is why `and_wrap_original` is used.
|
46
|
+
# https://relishapp.com/rspec/rspec-mocks/docs/configuring-responses/wrapping-the-original-implementation
|
47
|
+
#
|
48
|
+
allow(matcher.object).to receive(matcher.method).and_wrap_original do |original, *actual_args, **actual_kwargs, &actual_block|
|
49
|
+
##
|
50
|
+
# TODO: Add backtrace for easier reason tracing.
|
51
|
+
#
|
52
|
+
matcher.delegations << Entities::Delegation.new(
|
53
|
+
object: matcher.object,
|
54
|
+
method: matcher.method,
|
55
|
+
args: actual_args,
|
56
|
+
kwargs: actual_kwargs,
|
57
|
+
block: actual_block
|
58
|
+
)
|
59
|
+
|
60
|
+
##
|
61
|
+
# NOTE: Imitates `and_call_original`.
|
62
|
+
#
|
63
|
+
original.call(*actual_args, **actual_kwargs, &actual_block) if matcher.should_call_original?
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ConvenientService
|
4
|
+
module RSpec
|
5
|
+
module Matchers
|
6
|
+
module Custom
|
7
|
+
class DelegateTo
|
8
|
+
module Entities
|
9
|
+
class Matcher
|
10
|
+
module Entities
|
11
|
+
module Chainings
|
12
|
+
module SubMatchers
|
13
|
+
class Arguments < Chainings::SubMatchers::Base
|
14
|
+
module Commands
|
15
|
+
class GeneratePrintableArguments < Support::Command
|
16
|
+
include Support::Delegate
|
17
|
+
|
18
|
+
##
|
19
|
+
# @!attribute [r] arguments
|
20
|
+
# @return [ConvenientService::RSpec::Matchers::Custom::DelegateTo::Entities::Arguments]
|
21
|
+
#
|
22
|
+
attr_reader :arguments
|
23
|
+
|
24
|
+
##
|
25
|
+
# @return [Array]
|
26
|
+
#
|
27
|
+
delegate :args, to: :arguments
|
28
|
+
|
29
|
+
##
|
30
|
+
# @return [Hash]
|
31
|
+
#
|
32
|
+
delegate :kwargs, to: :arguments
|
33
|
+
|
34
|
+
##
|
35
|
+
# @return [Proc]
|
36
|
+
#
|
37
|
+
delegate :block, to: :arguments
|
38
|
+
|
39
|
+
##
|
40
|
+
# @param arguments [ConvenientService::RSpec::Matchers::Custom::DelegateTo::Entities::Arguments]
|
41
|
+
#
|
42
|
+
def initialize(arguments:)
|
43
|
+
@arguments = arguments
|
44
|
+
end
|
45
|
+
|
46
|
+
##
|
47
|
+
# @return [String]
|
48
|
+
#
|
49
|
+
def call
|
50
|
+
return "" if arguments.null_arguments?
|
51
|
+
|
52
|
+
text =
|
53
|
+
if args.any? && kwargs.any?
|
54
|
+
"(#{printable_args}, #{printable_kwargs})"
|
55
|
+
elsif args.any?
|
56
|
+
"(#{printable_args})"
|
57
|
+
elsif kwargs.any?
|
58
|
+
"(#{printable_kwargs})"
|
59
|
+
else
|
60
|
+
"()"
|
61
|
+
end
|
62
|
+
|
63
|
+
text += " #{printable_block}" if block
|
64
|
+
|
65
|
+
text
|
66
|
+
end
|
67
|
+
|
68
|
+
##
|
69
|
+
# @return [String]
|
70
|
+
#
|
71
|
+
def printable_args
|
72
|
+
args.map(&:inspect).join(", ")
|
73
|
+
end
|
74
|
+
|
75
|
+
##
|
76
|
+
# @return [String]
|
77
|
+
#
|
78
|
+
def printable_kwargs
|
79
|
+
kwargs.map { |key, value| "#{key}: #{value.inspect}" }.join(", ")
|
80
|
+
end
|
81
|
+
|
82
|
+
##
|
83
|
+
# @return [String]
|
84
|
+
#
|
85
|
+
def printable_block
|
86
|
+
block ? Utils::Proc.display(block) : ""
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|