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
@@ -0,0 +1,58 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ConvenientService
|
4
|
+
module Support
|
5
|
+
module DependencyContainer
|
6
|
+
module Commands
|
7
|
+
class AssertValidMethod < Support::Command
|
8
|
+
##
|
9
|
+
# @!attribute [r] full_name
|
10
|
+
# @return [String, Symbol]
|
11
|
+
#
|
12
|
+
attr_reader :full_name
|
13
|
+
|
14
|
+
##
|
15
|
+
# @!attribute [r] scope
|
16
|
+
# @return [Symbol]
|
17
|
+
#
|
18
|
+
attr_reader :scope
|
19
|
+
|
20
|
+
##
|
21
|
+
# @!attribute [r] container
|
22
|
+
# @return [Module]
|
23
|
+
#
|
24
|
+
attr_reader :container
|
25
|
+
|
26
|
+
##
|
27
|
+
# @param full_name [String, Symbol]
|
28
|
+
# @param scope [Symbol]
|
29
|
+
# @param container[Module]
|
30
|
+
# @return [void]
|
31
|
+
#
|
32
|
+
def initialize(full_name:, scope:, container:)
|
33
|
+
@full_name = full_name
|
34
|
+
@scope = scope
|
35
|
+
@container = container
|
36
|
+
end
|
37
|
+
|
38
|
+
##
|
39
|
+
# @return [void]
|
40
|
+
# @raise [ConvenientService::Support::DependencyContainer::Errors::NotExportedMethod]
|
41
|
+
#
|
42
|
+
def call
|
43
|
+
raise Errors::NotExportedMethod.new(method_name: full_name, method_scope: scope, mod: container) unless method
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
##
|
49
|
+
# @return [ConvenientService::Support::DependencyContainer::Entities::Method, nil]
|
50
|
+
#
|
51
|
+
def method
|
52
|
+
container.exported_methods.find_by(full_name: full_name, scope: scope)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -7,12 +7,12 @@ module ConvenientService
|
|
7
7
|
class AssertValidScope < Support::Command
|
8
8
|
##
|
9
9
|
# @!attribute [r] scope
|
10
|
-
# @return [
|
10
|
+
# @return [Symbol]
|
11
11
|
#
|
12
12
|
attr_reader :scope
|
13
13
|
|
14
14
|
##
|
15
|
-
# @param scope [
|
15
|
+
# @param scope [Symbol]
|
16
16
|
# @return [void]
|
17
17
|
#
|
18
18
|
def initialize(scope:)
|
@@ -20,7 +20,8 @@ module ConvenientService
|
|
20
20
|
end
|
21
21
|
|
22
22
|
##
|
23
|
-
# @return [
|
23
|
+
# @return [void]
|
24
|
+
# @raise [ConvenientService::Support::DependencyContainer::Errors::InvalidScope]
|
24
25
|
#
|
25
26
|
def call
|
26
27
|
raise Errors::InvalidScope.new(scope: scope) unless Constants::SCOPES.include?(scope)
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ConvenientService
|
4
|
+
module Support
|
5
|
+
module DependencyContainer
|
6
|
+
module Commands
|
7
|
+
class DefineEntry < Support::Command
|
8
|
+
##
|
9
|
+
# @!attribute [r] container
|
10
|
+
# @return [Module]
|
11
|
+
#
|
12
|
+
attr_reader :container
|
13
|
+
|
14
|
+
##
|
15
|
+
# @!attribute [r] name
|
16
|
+
# @return [String, Symbol]
|
17
|
+
#
|
18
|
+
attr_reader :name
|
19
|
+
|
20
|
+
##
|
21
|
+
# @!attribute [r] body
|
22
|
+
# @return [Proc]
|
23
|
+
#
|
24
|
+
attr_reader :body
|
25
|
+
|
26
|
+
##
|
27
|
+
# @param container [Module]
|
28
|
+
# @param name [String, Symbol]
|
29
|
+
# @param body [Proc]
|
30
|
+
#
|
31
|
+
def initialize(container:, name:, body:)
|
32
|
+
@container = container
|
33
|
+
@name = name
|
34
|
+
@body = body
|
35
|
+
end
|
36
|
+
|
37
|
+
##
|
38
|
+
# @return [String, Symbol]
|
39
|
+
#
|
40
|
+
def call
|
41
|
+
container.define_singleton_method(name, &body)
|
42
|
+
|
43
|
+
name
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -1,5 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative "commands/assert_valid_scope"
|
4
|
+
require_relative "commands/assert_valid_container"
|
5
|
+
require_relative "commands/assert_valid_method"
|
4
6
|
require_relative "commands/create_methods_module"
|
7
|
+
require_relative "commands/define_entry"
|
5
8
|
require_relative "commands/import_method"
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ConvenientService
|
4
|
+
module Support
|
5
|
+
module DependencyContainer
|
6
|
+
module Container
|
7
|
+
include Export
|
8
|
+
|
9
|
+
export :"constants.DEFAULT_SCOPE" do
|
10
|
+
Constants::DEFAULT_SCOPE
|
11
|
+
end
|
12
|
+
|
13
|
+
export :"commands.AssertValidContainer" do
|
14
|
+
Commands::AssertValidContainer
|
15
|
+
end
|
16
|
+
|
17
|
+
export :"commands.AssertValidScope" do
|
18
|
+
Commands::AssertValidScope
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ConvenientService
|
4
|
+
module Support
|
5
|
+
module DependencyContainer
|
6
|
+
module Entry
|
7
|
+
include Support::Concern
|
8
|
+
|
9
|
+
class_methods do
|
10
|
+
##
|
11
|
+
# @param name [String, Symbol]
|
12
|
+
# @param body [Proc]
|
13
|
+
# @return [String, Symbol]
|
14
|
+
#
|
15
|
+
def entry(name, &body)
|
16
|
+
Commands::DefineEntry.call(container: self, name: name, body: body)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -4,7 +4,7 @@ module ConvenientService
|
|
4
4
|
module Support
|
5
5
|
module DependencyContainer
|
6
6
|
module Errors
|
7
|
-
class InvalidScope < ConvenientService::Error
|
7
|
+
class InvalidScope < ::ConvenientService::Error
|
8
8
|
##
|
9
9
|
# @param scope [Object]
|
10
10
|
# @return [void]
|
@@ -29,7 +29,7 @@ module ConvenientService
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
class NotExportableModule < ConvenientService::Error
|
32
|
+
class NotExportableModule < ::ConvenientService::Error
|
33
33
|
##
|
34
34
|
# @param mod [Module]
|
35
35
|
# @return [void]
|
@@ -38,14 +38,14 @@ module ConvenientService
|
|
38
38
|
message = <<~TEXT
|
39
39
|
Module `#{mod}` can NOT export methods.
|
40
40
|
|
41
|
-
Did you forget to include `ConvenientService::
|
41
|
+
Did you forget to include `ConvenientService::DependencyContainer::Export` into it?
|
42
42
|
TEXT
|
43
43
|
|
44
44
|
super(message)
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
-
class NotExportedMethod < ConvenientService::Error
|
48
|
+
class NotExportedMethod < ::ConvenientService::Error
|
49
49
|
##
|
50
50
|
# @param method_name [String]
|
51
51
|
# @param method_scope [Symbol]
|
@@ -69,7 +69,7 @@ module ConvenientService
|
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
72
|
-
class NotModule < ConvenientService::Error
|
72
|
+
class NotModule < ::ConvenientService::Error
|
73
73
|
##
|
74
74
|
# @param klass [Class]
|
75
75
|
# @return [void]
|
@@ -17,11 +17,11 @@ module ConvenientService
|
|
17
17
|
def import(full_name, from:, scope: Constants::DEFAULT_SCOPE, prepend: Constants::DEFAULT_PREPEND)
|
18
18
|
Commands::AssertValidScope.call(scope: scope)
|
19
19
|
|
20
|
-
|
20
|
+
Commands::AssertValidContainer.call(container: from)
|
21
21
|
|
22
|
-
|
22
|
+
Commands::AssertValidMethod.call(full_name: full_name, scope: scope, container: from)
|
23
23
|
|
24
|
-
|
24
|
+
method = from.exported_methods.find_by(full_name: full_name, scope: scope)
|
25
25
|
|
26
26
|
Commands::ImportMethod.call(importing_module: self, exported_method: method, prepend: prepend)
|
27
27
|
end
|
@@ -5,5 +5,8 @@ require_relative "dependency_container/constants"
|
|
5
5
|
require_relative "dependency_container/entities"
|
6
6
|
require_relative "dependency_container/errors"
|
7
7
|
|
8
|
+
require_relative "dependency_container/entry"
|
8
9
|
require_relative "dependency_container/export"
|
9
10
|
require_relative "dependency_container/import"
|
11
|
+
|
12
|
+
require_relative "dependency_container/container"
|
@@ -3,10 +3,17 @@
|
|
3
3
|
module ConvenientService
|
4
4
|
module Support
|
5
5
|
module FiniteLoop
|
6
|
+
##
|
7
|
+
# @return [Integer]
|
8
|
+
#
|
6
9
|
MAX_ITERATION_COUNT = 1_000
|
7
10
|
|
8
11
|
module Errors
|
9
|
-
class MaxIterationCountExceeded < ::
|
12
|
+
class MaxIterationCountExceeded < ::ConvenientService::Error
|
13
|
+
##
|
14
|
+
# @param limit [Integer]
|
15
|
+
# @return [void]
|
16
|
+
#
|
10
17
|
def initialize(limit:)
|
11
18
|
message = <<~TEXT
|
12
19
|
Max iteration count is exceeded. Current limit is #{limit}.
|
@@ -18,7 +25,10 @@ module ConvenientService
|
|
18
25
|
end
|
19
26
|
end
|
20
27
|
|
21
|
-
class NoBlockGiven < ::
|
28
|
+
class NoBlockGiven < ::ConvenientService::Error
|
29
|
+
##
|
30
|
+
# @return [void]
|
31
|
+
#
|
22
32
|
def initialize
|
23
33
|
message = <<~TEXT
|
24
34
|
`finite_loop` always expects a block to be given.
|
@@ -31,6 +41,31 @@ module ConvenientService
|
|
31
41
|
|
32
42
|
private
|
33
43
|
|
44
|
+
##
|
45
|
+
# @example Provides `self.finite_loop` in order to have a way to use `finite_loop` without including `ConvenientService::Support::FiniteLoop`.
|
46
|
+
# ConvenientService::Support::FiniteLoop.finite_loop do |index|
|
47
|
+
# break if index > 3
|
48
|
+
# end
|
49
|
+
#
|
50
|
+
module_function
|
51
|
+
|
52
|
+
##
|
53
|
+
# @param max_iteration_count [Integer]
|
54
|
+
# @param raise_on_exceedance [Boolean]
|
55
|
+
# @param block [Proc, nil]
|
56
|
+
# @return [Object] Can be any type.
|
57
|
+
#
|
58
|
+
# @example
|
59
|
+
# class Person
|
60
|
+
# include ConvenientService::Support::FiniteLoop
|
61
|
+
#
|
62
|
+
# def foo
|
63
|
+
# finite_loop do |index|
|
64
|
+
# break if index > 3
|
65
|
+
# end
|
66
|
+
# end
|
67
|
+
# end
|
68
|
+
#
|
34
69
|
def finite_loop(max_iteration_count: MAX_ITERATION_COUNT, raise_on_exceedance: true, &block)
|
35
70
|
raise Errors::NoBlockGiven.new unless block
|
36
71
|
|
@@ -13,7 +13,7 @@ module ConvenientService
|
|
13
13
|
class StackBuilder < Dependencies::Extractions::RubyMiddleware::Middleware::Builder
|
14
14
|
##
|
15
15
|
# @param opts [Hash]
|
16
|
-
# @param block [Proc]
|
16
|
+
# @param block [Proc, nil]
|
17
17
|
# @return [void]
|
18
18
|
#
|
19
19
|
# @see https://github.com/marian13/ruby-middleware/blob/v0.4.2/lib/middleware/builder.rb#L43
|
@@ -2,8 +2,9 @@
|
|
2
2
|
|
3
3
|
module ConvenientService
|
4
4
|
module Support
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
##
|
6
|
+
# @return [ConvenientService::Support::UniqueValue]
|
7
|
+
#
|
8
|
+
NOT_PASSED = Support::UniqueValue.new("not_passed")
|
8
9
|
end
|
9
10
|
end
|
@@ -16,6 +16,37 @@ module ConvenientService
|
|
16
16
|
def version
|
17
17
|
@version ||= Support::Version.new(::RUBY_VERSION)
|
18
18
|
end
|
19
|
+
|
20
|
+
##
|
21
|
+
# Returns `true` when JRuby, `false` otherwise.
|
22
|
+
#
|
23
|
+
# @return [Boolean]
|
24
|
+
#
|
25
|
+
# @see https://github.com/rdp/os
|
26
|
+
#
|
27
|
+
# @internal
|
28
|
+
# NOTE: Gratefully copied from the `os` gem. Version `1.1.4`.
|
29
|
+
# - https://github.com/rdp/os/blob/v1.1.4/lib/os.rb#L101
|
30
|
+
#
|
31
|
+
# NOTE: Modified original implementation in order to return a boolean.
|
32
|
+
#
|
33
|
+
def jruby?
|
34
|
+
::RUBY_PLATFORM.to_s.match?(/java/)
|
35
|
+
end
|
36
|
+
|
37
|
+
##
|
38
|
+
# Returns `true` when TruffleRuby, `false` otherwise.
|
39
|
+
#
|
40
|
+
# @return [Boolean]
|
41
|
+
#
|
42
|
+
# @internal
|
43
|
+
# NOTE: Taken from irb testing. May NOT be stable.
|
44
|
+
#
|
45
|
+
# TODO: Find a confirmation of stability.
|
46
|
+
#
|
47
|
+
def truffleruby?
|
48
|
+
::RUBY_ENGINE.to_s.match?(/truffleruby/)
|
49
|
+
end
|
19
50
|
end
|
20
51
|
end
|
21
52
|
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ConvenientService
|
4
|
+
module Support
|
5
|
+
class SafeMethod
|
6
|
+
##
|
7
|
+
# @!attribute [r] object
|
8
|
+
# @return [Object] Can be any type.
|
9
|
+
#
|
10
|
+
attr_reader :object
|
11
|
+
|
12
|
+
##
|
13
|
+
# @!attribute [r] method
|
14
|
+
# @return [Symbol, String]
|
15
|
+
#
|
16
|
+
attr_reader :method
|
17
|
+
|
18
|
+
##
|
19
|
+
# @!attribute [r] default
|
20
|
+
# @return [Object] Can be any type.
|
21
|
+
#
|
22
|
+
attr_reader :default
|
23
|
+
|
24
|
+
##
|
25
|
+
# @param object [Object] Can be any type.
|
26
|
+
# @param method [Symbol, String]
|
27
|
+
# @param default [Object, nil] Can be any type.
|
28
|
+
# @return [void]
|
29
|
+
#
|
30
|
+
def initialize(object, method, default: nil)
|
31
|
+
@object = object
|
32
|
+
@method = method
|
33
|
+
@default = default
|
34
|
+
end
|
35
|
+
|
36
|
+
##
|
37
|
+
# @param args [Array<Object>]
|
38
|
+
# @param kwargs [Hash{Symbol => Object}]
|
39
|
+
# @param block [Proc, nil]
|
40
|
+
# @return [Object] Can be any type.
|
41
|
+
#
|
42
|
+
def call(*args, **kwargs, &block)
|
43
|
+
return default unless method_defined?
|
44
|
+
|
45
|
+
object.__send__(method, *args, **kwargs, &block)
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
##
|
51
|
+
# @return [Boolean]
|
52
|
+
#
|
53
|
+
def method_defined?
|
54
|
+
Utils::Method.defined?(method, klass, private: true)
|
55
|
+
end
|
56
|
+
|
57
|
+
##
|
58
|
+
# @return [Class]
|
59
|
+
#
|
60
|
+
def klass
|
61
|
+
@klass ||= Utils::Object.resolve_class(object)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,119 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ConvenientService
|
4
|
+
module Support
|
5
|
+
# @internal
|
6
|
+
# NOTE: Mutex and Semaphore docs.
|
7
|
+
# - https://ruby-doc.org/core-2.7.0/Mutex.html
|
8
|
+
# - https://en.wikipedia.org/wiki/Semaphore_(programming)
|
9
|
+
#
|
10
|
+
class ThreadSafeCounter < Support::Counter
|
11
|
+
##
|
12
|
+
# @see ConvenientService::Support::Counter#current_value=
|
13
|
+
#
|
14
|
+
# @internal
|
15
|
+
# NOTE: Instance variables are accessed directly to release the lock faster.
|
16
|
+
#
|
17
|
+
# IMPORTANT: The lock is always properly released since it uses ensure under the hood.
|
18
|
+
# - https://github.com/ruby/ruby/blob/v2_7_0/thread_sync.c#L525
|
19
|
+
#
|
20
|
+
def current_value=(...)
|
21
|
+
@lock.synchronize { super }
|
22
|
+
end
|
23
|
+
|
24
|
+
##
|
25
|
+
# @see ConvenientService::Support::Counter#increment
|
26
|
+
#
|
27
|
+
# @internal
|
28
|
+
# NOTE: Instance variables are accessed directly to release the lock faster.
|
29
|
+
#
|
30
|
+
# IMPORTANT: The lock is always properly released since it uses ensure under the hood.
|
31
|
+
# - https://github.com/ruby/ruby/blob/v2_7_0/thread_sync.c#L525
|
32
|
+
#
|
33
|
+
def increment(...)
|
34
|
+
@lock.synchronize { super }
|
35
|
+
end
|
36
|
+
|
37
|
+
##
|
38
|
+
# @see ConvenientService::Support::Counter#increment!
|
39
|
+
#
|
40
|
+
# @internal
|
41
|
+
# NOTE: Instance variables are accessed directly to release the lock faster.
|
42
|
+
#
|
43
|
+
# IMPORTANT: The lock is always properly released since it uses ensure under the hood.
|
44
|
+
# - https://github.com/ruby/ruby/blob/v2_7_0/thread_sync.c#L525
|
45
|
+
#
|
46
|
+
def increment!(...)
|
47
|
+
@lock.synchronize { super }
|
48
|
+
end
|
49
|
+
|
50
|
+
##
|
51
|
+
# `bincrement` means boolean increment. Works exactly in the same way as `increment` except returns a boolean value.
|
52
|
+
# If incremented successfully then returns `true`, otherwise - returns `false`.
|
53
|
+
#
|
54
|
+
# @see ConvenientService::Support::Counter#bincrement
|
55
|
+
#
|
56
|
+
# @internal
|
57
|
+
# NOTE: Instance variables are accessed directly to release the lock faster.
|
58
|
+
#
|
59
|
+
# IMPORTANT: The lock is always properly released since it uses ensure under the hood.
|
60
|
+
# - https://github.com/ruby/ruby/blob/v2_7_0/thread_sync.c#L525
|
61
|
+
#
|
62
|
+
def bincrement(...)
|
63
|
+
@lock.synchronize { super }
|
64
|
+
end
|
65
|
+
|
66
|
+
##
|
67
|
+
# @see ConvenientService::Support::Counter#decrement
|
68
|
+
#
|
69
|
+
# @internal
|
70
|
+
# NOTE: Instance variables are accessed directly to release the lock faster.
|
71
|
+
#
|
72
|
+
# IMPORTANT: The lock is always properly released since it uses ensure under the hood.
|
73
|
+
# - https://github.com/ruby/ruby/blob/v2_7_0/thread_sync.c#L525
|
74
|
+
#
|
75
|
+
def decrement(...)
|
76
|
+
@lock.synchronize { super }
|
77
|
+
end
|
78
|
+
|
79
|
+
##
|
80
|
+
# @see ConvenientService::Support::Counter#decrement!
|
81
|
+
#
|
82
|
+
# @internal
|
83
|
+
# NOTE: Instance variables are accessed directly to release the lock faster.
|
84
|
+
#
|
85
|
+
# IMPORTANT: The lock is always properly released since it uses ensure under the hood.
|
86
|
+
# - https://github.com/ruby/ruby/blob/v2_7_0/thread_sync.c#L525
|
87
|
+
#
|
88
|
+
def decrement!(...)
|
89
|
+
@lock.synchronize { super }
|
90
|
+
end
|
91
|
+
|
92
|
+
##
|
93
|
+
# `bdecrement` means boolean decrement. Works exactly in the same way as `decrement` except returns a boolean value.
|
94
|
+
# If decremented successfully then returns `true`, otherwise - returns `false`.
|
95
|
+
#
|
96
|
+
# @see ConvenientService::Support::Counter#bdecrement
|
97
|
+
#
|
98
|
+
# @internal
|
99
|
+
# NOTE: Instance variables are accessed directly to release the lock faster.
|
100
|
+
#
|
101
|
+
# IMPORTANT: The lock is always properly released since it uses ensure under the hood.
|
102
|
+
# - https://github.com/ruby/ruby/blob/v2_7_0/thread_sync.c#L525
|
103
|
+
#
|
104
|
+
def bdecrement(...)
|
105
|
+
@lock.synchronize { super }
|
106
|
+
end
|
107
|
+
|
108
|
+
##
|
109
|
+
# @see ConvenientService::Support::Counter#reset
|
110
|
+
#
|
111
|
+
# @internal
|
112
|
+
# NOTE: Instance variables are accessed directly to release the lock faster.
|
113
|
+
#
|
114
|
+
def reset(...)
|
115
|
+
@lock.synchronize { super }
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
@@ -2,8 +2,9 @@
|
|
2
2
|
|
3
3
|
module ConvenientService
|
4
4
|
module Support
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
##
|
6
|
+
# @return [ConvenientService::Support::UniqueValue]
|
7
|
+
#
|
8
|
+
UNDEFINED = Support::UniqueValue.new("undefined")
|
8
9
|
end
|
9
10
|
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ConvenientService
|
4
|
+
module Support
|
5
|
+
class UniqueValue
|
6
|
+
##
|
7
|
+
# @!attribute [r] label
|
8
|
+
# @return [String]
|
9
|
+
#
|
10
|
+
attr_reader :label
|
11
|
+
|
12
|
+
##
|
13
|
+
# @param label [String]
|
14
|
+
# @return [void]
|
15
|
+
#
|
16
|
+
def initialize(label = default_label)
|
17
|
+
@label = label
|
18
|
+
end
|
19
|
+
|
20
|
+
##
|
21
|
+
# @param other [Object] Can be any type.
|
22
|
+
# @return [Boolean]
|
23
|
+
#
|
24
|
+
# @internal
|
25
|
+
# NOTE: Every single Ruby object responds to `object_id`.
|
26
|
+
#
|
27
|
+
def ==(other)
|
28
|
+
return unless other.instance_of?(self.class)
|
29
|
+
|
30
|
+
object_id == other.object_id
|
31
|
+
end
|
32
|
+
|
33
|
+
##
|
34
|
+
# @param other [Object] Can be any type.
|
35
|
+
# @return [Boolean]
|
36
|
+
#
|
37
|
+
def ===(other)
|
38
|
+
self == other
|
39
|
+
end
|
40
|
+
|
41
|
+
##
|
42
|
+
# @param other [Object] Can be any type.
|
43
|
+
# @return [Boolean]
|
44
|
+
#
|
45
|
+
def eql?(other)
|
46
|
+
self == other
|
47
|
+
end
|
48
|
+
|
49
|
+
##
|
50
|
+
# @return [String]
|
51
|
+
#
|
52
|
+
def inspect
|
53
|
+
return default_label if label.nil?
|
54
|
+
return default_label if label.empty?
|
55
|
+
|
56
|
+
label
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
##
|
62
|
+
# @return [String]
|
63
|
+
#
|
64
|
+
def default_label
|
65
|
+
"unique_value_#{object_id}"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative "support/unique_value"
|
3
4
|
require_relative "support/not_passed"
|
4
5
|
require_relative "support/undefined"
|
5
6
|
|
@@ -11,6 +12,7 @@ require_relative "support/cache"
|
|
11
12
|
require_relative "support/castable"
|
12
13
|
require_relative "support/command"
|
13
14
|
require_relative "support/copyable"
|
15
|
+
require_relative "support/counter"
|
14
16
|
require_relative "support/delegate"
|
15
17
|
require_relative "support/dependency_container"
|
16
18
|
require_relative "support/finite_loop"
|
@@ -18,4 +20,6 @@ require_relative "support/gems"
|
|
18
20
|
require_relative "support/middleware"
|
19
21
|
require_relative "support/raw_value"
|
20
22
|
require_relative "support/ruby"
|
23
|
+
require_relative "support/safe_method"
|
24
|
+
require_relative "support/thread_safe_counter"
|
21
25
|
require_relative "support/version"
|