convenient_service 0.11.0 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.dev/.tmuxinator.yml +2 -1
- data/.github/workflows/ci.yml +21 -1
- data/CHANGELOG.md +67 -0
- data/Gemfile +6 -0
- data/README.md +4 -2
- data/Taskfile.yml +94 -0
- data/convenient_service.gemspec +40 -2
- data/docker/2.7/Dockerfile +3 -3
- data/docker/3.0/Dockerfile +2 -2
- data/docker/3.1/Dockerfile +2 -2
- data/docker/3.2/Dockerfile +73 -0
- data/docker/jruby-9.4/Dockerfile +88 -0
- data/docker/truffleruby-22.3/Dockerfile +91 -0
- data/lib/convenient_service/common/plugins/aliases.rb +0 -1
- data/lib/convenient_service/common/plugins/assigns_attributes_in_constructor/using_active_model_attribute_assignment/middleware.rb +12 -8
- data/lib/convenient_service/common/plugins/caches_return_value/middleware.rb +3 -3
- data/lib/convenient_service/common/plugins/can_have_user_provided_entity/errors.rb +2 -2
- data/lib/convenient_service/common/plugins/has_around_callbacks/errors.rb +1 -1
- data/lib/convenient_service/common/plugins/has_callbacks/entities/callback.rb +7 -7
- data/lib/convenient_service/common/plugins/has_internals/entities/internals/plugins/aliases.rb +7 -0
- data/lib/convenient_service/common/plugins/has_internals/entities/internals/plugins.rb +2 -0
- data/lib/convenient_service/configs/minimal.rb +19 -10
- data/lib/convenient_service/core/class_methods.rb +24 -9
- data/lib/convenient_service/core/constants.rb +36 -0
- data/lib/convenient_service/core/entities/config/commands/track_method_missing_commit_trigger.rb +69 -0
- data/lib/convenient_service/core/entities/config/commands.rb +3 -0
- data/lib/convenient_service/core/entities/config/entities/concerns/entities/stack.rb +10 -10
- data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/chain.rb +3 -3
- data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/middleware.rb +18 -1
- data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/middleware_creator.rb +62 -0
- data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/stack.rb +12 -12
- data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities.rb +1 -0
- data/lib/convenient_service/core/entities/config/entities/method_middlewares.rb +1 -1
- data/lib/convenient_service/core/entities/config/errors.rb +38 -1
- data/lib/convenient_service/core/entities/config.rb +14 -4
- data/lib/convenient_service/core/instance_methods.rb +6 -4
- data/lib/convenient_service/core.rb +1 -0
- data/lib/convenient_service/dependencies/built_in.rb +7 -0
- data/lib/convenient_service/dependencies/extractions/active_support_concern/concern.rb +18 -2
- data/lib/convenient_service/dependencies/extractions/active_support_concern.rb +4 -0
- data/lib/convenient_service/dependencies/extractions/ruby_middleware/middleware/builder.rb +7 -1
- data/lib/convenient_service/dependencies/extractions/ruby_middleware/middleware/logger.rb +7 -1
- data/lib/convenient_service/dependencies/extractions/ruby_middleware/middleware/runner.rb +15 -1
- data/lib/convenient_service/dependencies/extractions/ruby_middleware/middleware.rb +8 -1
- data/lib/convenient_service/dependencies/extractions/ruby_middleware.rb +3 -2
- data/lib/convenient_service/dependencies.rb +16 -15
- data/lib/convenient_service/examples/dry/gemfile.rb +4 -4
- data/lib/convenient_service/examples/rails/gemfile.rb +4 -4
- data/lib/convenient_service/examples/standard/cowsay.rb +4 -4
- data/lib/convenient_service/examples/standard/gemfile/services/assert_file_exists.rb +1 -1
- data/lib/convenient_service/examples/standard/gemfile/services/assert_file_not_empty.rb +1 -1
- data/lib/convenient_service/examples/standard/gemfile/services/assert_node_available.rb +0 -9
- data/lib/convenient_service/examples/standard/gemfile/services/assert_npm_package_available.rb +0 -10
- data/lib/convenient_service/examples/standard/gemfile/services/format.rb +0 -10
- data/lib/convenient_service/examples/standard/gemfile/services/merge_sections.rb +0 -10
- data/lib/convenient_service/examples/standard/gemfile/services/parse_content.rb +0 -10
- data/lib/convenient_service/examples/standard/gemfile/services/read_file_content.rb +0 -10
- data/lib/convenient_service/examples/standard/gemfile/services/replace_file_content.rb +0 -10
- data/lib/convenient_service/examples/standard/gemfile.rb +4 -4
- data/lib/convenient_service/examples/standard/request_params/services/extract_params_from_body.rb +0 -10
- data/lib/convenient_service/examples/standard/request_params/services/extract_params_from_path.rb +0 -10
- data/lib/convenient_service/examples/standard/request_params/services/validate_casted_params.rb +0 -10
- data/lib/convenient_service/examples/standard/request_params/services/validate_uncasted_params.rb +0 -10
- data/lib/convenient_service/examples/standard/request_params.rb +4 -4
- data/lib/convenient_service/feature.rb +12 -0
- data/lib/convenient_service/logger.rb +6 -5
- data/lib/convenient_service/rspec/helpers/custom/in_threads.rb +74 -0
- data/lib/convenient_service/rspec/helpers/custom/stub_service/constants.rb +20 -0
- data/lib/convenient_service/rspec/helpers/custom/stub_service/entities/stubbed_service.rb +4 -4
- data/lib/convenient_service/rspec/helpers/custom/stub_service.rb +1 -0
- data/lib/convenient_service/rspec/helpers/custom/wrap_method/entities/wrapped_method.rb +3 -3
- data/lib/convenient_service/rspec/helpers/custom/wrap_method/errors.rb +1 -1
- data/lib/convenient_service/rspec/helpers/custom.rb +1 -0
- data/lib/convenient_service/rspec/helpers/in_threads.rb +13 -0
- data/lib/convenient_service/rspec/helpers.rb +2 -0
- data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities/matcher/entities/chainings_collection/errors.rb +3 -3
- data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities/matcher/entities/delegation.rb +3 -3
- data/lib/convenient_service/rspec/matchers/custom/export.rb +82 -0
- data/lib/convenient_service/rspec/matchers/custom/results/base/constants.rb +22 -0
- data/lib/convenient_service/rspec/matchers/custom/results/base/errors.rb +1 -1
- data/lib/convenient_service/rspec/matchers/custom/results/base.rb +2 -1
- data/lib/convenient_service/rspec/matchers/custom.rb +1 -0
- data/lib/convenient_service/rspec/matchers/export.rb +13 -0
- data/lib/convenient_service/rspec/matchers.rb +2 -0
- data/lib/convenient_service/service/plugins/aliases.rb +0 -2
- data/lib/convenient_service/service/plugins/can_have_method_steps/middleware.rb +2 -2
- data/lib/convenient_service/service/plugins/can_have_result_step/middleware.rb +2 -2
- data/lib/convenient_service/service/plugins/can_have_steps/concern.rb +2 -2
- data/lib/convenient_service/service/plugins/can_have_steps/entities/method/commands/cast_method.rb +46 -11
- data/lib/convenient_service/service/plugins/can_have_steps/entities/method/commands/cast_method_direction.rb +29 -2
- data/lib/convenient_service/service/plugins/can_have_steps/entities/method/commands/cast_method_factory.rb +113 -0
- data/lib/convenient_service/service/plugins/can_have_steps/entities/method/commands.rb +1 -3
- data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/factories/base.rb +62 -0
- data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/factories/hash/base.rb +35 -0
- data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/factories/hash/proc_value.rb +42 -0
- data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/factories/hash/raw_value.rb +42 -0
- data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/factories/hash/reassignment_value.rb +42 -0
- data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/factories/hash/string_value.rb +42 -0
- data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/factories/hash/symbol_value.rb +42 -0
- data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/factories/hash.rb +8 -0
- data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/factories/method.rb +40 -0
- data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/factories/reassignment.rb +40 -0
- data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/factories/string.rb +40 -0
- data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/factories/symbol.rb +40 -0
- data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/factories.rb +8 -0
- data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities.rb +1 -0
- data/lib/convenient_service/service/plugins/can_have_steps/entities/method/errors.rb +7 -7
- data/lib/convenient_service/service/plugins/can_have_steps/entities/step/errors.rb +12 -8
- data/lib/convenient_service/service/plugins/can_have_steps/entities/step/plugins/aliases.rb +7 -0
- data/lib/convenient_service/service/plugins/can_have_steps/entities/step/plugins.rb +2 -0
- data/lib/convenient_service/service/plugins/can_have_steps/entities/step_collection.rb +37 -8
- data/lib/convenient_service/service/plugins/can_have_stubbed_result/concern.rb +19 -11
- data/lib/convenient_service/service/plugins/can_have_stubbed_result/middleware.rb +3 -3
- data/lib/convenient_service/service/plugins/has_result/concern/instance_methods.rb +3 -3
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/aliases.rb +7 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/can_have_parent_result/concern.rb +12 -5
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/{has_jsend_status_and_attributes/concern/class_methods.rb → can_have_parent_result/constants.rb} +3 -4
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/can_have_parent_result.rb +1 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/{has_jsend_status_and_attributes/commands/cast_jsend_attributes.rb → has_j_send_status_and_attributes/commands/cast_j_send_attributes.rb} +1 -1
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/commands/create_code_class.rb +49 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/commands/create_data_class.rb +49 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/commands/create_message_class.rb +49 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/commands/create_status_class.rb +49 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/commands.rb +7 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/concern/class_methods.rb +69 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/{has_jsend_status_and_attributes → has_j_send_status_and_attributes}/concern/instance_methods.rb +9 -9
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/{has_jsend_status_and_attributes → has_j_send_status_and_attributes}/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/{has_jsend_status_and_attributes → has_j_send_status_and_attributes}/entities/code/concern/class_methods.rb +2 -2
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/{has_jsend_status_and_attributes → has_j_send_status_and_attributes}/entities/code/concern/instance_methods.rb +3 -3
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/{has_jsend_status_and_attributes → has_j_send_status_and_attributes}/entities/code/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/{has_jsend_status_and_attributes → has_j_send_status_and_attributes}/entities/code.rb +1 -1
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/entities/data/concern/class_methods.rb +38 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/entities/data/concern/instance_methods.rb +94 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/entities/data/concern.rb +36 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/entities/data.rb +25 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/entities/message/concern/class_methods.rb +40 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/entities/message/concern/instance_methods.rb +58 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/entities/message/concern.rb +36 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/entities/message.rb +25 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/entities/status/concern/class_methods.rb +40 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/entities/status/concern/instance_methods.rb +115 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/entities/status/concern.rb +36 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/entities/status.rb +25 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/{has_jsend_status_and_attributes → has_j_send_status_and_attributes}/errors.rb +6 -2
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/{has_jsend_status_and_attributes → has_j_send_status_and_attributes}/middleware.rb +4 -4
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/{has_jsend_status_and_attributes/structs/jsend_attributes.rb → has_j_send_status_and_attributes/structs/j_send_attributes.rb} +1 -1
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/structs.rb +3 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes.rb +8 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_result_short_syntax/concern.rb +3 -3
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/raises_on_not_checked_result_status/errors.rb +1 -1
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins.rb +3 -1
- data/lib/convenient_service/service/plugins/has_result/errors.rb +2 -2
- data/lib/convenient_service/service/plugins/has_result_status_check_short_syntax/concern.rb +16 -0
- data/lib/convenient_service/service/plugins/raises_on_double_result/errors.rb +1 -1
- data/lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions/commands/format_backtrace.rb +1 -1
- data/lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions/commands/format_exception.rb +11 -10
- data/lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions/middleware.rb +14 -7
- data/lib/convenient_service/services/run_own_method_in_organizer.rb +1 -1
- data/lib/convenient_service/support/abstract_method/errors.rb +1 -1
- data/lib/convenient_service/support/arguments.rb +3 -3
- data/lib/convenient_service/support/cache/key.rb +3 -3
- data/lib/convenient_service/support/cache.rb +1 -1
- data/lib/convenient_service/support/castable/errors.rb +2 -2
- data/lib/convenient_service/support/counter.rb +212 -0
- data/lib/convenient_service/support/dependency_container/commands/assert_valid_container.rb +33 -0
- data/lib/convenient_service/support/dependency_container/commands/assert_valid_method.rb +58 -0
- data/lib/convenient_service/support/dependency_container/commands/assert_valid_scope.rb +4 -3
- data/lib/convenient_service/support/dependency_container/commands/define_entry.rb +49 -0
- data/lib/convenient_service/support/dependency_container/commands.rb +3 -0
- data/lib/convenient_service/support/dependency_container/container.rb +23 -0
- data/lib/convenient_service/support/dependency_container/entry.rb +22 -0
- data/lib/convenient_service/support/dependency_container/errors.rb +5 -5
- data/lib/convenient_service/support/dependency_container/import.rb +3 -3
- data/lib/convenient_service/support/dependency_container.rb +3 -0
- data/lib/convenient_service/support/finite_loop.rb +37 -2
- data/lib/convenient_service/support/middleware/stack_builder.rb +1 -1
- data/lib/convenient_service/support/not_passed.rb +4 -3
- data/lib/convenient_service/support/ruby.rb +31 -0
- data/lib/convenient_service/support/safe_method.rb +65 -0
- data/lib/convenient_service/support/thread_safe_counter.rb +119 -0
- data/lib/convenient_service/support/undefined.rb +4 -3
- data/lib/convenient_service/support/unique_value.rb +69 -0
- data/lib/convenient_service/support.rb +4 -0
- data/lib/convenient_service/utils/array/errors.rb +1 -1
- data/lib/convenient_service/utils/array/find_last.rb +1 -1
- data/lib/convenient_service/utils/array/find_yield.rb +1 -1
- data/lib/convenient_service/utils/object/resolve_class.rb +56 -0
- data/lib/convenient_service/utils/object.rb +9 -0
- data/lib/convenient_service/version.rb +1 -1
- data/lib/convenient_service.rb +6 -0
- metadata +75 -34
- data/lib/convenient_service/factories/arguments.rb +0 -43
- data/lib/convenient_service/factories/results.rb +0 -214
- data/lib/convenient_service/factories/services.rb +0 -229
- data/lib/convenient_service/factories/step/instance.rb +0 -42
- data/lib/convenient_service/factories/step.rb +0 -3
- data/lib/convenient_service/factories/steps.rb +0 -126
- data/lib/convenient_service/factories.rb +0 -22
- data/lib/convenient_service/factory.rb +0 -21
- data/lib/convenient_service/service/plugins/can_have_steps/entities/method/commands/cast_method_caller.rb +0 -74
- data/lib/convenient_service/service/plugins/can_have_steps/entities/method/commands/cast_method_key.rb +0 -78
- data/lib/convenient_service/service/plugins/can_have_steps/entities/method/commands/cast_method_name.rb +0 -78
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/commands.rb +0 -3
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/data/class_methods.rb +0 -32
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/data.rb +0 -74
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/message/class_methods.rb +0 -34
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/message.rb +0 -45
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/status/class_methods.rb +0 -34
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/status.rb +0 -77
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/structs.rb +0 -3
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes.rb +0 -8
- /data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/{has_jsend_status_and_attributes → has_j_send_status_and_attributes}/entities.rb +0 -0
@@ -67,7 +67,7 @@ module ConvenientService
|
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
|
-
class OutputMethodProc < ConvenientService::Error
|
70
|
+
class OutputMethodProc < ::ConvenientService::Error
|
71
71
|
def initialize(method:, container:)
|
72
72
|
message = <<~TEXT
|
73
73
|
Procs are not allowed for `out` methods.
|
@@ -77,7 +77,7 @@ module ConvenientService
|
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
80
|
-
class OutputMethodRawValue < ConvenientService::Error
|
80
|
+
class OutputMethodRawValue < ::ConvenientService::Error
|
81
81
|
def initialize(method:, container:)
|
82
82
|
message = <<~TEXT
|
83
83
|
Raw values are not allowed for `out` methods.
|
@@ -99,7 +99,7 @@ module ConvenientService
|
|
99
99
|
end
|
100
100
|
end
|
101
101
|
|
102
|
-
class InputMethodReassignment < ConvenientService::Error
|
102
|
+
class InputMethodReassignment < ::ConvenientService::Error
|
103
103
|
def initialize(method:, container:)
|
104
104
|
message = <<~TEXT
|
105
105
|
Reassignments are not allowed for `in` methods.
|
@@ -109,7 +109,7 @@ module ConvenientService
|
|
109
109
|
end
|
110
110
|
end
|
111
111
|
|
112
|
-
class MethodIsNotInputMethod < ConvenientService::Error
|
112
|
+
class MethodIsNotInputMethod < ::ConvenientService::Error
|
113
113
|
def initialize(method:, container:)
|
114
114
|
message = <<~TEXT
|
115
115
|
Method `#{method.name}` is NOT an `in` method.
|
@@ -119,7 +119,7 @@ module ConvenientService
|
|
119
119
|
end
|
120
120
|
end
|
121
121
|
|
122
|
-
class MethodIsNotOutputMethod < ConvenientService::Error
|
122
|
+
class MethodIsNotOutputMethod < ::ConvenientService::Error
|
123
123
|
def initialize(method:, container:)
|
124
124
|
message = <<~TEXT
|
125
125
|
Method `#{method.name}` is NOT an `out` method.
|
@@ -129,7 +129,7 @@ module ConvenientService
|
|
129
129
|
end
|
130
130
|
end
|
131
131
|
|
132
|
-
class NotCompletedStep < ConvenientService::Error
|
132
|
+
class NotCompletedStep < ::ConvenientService::Error
|
133
133
|
def initialize(method_name:, step:)
|
134
134
|
message = <<~TEXT
|
135
135
|
`out` method `#{method_name}` is called before its corresponding step `#{step.printable_service}` is completed.
|
@@ -141,7 +141,7 @@ module ConvenientService
|
|
141
141
|
end
|
142
142
|
end
|
143
143
|
|
144
|
-
class NotExistingStepResultDataAttribute < ConvenientService::Error
|
144
|
+
class NotExistingStepResultDataAttribute < ::ConvenientService::Error
|
145
145
|
def initialize(key:, step:)
|
146
146
|
message = <<~TEXT
|
147
147
|
Step `#{step.printable_service}` result does NOT return `#{key}` data attribute.
|
@@ -4,16 +4,20 @@ module ConvenientService
|
|
4
4
|
module Service
|
5
5
|
module Plugins
|
6
6
|
module CanHaveSteps
|
7
|
-
module
|
8
|
-
class
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
module Entities
|
8
|
+
class Step
|
9
|
+
module Errors
|
10
|
+
class StepHasNoOrganizer < ::ConvenientService::Error
|
11
|
+
def initialize(step:)
|
12
|
+
message = <<~TEXT
|
13
|
+
Step `#{step.service}` has not assigned organizer.
|
12
14
|
|
13
|
-
|
14
|
-
|
15
|
+
Did you forget to set it?
|
16
|
+
TEXT
|
15
17
|
|
16
|
-
|
18
|
+
super(message)
|
19
|
+
end
|
20
|
+
end
|
17
21
|
end
|
18
22
|
end
|
19
23
|
end
|
@@ -8,33 +8,49 @@ module ConvenientService
|
|
8
8
|
class StepCollection
|
9
9
|
include ::Enumerable
|
10
10
|
|
11
|
+
##
|
12
|
+
# @!attribute [r] steps
|
13
|
+
# @return [Array<ConvenientService::Service::Plugins::CanHaveSteps::Entities::Step>]
|
14
|
+
#
|
11
15
|
attr_reader :steps
|
12
16
|
|
13
|
-
|
14
|
-
|
17
|
+
##
|
18
|
+
# @param steps [Array<ConvenientService::Service::Plugins::CanHaveSteps::Entities::Step>]
|
19
|
+
# @return [void]
|
20
|
+
#
|
21
|
+
def initialize(steps: [])
|
22
|
+
@steps = steps
|
15
23
|
end
|
16
24
|
|
17
25
|
##
|
18
|
-
#
|
26
|
+
# @return [Boolean] true if called for the first time, false otherwise (similarly as Kernel#require).
|
27
|
+
#
|
28
|
+
# @see https://ruby-doc.org/core-3.1.2/Kernel.html#method-i-require
|
29
|
+
#
|
30
|
+
# @internal
|
31
|
+
# IMPORTANT: `step.validate!` is intentionally removed from `steps.each { |step| step.validate! && step.define! }.freeze` since it is NOT idempotent.
|
32
|
+
#
|
33
|
+
# NOTE: `step.validate!` is still useful as a `doctor` command.
|
19
34
|
#
|
20
35
|
def commit!
|
21
36
|
return false if committed?
|
22
37
|
|
23
|
-
|
24
|
-
# IMPORTANT: Temporarily removed `step.validate!` since it is neither thread-safe nor idempotent.
|
25
|
-
#
|
26
|
-
steps.each { |step| step.define! }.freeze
|
38
|
+
steps.each(&:define!).freeze
|
27
39
|
|
28
40
|
true
|
29
41
|
end
|
30
42
|
|
31
43
|
##
|
32
|
-
#
|
44
|
+
# @return [Boolean]
|
33
45
|
#
|
34
46
|
def committed?
|
35
47
|
steps.frozen?
|
36
48
|
end
|
37
49
|
|
50
|
+
##
|
51
|
+
# @param block [Proc, nil]
|
52
|
+
# @return [Array<ConvenientService::Service::Plugins::CanHaveSteps::Entities::Step>, Enumerator]
|
53
|
+
#
|
38
54
|
def each(&block)
|
39
55
|
steps.each(&block)
|
40
56
|
end
|
@@ -52,10 +68,20 @@ module ConvenientService
|
|
52
68
|
steps[index]
|
53
69
|
end
|
54
70
|
|
71
|
+
##
|
72
|
+
# @param step [ConvenientService::Service::Plugins::CanHaveSteps::Entities::Step]
|
73
|
+
# @return [ConvenientService::Service::Plugins::CanHaveSteps::Entities::StepCollection]
|
74
|
+
#
|
55
75
|
def <<(step)
|
56
76
|
steps << step.copy(overrides: {kwargs: {index: next_available_index}})
|
77
|
+
|
78
|
+
self
|
57
79
|
end
|
58
80
|
|
81
|
+
##
|
82
|
+
# @param other [Object] Can be any type.
|
83
|
+
# @return [Boolean, nil]
|
84
|
+
#
|
59
85
|
def ==(other)
|
60
86
|
return unless other.instance_of?(self.class)
|
61
87
|
|
@@ -66,6 +92,9 @@ module ConvenientService
|
|
66
92
|
|
67
93
|
private
|
68
94
|
|
95
|
+
##
|
96
|
+
# @return [Integer]
|
97
|
+
#
|
69
98
|
def next_available_index
|
70
99
|
steps.size
|
71
100
|
end
|
@@ -7,6 +7,19 @@ module ConvenientService
|
|
7
7
|
module Concern
|
8
8
|
include Support::Concern
|
9
9
|
|
10
|
+
included do |service_class|
|
11
|
+
service_class.extend ClassMethods
|
12
|
+
|
13
|
+
##
|
14
|
+
# IMPORTANT:
|
15
|
+
# - Initializes `stubbed_results` during the `include Concern` process.
|
16
|
+
# - Tries to enforce thread-safety in such a way.
|
17
|
+
# - https://github.com/ruby/spec/blob/master/core/module/include_spec.rb
|
18
|
+
# - https://github.com/ruby/ruby/blob/master/class.c
|
19
|
+
#
|
20
|
+
service_class.stubbed_results
|
21
|
+
end
|
22
|
+
|
10
23
|
class_methods do
|
11
24
|
##
|
12
25
|
# @return [ConvenientService::Support::Cache]
|
@@ -17,16 +30,8 @@ module ConvenientService
|
|
17
30
|
# - https://github.com/rspec/rspec-core/blob/v3.12.0/lib/rspec/core.rb#L122
|
18
31
|
# - https://relishapp.com/rspec/rspec-core/docs/metadata/current-example
|
19
32
|
#
|
20
|
-
# TODO: Mutex for thread-safety when parallel steps will be supported.
|
21
|
-
#
|
22
33
|
def stubbed_results
|
23
|
-
return Support::Cache.new unless Support::Gems::RSpec.current_example
|
24
|
-
|
25
34
|
##
|
26
|
-
# IMPORTANT: ivar name with class and current thread enforces thread safety since there is no resource to share.
|
27
|
-
#
|
28
|
-
# TODO: Thread safety specs.
|
29
|
-
#
|
30
35
|
# NOTE: `self` is a service class in the current context. For example:
|
31
36
|
#
|
32
37
|
# before do
|
@@ -37,9 +42,12 @@ module ConvenientService
|
|
37
42
|
#
|
38
43
|
# # Then `self` is `ConvenientService::Examples::Standard::Gemfile::Services::RunShell`.
|
39
44
|
#
|
40
|
-
|
41
|
-
|
42
|
-
|
45
|
+
cache =
|
46
|
+
if Support::Gems::RSpec.current_example
|
47
|
+
Utils::Object.instance_variable_fetch(Support::Gems::RSpec.current_example, :@__convenient_service_stubbed_results__) { Support::Cache.new }
|
48
|
+
else
|
49
|
+
Support::Cache.new
|
50
|
+
end
|
43
51
|
|
44
52
|
cache.scope(self)
|
45
53
|
end
|
@@ -6,9 +6,9 @@ module ConvenientService
|
|
6
6
|
module CanHaveStubbedResult
|
7
7
|
class Middleware < Core::MethodChainMiddleware
|
8
8
|
##
|
9
|
-
# @param args [Array]
|
10
|
-
# @param kwargs [Hash]
|
11
|
-
# @param block [Proc]
|
9
|
+
# @param args [Array<Object>]
|
10
|
+
# @param kwargs [Hash{Symbol => Object}]
|
11
|
+
# @param block [Proc, nil]
|
12
12
|
# @return [Object] Can be any type.
|
13
13
|
#
|
14
14
|
def next(*args, **kwargs, &block)
|
@@ -16,7 +16,7 @@ module ConvenientService
|
|
16
16
|
|
17
17
|
##
|
18
18
|
# @api public
|
19
|
-
# @param kwargs [Hash]
|
19
|
+
# @param kwargs [Hash{Symbol => Object}]
|
20
20
|
# @return [ConvenientService::Service::Plugins::HasResult::Entities::Result]
|
21
21
|
#
|
22
22
|
def success(**kwargs)
|
@@ -25,7 +25,7 @@ module ConvenientService
|
|
25
25
|
|
26
26
|
##
|
27
27
|
# @api public
|
28
|
-
# @param kwargs [Hash]
|
28
|
+
# @param kwargs [Hash{Symbol => Object}]
|
29
29
|
# @return [ConvenientService::Service::Plugins::HasResult::Entities::Result]
|
30
30
|
#
|
31
31
|
def failure(**kwargs)
|
@@ -34,7 +34,7 @@ module ConvenientService
|
|
34
34
|
|
35
35
|
##
|
36
36
|
# @api public
|
37
|
-
# @param kwargs [Hash]
|
37
|
+
# @param kwargs [Hash{Symbol => Object}]
|
38
38
|
# @return [ConvenientService::Service::Plugins::HasResult::Entities::Result]
|
39
39
|
#
|
40
40
|
def error(**kwargs)
|
@@ -16,11 +16,12 @@ module ConvenientService
|
|
16
16
|
# @return [ConvenientService::Service::Plugins::HasResult::Entities::Result, nil]
|
17
17
|
#
|
18
18
|
def parent
|
19
|
-
|
19
|
+
Utils::Object.memoize_including_falsy_values(self, :@parent) { internals.cache[:parent] }
|
20
20
|
end
|
21
21
|
|
22
22
|
##
|
23
23
|
# @param include_self [Boolean]
|
24
|
+
# @param limit [Integer]
|
24
25
|
# @return [Array<ConvenientService::Service::Plugins::HasResult::Entities::Result>]
|
25
26
|
#
|
26
27
|
# @internal
|
@@ -46,17 +47,18 @@ module ConvenientService
|
|
46
47
|
# parents
|
47
48
|
# end
|
48
49
|
#
|
49
|
-
def parents(include_self: false)
|
50
|
-
parents_enum(include_self: include_self).to_a
|
50
|
+
def parents(include_self: false, limit: Constants::PARENTS_LIMIT)
|
51
|
+
parents_enum(include_self: include_self, limit: limit).to_a
|
51
52
|
end
|
52
53
|
|
53
54
|
##
|
54
55
|
# @param include_self [Boolean]
|
56
|
+
# @param limit [Integer]
|
55
57
|
# @return [Enumerator<ConvenientService::Service::Plugins::HasResult::Entities::Result>]
|
56
58
|
#
|
57
59
|
# @see https://ruby-doc.org/core-2.7.0/Enumerator.html
|
58
60
|
#
|
59
|
-
def parents_enum(include_self: false)
|
61
|
+
def parents_enum(include_self: false, limit: Constants::PARENTS_LIMIT)
|
60
62
|
::Enumerator.new do |yielder|
|
61
63
|
yielder.yield(self) if include_self
|
62
64
|
|
@@ -66,7 +68,12 @@ module ConvenientService
|
|
66
68
|
#
|
67
69
|
parent = parent()
|
68
70
|
|
69
|
-
|
71
|
+
##
|
72
|
+
# NOTE: `finite_loop` is used to avoid even a theoretical infinite loop.
|
73
|
+
#
|
74
|
+
Support::FiniteLoop.finite_loop(max_iteration_count: limit, raise_on_exceedance: false) do
|
75
|
+
break unless parent
|
76
|
+
|
70
77
|
yielder.yield(parent)
|
71
78
|
|
72
79
|
parent = parent.parent
|
@@ -7,10 +7,9 @@ module ConvenientService
|
|
7
7
|
module Entities
|
8
8
|
class Result
|
9
9
|
module Plugins
|
10
|
-
module
|
11
|
-
module
|
12
|
-
|
13
|
-
end
|
10
|
+
module CanHaveParentResult
|
11
|
+
module Constants
|
12
|
+
PARENTS_LIMIT = 1_000
|
14
13
|
end
|
15
14
|
end
|
16
15
|
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ConvenientService
|
4
|
+
module Service
|
5
|
+
module Plugins
|
6
|
+
module HasResult
|
7
|
+
module Entities
|
8
|
+
class Result
|
9
|
+
module Plugins
|
10
|
+
module HasJSendStatusAndAttributes
|
11
|
+
module Commands
|
12
|
+
class CreateCodeClass < Support::Command
|
13
|
+
include Support::DependencyContainer::Import
|
14
|
+
|
15
|
+
##
|
16
|
+
# @!attribute [r] result_class
|
17
|
+
# @return Class
|
18
|
+
#
|
19
|
+
attr_reader :result_class
|
20
|
+
|
21
|
+
##
|
22
|
+
# @return Class
|
23
|
+
#
|
24
|
+
import :"commands.FindOrCreateEntity", from: Common::Plugins::CanHaveUserProvidedEntity::Container
|
25
|
+
|
26
|
+
##
|
27
|
+
# @param result_class [Class]
|
28
|
+
# @return [void]
|
29
|
+
#
|
30
|
+
def initialize(result_class:)
|
31
|
+
@result_class = result_class
|
32
|
+
end
|
33
|
+
|
34
|
+
##
|
35
|
+
# @return [Class]
|
36
|
+
#
|
37
|
+
def call
|
38
|
+
commands.FindOrCreateEntity.call(namespace: result_class, proto_entity: Entities::Code)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ConvenientService
|
4
|
+
module Service
|
5
|
+
module Plugins
|
6
|
+
module HasResult
|
7
|
+
module Entities
|
8
|
+
class Result
|
9
|
+
module Plugins
|
10
|
+
module HasJSendStatusAndAttributes
|
11
|
+
module Commands
|
12
|
+
class CreateDataClass < Support::Command
|
13
|
+
include Support::DependencyContainer::Import
|
14
|
+
|
15
|
+
##
|
16
|
+
# @!attribute [r] result_class
|
17
|
+
# @return Class
|
18
|
+
#
|
19
|
+
attr_reader :result_class
|
20
|
+
|
21
|
+
##
|
22
|
+
# @return Class
|
23
|
+
#
|
24
|
+
import :"commands.FindOrCreateEntity", from: Common::Plugins::CanHaveUserProvidedEntity::Container
|
25
|
+
|
26
|
+
##
|
27
|
+
# @param result_class [Class]
|
28
|
+
# @return [void]
|
29
|
+
#
|
30
|
+
def initialize(result_class:)
|
31
|
+
@result_class = result_class
|
32
|
+
end
|
33
|
+
|
34
|
+
##
|
35
|
+
# @return [Class]
|
36
|
+
#
|
37
|
+
def call
|
38
|
+
commands.FindOrCreateEntity.call(namespace: result_class, proto_entity: Entities::Data)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ConvenientService
|
4
|
+
module Service
|
5
|
+
module Plugins
|
6
|
+
module HasResult
|
7
|
+
module Entities
|
8
|
+
class Result
|
9
|
+
module Plugins
|
10
|
+
module HasJSendStatusAndAttributes
|
11
|
+
module Commands
|
12
|
+
class CreateMessageClass < Support::Command
|
13
|
+
include Support::DependencyContainer::Import
|
14
|
+
|
15
|
+
##
|
16
|
+
# @!attribute [r] result_class
|
17
|
+
# @return Class
|
18
|
+
#
|
19
|
+
attr_reader :result_class
|
20
|
+
|
21
|
+
##
|
22
|
+
# @return Class
|
23
|
+
#
|
24
|
+
import :"commands.FindOrCreateEntity", from: Common::Plugins::CanHaveUserProvidedEntity::Container
|
25
|
+
|
26
|
+
##
|
27
|
+
# @param result_class [Class]
|
28
|
+
# @return [void]
|
29
|
+
#
|
30
|
+
def initialize(result_class:)
|
31
|
+
@result_class = result_class
|
32
|
+
end
|
33
|
+
|
34
|
+
##
|
35
|
+
# @return [Class]
|
36
|
+
#
|
37
|
+
def call
|
38
|
+
commands.FindOrCreateEntity.call(namespace: result_class, proto_entity: Entities::Message)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ConvenientService
|
4
|
+
module Service
|
5
|
+
module Plugins
|
6
|
+
module HasResult
|
7
|
+
module Entities
|
8
|
+
class Result
|
9
|
+
module Plugins
|
10
|
+
module HasJSendStatusAndAttributes
|
11
|
+
module Commands
|
12
|
+
class CreateStatusClass < Support::Command
|
13
|
+
include Support::DependencyContainer::Import
|
14
|
+
|
15
|
+
##
|
16
|
+
# @!attribute [r] result_class
|
17
|
+
# @return Class
|
18
|
+
#
|
19
|
+
attr_reader :result_class
|
20
|
+
|
21
|
+
##
|
22
|
+
# @return Class
|
23
|
+
#
|
24
|
+
import :"commands.FindOrCreateEntity", from: Common::Plugins::CanHaveUserProvidedEntity::Container
|
25
|
+
|
26
|
+
##
|
27
|
+
# @param result_class [Class]
|
28
|
+
# @return [void]
|
29
|
+
#
|
30
|
+
def initialize(result_class:)
|
31
|
+
@result_class = result_class
|
32
|
+
end
|
33
|
+
|
34
|
+
##
|
35
|
+
# @return [Class]
|
36
|
+
#
|
37
|
+
def call
|
38
|
+
commands.FindOrCreateEntity.call(namespace: result_class, proto_entity: Entities::Status)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "commands/cast_j_send_attributes"
|
4
|
+
require_relative "commands/create_code_class"
|
5
|
+
require_relative "commands/create_data_class"
|
6
|
+
require_relative "commands/create_message_class"
|
7
|
+
require_relative "commands/create_status_class"
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ConvenientService
|
4
|
+
module Service
|
5
|
+
module Plugins
|
6
|
+
module HasResult
|
7
|
+
module Entities
|
8
|
+
class Result
|
9
|
+
module Plugins
|
10
|
+
module HasJSendStatusAndAttributes
|
11
|
+
module Concern
|
12
|
+
module ClassMethods
|
13
|
+
##
|
14
|
+
# @api private
|
15
|
+
# @return [Class]
|
16
|
+
#
|
17
|
+
# @internal
|
18
|
+
# NOTE: A command instead of `import` is used in order to NOT pollute the public interface.
|
19
|
+
# TODO: Specs that prevent public interface accidental pollution.
|
20
|
+
#
|
21
|
+
def code_class
|
22
|
+
@code_class ||= Commands::CreateCodeClass.call(result_class: self)
|
23
|
+
end
|
24
|
+
|
25
|
+
##
|
26
|
+
# @api private
|
27
|
+
# @return [Class]
|
28
|
+
#
|
29
|
+
# @internal
|
30
|
+
# NOTE: A command instead of `import` is used in order to NOT pollute the public interface.
|
31
|
+
# TODO: Specs that prevent public interface accidental pollution.
|
32
|
+
#
|
33
|
+
def data_class
|
34
|
+
@data_class ||= Commands::CreateDataClass.call(result_class: self)
|
35
|
+
end
|
36
|
+
|
37
|
+
##
|
38
|
+
# @api private
|
39
|
+
# @return [Class]
|
40
|
+
#
|
41
|
+
# @internal
|
42
|
+
# NOTE: A command instead of `import` is used in order to NOT pollute the public interface.
|
43
|
+
# TODO: Specs that prevent public interface accidental pollution.
|
44
|
+
#
|
45
|
+
def message_class
|
46
|
+
@message_class ||= Commands::CreateMessageClass.call(result_class: self)
|
47
|
+
end
|
48
|
+
|
49
|
+
##
|
50
|
+
# @api private
|
51
|
+
# @return [Class]
|
52
|
+
#
|
53
|
+
# @internal
|
54
|
+
# NOTE: A command instead of `import` is used in order to NOT pollute the public interface.
|
55
|
+
# TODO: Specs that prevent public interface accidental pollution.
|
56
|
+
#
|
57
|
+
def status_class
|
58
|
+
@status_class ||= Commands::CreateStatusClass.call(result_class: self)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|