convenient_service 0.25.0 → 0.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/convenient_service/aliases.rb +0 -11
- data/lib/convenient_service/common/plugins/assigns_attributes_in_constructor/using_active_model_attribute_assignment/concern.rb +1 -1
- data/lib/convenient_service/common/plugins/assigns_attributes_in_constructor/using_dry_initializer/concern.rb +1 -1
- data/lib/convenient_service/common/plugins/caches_constructor_arguments/concern.rb +1 -1
- data/lib/convenient_service/common/plugins/can_be_copied/concern.rb +1 -1
- data/lib/convenient_service/common/plugins/can_have_callbacks/concern.rb +1 -1
- data/lib/convenient_service/common/plugins/can_have_callbacks/entities/type/concern.rb +1 -1
- data/lib/convenient_service/common/plugins/can_have_not_passed_arguments/concern.rb +1 -1
- data/lib/convenient_service/common/plugins/can_utilize_finite_loop/concern.rb +1 -1
- data/lib/convenient_service/common/plugins/has_attributes/using_active_model_attributes/concern.rb +1 -1
- data/lib/convenient_service/common/plugins/has_constructor/concern.rb +1 -1
- data/lib/convenient_service/common/plugins/has_constructor_without_initialize/concern.rb +1 -1
- data/lib/convenient_service/common/plugins/has_instance_proxy/concern.rb +1 -1
- data/lib/convenient_service/common/plugins/has_internals/concern.rb +1 -1
- data/lib/convenient_service/common/plugins/has_internals/entities/internals/concern.rb +1 -1
- data/lib/convenient_service/common/plugins/has_internals/entities/internals/plugins/has_cache/concern.rb +1 -1
- data/lib/convenient_service/common/plugins/has_j_send_result_duck_short_syntax/concern.rb +1 -1
- data/lib/convenient_service/common/plugins/has_memoization/using_memo_wise/concern.rb +1 -1
- data/lib/convenient_service/common/plugins/tries_to_convert_result_duck_to_result/middleware.rb +54 -0
- data/lib/convenient_service/common/plugins/tries_to_convert_result_duck_to_result.rb +8 -0
- data/lib/convenient_service/common/plugins.rb +1 -0
- data/lib/convenient_service/config/entities/option.rb +11 -9
- data/lib/convenient_service/config/entities/option_collection.rb +8 -4
- data/lib/convenient_service/core/aliases.rb +50 -0
- data/lib/convenient_service/core/entities/config/commands/build_entity_from_config_option.rb +63 -0
- data/lib/convenient_service/core/entities/config/commands.rb +1 -0
- data/lib/convenient_service/core/entities/config/entities/concerns/usual.rb +50 -0
- data/lib/convenient_service/core/entities/config/entities/concerns.rb +2 -0
- data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/middlewares/base/concern/class_methods.rb +9 -0
- data/lib/convenient_service/feature/plugins/can_have_entries/concern.rb +1 -1
- data/lib/convenient_service/feature/plugins/can_have_rspec_stubbed_entries/concern.rb +1 -1
- data/lib/convenient_service/feature/plugins/can_have_stubbed_entries/concern.rb +1 -1
- data/lib/convenient_service/feature/plugins/has_amazing_print_inspect/concern.rb +1 -1
- data/lib/convenient_service/feature/plugins/has_awesome_print_inspect/concern.rb +1 -1
- data/lib/convenient_service/feature/plugins/has_inspect/concern.rb +1 -1
- data/lib/convenient_service/service/configs/standard/v1.rb +2 -0
- data/lib/convenient_service/service/configs/standard.rb +21 -9
- data/lib/convenient_service/service/plugins/can_be_called/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/can_have_connected_steps/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/can_have_fallbacks/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/can_have_handled_exceptions/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/can_have_inline_services/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/can_have_inline_services/entities/proxy.rb +5 -0
- data/lib/convenient_service/service/plugins/can_have_recalculations/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/can_have_rspec_stubbed_results/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/can_have_sequential_steps/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/can_have_service_aware_enumerables/concern.rb +1 -10
- data/lib/convenient_service/service/plugins/can_have_steps/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/can_have_steps/entities/method/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/can_have_steps/entities/service/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/can_have_steps/entities/step/commands/cast_params.rb +0 -8
- data/lib/convenient_service/service/plugins/can_have_steps/entities/step/commands/extract_params.rb +1 -2
- data/lib/convenient_service/service/plugins/can_have_steps/entities/step/concern/instance_methods.rb +0 -11
- data/lib/convenient_service/service/plugins/can_have_steps/entities/step/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/can_have_steps/entities/step/plugins/can_be_evaluated/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/can_have_steps/entities/step/plugins/can_be_evaluated/middleware.rb +43 -0
- data/lib/convenient_service/service/plugins/can_have_steps/entities/step/plugins/can_be_evaluated.rb +1 -0
- data/lib/convenient_service/service/plugins/can_have_steps/entities/step/plugins/can_be_method_step/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/can_have_steps/entities/step/plugins/can_be_service_step/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/can_have_steps/entities/step/plugins/can_be_strict/concern.rb +35 -0
- data/lib/convenient_service/service/plugins/can_have_steps/entities/step/plugins/can_be_strict/middleware.rb +40 -0
- data/lib/convenient_service/service/plugins/can_have_steps/entities/step/plugins/can_be_strict.rb +9 -0
- data/lib/convenient_service/service/plugins/can_have_steps/entities/step/plugins/can_be_used_in_service_aware_enumerables/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/can_have_steps/entities/step/plugins/can_have_fallbacks/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/can_have_steps/entities/step/plugins/has_amazing_print_inspect/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/can_have_steps/entities/step/plugins/has_awesome_print_inspect/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/can_have_steps/entities/step/plugins/has_inspect/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/can_have_steps/entities/step/plugins/has_result/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/can_have_steps/entities/step/plugins/has_result/middleware.rb +0 -2
- data/lib/convenient_service/service/plugins/can_have_steps/entities/step/plugins.rb +1 -0
- data/lib/convenient_service/service/plugins/can_have_steps/entities/step/structs/params.rb +2 -2
- data/lib/convenient_service/service/plugins/can_have_stubbed_results/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/can_not_be_inherited/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/has_amazing_print_inspect/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/has_awesome_print_inspect/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/has_inspect/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/has_j_send_result/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/can_be_called/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/can_be_from_exception/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/can_be_from_fallback/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/can_be_from_handled_exception/concern.rb +6 -1
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/can_be_from_unhandled_exception/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/can_be_own_result/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/can_be_strict/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/can_be_stubbed_result/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/can_be_used_in_service_aware_enumerables/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/can_have_checked_status/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/can_have_fallbacks/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/can_have_parent_result/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/can_have_step/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_amazing_print_inspect/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_awesome_print_inspect/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_inspect/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/concern/instance_methods.rb +7 -0
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/entities/code/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/entities/code/plugins/has_amazing_print_inspect/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/entities/code/plugins/has_awesome_print_inspect/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/entities/code/plugins/has_inspect/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/entities/data/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/entities/data/plugins/has_amazing_print_inspect/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/entities/data/plugins/has_awesome_print_inspect/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/entities/data/plugins/has_inspect/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/entities/message/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/entities/message/plugins/has_amazing_print_inspect/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/entities/message/plugins/has_awesome_print_inspect/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/entities/message/plugins/has_inspect/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/entities/status/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/entities/status/plugins/can_be_checked/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/entities/status/plugins/has_amazing_print_inspect/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/entities/status/plugins/has_awesome_print_inspect/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/entities/status/plugins/has_inspect/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_negated_result/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_pattern_matching_support/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/helps_to_learn_similarities_with_common_objects/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/has_j_send_result_params_validations/using_active_model_validations/concern.rb +15 -3
- data/lib/convenient_service/service/plugins/has_j_send_result_params_validations/using_active_model_validations/middleware.rb +10 -2
- data/lib/convenient_service/service/plugins/has_j_send_result_params_validations/using_active_model_validations/no_op_concern.rb +116 -0
- data/lib/convenient_service/service/plugins/has_j_send_result_params_validations/using_active_model_validations.rb +1 -0
- data/lib/convenient_service/service/plugins/has_j_send_result_params_validations/using_dry_validation/concern.rb +19 -1
- data/lib/convenient_service/service/plugins/has_j_send_result_params_validations/using_dry_validation/middleware.rb +10 -2
- data/lib/convenient_service/service/plugins/has_j_send_result_params_validations/using_dry_validation/no_op_concern.rb +43 -0
- data/lib/convenient_service/service/plugins/has_j_send_result_params_validations/using_dry_validation.rb +1 -0
- data/lib/convenient_service/service/plugins/has_j_send_result_short_syntax/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/has_j_send_result_status_check_short_syntax/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/has_negated_j_send_result/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/has_negated_result/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/has_result/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/raises_on_not_result_return_value/middleware.rb +7 -3
- data/lib/convenient_service/version.rb +1 -1
- metadata +12 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2720d14bda6c640d8c9e951311f89352f93b8b02018dd6bda721741b2148d542
|
|
4
|
+
data.tar.gz: 443f18f104077ddd7c6a2c87d30ff77c6f34cc267afcbf814a8de3d3f2aff1a7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 27b25614536893aba9bc8f785b5360ba514bc0a23c0dafcf5f8e56df27d698f00a7791595e5fc4b8c0df9e4822fbc9520444d94caebf61926cd8e6644922705b
|
|
7
|
+
data.tar.gz: 90ab1ac704bd5094b6b4b947fe0d73be1dc45da6dc19432ebbe388782027b0cc025325e07f29bdc8d0379dd78411d206c021b090729cbd568353f8de006ba4c8
|
|
@@ -62,17 +62,6 @@ module ConvenientService
|
|
|
62
62
|
#
|
|
63
63
|
Command = ::ConvenientService::Support::Command
|
|
64
64
|
|
|
65
|
-
##
|
|
66
|
-
# Convenient Service concern (Like Rails concern, but with some customizations).
|
|
67
|
-
#
|
|
68
|
-
# @api public
|
|
69
|
-
# @since 1.0.0
|
|
70
|
-
# @return [Module]
|
|
71
|
-
#
|
|
72
|
-
# @note Expected to be used from Convenient Service plugins.
|
|
73
|
-
#
|
|
74
|
-
Concern = ::ConvenientService::Support::Concern
|
|
75
|
-
|
|
76
65
|
##
|
|
77
66
|
# Convenient Service dependency container.
|
|
78
67
|
#
|
|
@@ -11,7 +11,7 @@ module ConvenientService
|
|
|
11
11
|
module AssignsAttributesInConstructor
|
|
12
12
|
module UsingActiveModelAttributeAssignment
|
|
13
13
|
module Concern
|
|
14
|
-
include
|
|
14
|
+
include ::ConvenientService::Concern
|
|
15
15
|
|
|
16
16
|
included do |service_class|
|
|
17
17
|
service_class.include ::ActiveModel::AttributeAssignment
|
data/lib/convenient_service/common/plugins/has_attributes/using_active_model_attributes/concern.rb
CHANGED
|
@@ -11,7 +11,7 @@ module ConvenientService
|
|
|
11
11
|
module HasAttributes
|
|
12
12
|
module UsingActiveModelAttributes
|
|
13
13
|
module Concern
|
|
14
|
-
include
|
|
14
|
+
include ::ConvenientService::Concern
|
|
15
15
|
|
|
16
16
|
included do |service_class|
|
|
17
17
|
service_class.include Patches::ActiveModelAttributes
|
data/lib/convenient_service/common/plugins/tries_to_convert_result_duck_to_result/middleware.rb
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
##
|
|
4
|
+
# @author Marian Kostyk <mariankostyk13895@gmail.com>
|
|
5
|
+
# @license LGPLv3 <https://www.gnu.org/licenses/lgpl-3.0.html>
|
|
6
|
+
##
|
|
7
|
+
|
|
8
|
+
module ConvenientService
|
|
9
|
+
module Common
|
|
10
|
+
module Plugins
|
|
11
|
+
module TriesToConvertResultDuckToResult
|
|
12
|
+
class Middleware < MethodChainMiddleware
|
|
13
|
+
intended_for :result, entity: any_entity
|
|
14
|
+
|
|
15
|
+
##
|
|
16
|
+
# @return [ConvenientService::Service::Plugins::HasJSendResult::Entities::Result]
|
|
17
|
+
#
|
|
18
|
+
# @internal
|
|
19
|
+
# NOTE: When original result is a result duck and it has `NoMethodError` exception, that exception should be raised just like any other exception. See specs for details.
|
|
20
|
+
#
|
|
21
|
+
# NOTE: `exception.receiver` is available on `NameError` descendants (like `NoMethodError`), but NOT on `StandardError`.
|
|
22
|
+
# - https://ruby-doc.org/core-2.7.1/NoMethodError.html
|
|
23
|
+
# - https://ruby-doc.org/core-2.7.1/NameError.html#method-i-receiver
|
|
24
|
+
# - https://ruby-doc.org/core-2.7.1/StandardError.html
|
|
25
|
+
#
|
|
26
|
+
def next(...)
|
|
27
|
+
original_object = chain.next(...)
|
|
28
|
+
|
|
29
|
+
result_duck, result = try_convert(original_object)
|
|
30
|
+
|
|
31
|
+
result_duck ? result : original_object
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
private
|
|
35
|
+
|
|
36
|
+
##
|
|
37
|
+
# @param original_object [Object] Can be any type.
|
|
38
|
+
# @return [Array]
|
|
39
|
+
# @raise [NoMethodError]
|
|
40
|
+
#
|
|
41
|
+
def try_convert(original_object)
|
|
42
|
+
result = original_object.result
|
|
43
|
+
|
|
44
|
+
[true, result]
|
|
45
|
+
rescue ::NoMethodError => exception
|
|
46
|
+
raise exception if original_object.respond_to?(:result)
|
|
47
|
+
|
|
48
|
+
[false, nil]
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -14,6 +14,7 @@ require_relative "plugins/caches_return_value"
|
|
|
14
14
|
require_relative "plugins/can_be_copied"
|
|
15
15
|
require_relative "plugins/can_have_user_provided_entity"
|
|
16
16
|
require_relative "plugins/ensures_negated_j_send_result"
|
|
17
|
+
require_relative "plugins/tries_to_convert_result_duck_to_result"
|
|
17
18
|
require_relative "plugins/can_have_callbacks"
|
|
18
19
|
require_relative "plugins/can_have_not_passed_arguments"
|
|
19
20
|
require_relative "plugins/can_utilize_finite_loop"
|
|
@@ -16,21 +16,26 @@ module ConvenientService
|
|
|
16
16
|
attr_reader :name
|
|
17
17
|
|
|
18
18
|
##
|
|
19
|
-
# @!attribute [r]
|
|
19
|
+
# @!attribute [r] details
|
|
20
20
|
# @return [Hash{Symbol => Object}]
|
|
21
21
|
#
|
|
22
|
-
attr_reader :
|
|
22
|
+
attr_reader :details
|
|
23
|
+
|
|
24
|
+
##
|
|
25
|
+
# @return [Hash{Symbol => Object}]
|
|
26
|
+
#
|
|
27
|
+
alias_method :data, :details
|
|
23
28
|
|
|
24
29
|
##
|
|
25
30
|
# @param name [Symbol]
|
|
26
31
|
# @param enabled [Object] Can be any type.
|
|
27
|
-
# @param
|
|
32
|
+
# @param details [Hash{Symbol => Object}]
|
|
28
33
|
# @return [void]
|
|
29
34
|
#
|
|
30
|
-
def initialize(name:, enabled: false, **
|
|
35
|
+
def initialize(name:, enabled: false, **details)
|
|
31
36
|
@name = name
|
|
32
37
|
@enabled = Utils.to_bool(enabled)
|
|
33
|
-
@
|
|
38
|
+
@details = details
|
|
34
39
|
end
|
|
35
40
|
|
|
36
41
|
##
|
|
@@ -44,15 +49,12 @@ module ConvenientService
|
|
|
44
49
|
# @param other [Object] Can be any type.
|
|
45
50
|
# @return [Boolean, nil]
|
|
46
51
|
#
|
|
47
|
-
# @internal
|
|
48
|
-
# TODO: Tests.
|
|
49
|
-
#
|
|
50
52
|
def ==(other)
|
|
51
53
|
return unless other.instance_of?(self.class)
|
|
52
54
|
|
|
53
55
|
return false if name != other.name
|
|
54
56
|
return false if enabled != other.enabled
|
|
55
|
-
return false if
|
|
57
|
+
return false if details != other.details
|
|
56
58
|
|
|
57
59
|
true
|
|
58
60
|
end
|
|
@@ -8,10 +8,6 @@
|
|
|
8
8
|
module ConvenientService
|
|
9
9
|
module Config
|
|
10
10
|
module Entities
|
|
11
|
-
##
|
|
12
|
-
# @internal
|
|
13
|
-
# TODO: Specs.
|
|
14
|
-
#
|
|
15
11
|
class OptionCollection
|
|
16
12
|
##
|
|
17
13
|
# @!attribute [r] options
|
|
@@ -65,6 +61,14 @@ module ConvenientService
|
|
|
65
61
|
options[name].enabled?
|
|
66
62
|
end
|
|
67
63
|
|
|
64
|
+
##
|
|
65
|
+
# @param names [Array<Symbol>]
|
|
66
|
+
# @return [Boolean]
|
|
67
|
+
#
|
|
68
|
+
def any_enabled?(*names)
|
|
69
|
+
names.any? { |name| enabled?(name) }
|
|
70
|
+
end
|
|
71
|
+
|
|
68
72
|
##
|
|
69
73
|
# @param name [Symbol]
|
|
70
74
|
# @return [Boolean]
|
|
@@ -6,6 +6,17 @@
|
|
|
6
6
|
##
|
|
7
7
|
|
|
8
8
|
module ConvenientService
|
|
9
|
+
##
|
|
10
|
+
# Convenient Service concern (Like Rails concern, but with some customizations).
|
|
11
|
+
#
|
|
12
|
+
# @api public
|
|
13
|
+
# @since 1.0.0
|
|
14
|
+
# @return [Module]
|
|
15
|
+
#
|
|
16
|
+
# @note Expected to be used from Convenient Service plugins.
|
|
17
|
+
#
|
|
18
|
+
Concern = ::ConvenientService::Core::Entities::Config::Entities::Concerns::Usual
|
|
19
|
+
|
|
9
20
|
##
|
|
10
21
|
# Base class for concern middlewares.
|
|
11
22
|
#
|
|
@@ -94,4 +105,43 @@ module ConvenientService
|
|
|
94
105
|
# # => <Service::Result status: :success>
|
|
95
106
|
#
|
|
96
107
|
MethodChainMiddleware = ::ConvenientService::Core::Entities::Config::Entities::MethodMiddlewares::Entities::Middlewares::Chain
|
|
108
|
+
|
|
109
|
+
##
|
|
110
|
+
# Alias to base class for method middlewares using `chain.next`.
|
|
111
|
+
#
|
|
112
|
+
# @api public
|
|
113
|
+
# @since 1.0.0
|
|
114
|
+
# @return [Class]
|
|
115
|
+
#
|
|
116
|
+
# @example Common usage.
|
|
117
|
+
# class Middleware < ConvenientService::MethodMiddleware
|
|
118
|
+
# def next(*args, **kwargs, &block)
|
|
119
|
+
# p [args, kwargs, block]
|
|
120
|
+
#
|
|
121
|
+
# value = chain.next(*args, **kwargs, &block)
|
|
122
|
+
#
|
|
123
|
+
# p value
|
|
124
|
+
#
|
|
125
|
+
# value
|
|
126
|
+
# end
|
|
127
|
+
# end
|
|
128
|
+
#
|
|
129
|
+
# class Service
|
|
130
|
+
# include ConvenientService::Standard::Config
|
|
131
|
+
#
|
|
132
|
+
# middlewares :result do
|
|
133
|
+
# insert_before 0, Middleware
|
|
134
|
+
# end
|
|
135
|
+
#
|
|
136
|
+
# def result
|
|
137
|
+
# success
|
|
138
|
+
# end
|
|
139
|
+
# end
|
|
140
|
+
#
|
|
141
|
+
# Service.result
|
|
142
|
+
# # {args: [], kwargs: {}, block: nil, entity: <Service>, method: :result}
|
|
143
|
+
# # <Service::Result status: :success>
|
|
144
|
+
# # => <Service::Result status: :success>
|
|
145
|
+
#
|
|
146
|
+
Middleware = MethodChainMiddleware
|
|
97
147
|
end
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
##
|
|
4
|
+
# @author Marian Kostyk <mariankostyk13895@gmail.com>
|
|
5
|
+
# @license LGPLv3 <https://www.gnu.org/licenses/lgpl-3.0.html>
|
|
6
|
+
##
|
|
7
|
+
|
|
8
|
+
module ConvenientService
|
|
9
|
+
module Core
|
|
10
|
+
module Entities
|
|
11
|
+
class Config
|
|
12
|
+
module Commands
|
|
13
|
+
class BuildEntityFromConfigOption < Support::Command
|
|
14
|
+
##
|
|
15
|
+
# @!attribute [r] base_entity
|
|
16
|
+
# @return [#with]
|
|
17
|
+
#
|
|
18
|
+
attr_reader :base_entity
|
|
19
|
+
|
|
20
|
+
##
|
|
21
|
+
# @!attribute [r] config
|
|
22
|
+
# @return [ConvenientService::Config::Entities::Option]
|
|
23
|
+
#
|
|
24
|
+
attr_reader :option
|
|
25
|
+
|
|
26
|
+
##
|
|
27
|
+
# @!attribute [r] detail_keys
|
|
28
|
+
# @return [Array<Symbol>]
|
|
29
|
+
#
|
|
30
|
+
attr_reader :detail_keys
|
|
31
|
+
|
|
32
|
+
##
|
|
33
|
+
# @param base_entity [#with]
|
|
34
|
+
# @param option [ConvenientService::Config::Entities::Option]
|
|
35
|
+
# @param detail_keys [Array<Symbol>]
|
|
36
|
+
# @return [void]
|
|
37
|
+
#
|
|
38
|
+
def initialize(base_entity:, option:, detail_keys:)
|
|
39
|
+
@base_entity = base_entity
|
|
40
|
+
@option = option
|
|
41
|
+
@detail_keys = detail_keys
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
##
|
|
45
|
+
# @return [Object] Can be any type.
|
|
46
|
+
#
|
|
47
|
+
def call
|
|
48
|
+
return base_entity unless option
|
|
49
|
+
return base_entity if option.data.empty?
|
|
50
|
+
return base_entity if detail_keys.empty?
|
|
51
|
+
|
|
52
|
+
data_values = option.data.slice(*detail_keys)
|
|
53
|
+
|
|
54
|
+
return base_entity if data_values.empty?
|
|
55
|
+
|
|
56
|
+
base_entity.with(**data_values)
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
# @license LGPLv3 <https://www.gnu.org/licenses/lgpl-3.0.html>
|
|
6
6
|
##
|
|
7
7
|
|
|
8
|
+
require_relative "commands/build_entity_from_config_option"
|
|
8
9
|
require_relative "commands/create_entity_class"
|
|
9
10
|
require_relative "commands/find_entity_class"
|
|
10
11
|
require_relative "commands/find_or_create_entity_class"
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
##
|
|
4
|
+
# @author Marian Kostyk <mariankostyk13895@gmail.com>
|
|
5
|
+
# @license LGPLv3 <https://www.gnu.org/licenses/lgpl-3.0.html>
|
|
6
|
+
##
|
|
7
|
+
|
|
8
|
+
module ConvenientService
|
|
9
|
+
module Core
|
|
10
|
+
module Entities
|
|
11
|
+
class Config
|
|
12
|
+
module Entities
|
|
13
|
+
class Concerns
|
|
14
|
+
module Usual
|
|
15
|
+
class << self
|
|
16
|
+
##
|
|
17
|
+
# @param mod [Module]
|
|
18
|
+
# @return [void]
|
|
19
|
+
#
|
|
20
|
+
def included(mod)
|
|
21
|
+
mod.extend Dependencies::Extractions::ActiveSupportConcern::Concern
|
|
22
|
+
|
|
23
|
+
mod.module_exec do
|
|
24
|
+
class << self
|
|
25
|
+
##
|
|
26
|
+
# @param option [ConvenientService::Config::Entities::Option]
|
|
27
|
+
# @param detail_keys [Array<Symbol>]
|
|
28
|
+
# @return [ConvenientService::Core::Entities::Config::Entities::MethodMiddlewares::Entities::Middlewares::Base]
|
|
29
|
+
#
|
|
30
|
+
def from(option, *detail_keys)
|
|
31
|
+
::ConvenientService::Core::Entities::Config::Commands::BuildEntityFromConfigOption.call(base_entity: self, option: option, detail_keys: detail_keys)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
##
|
|
35
|
+
# @return [ConvenientService::Core::Entities::Config::Entities::MethodMiddlewares::Entities::MiddlewareCreators::With]
|
|
36
|
+
#
|
|
37
|
+
def with(...)
|
|
38
|
+
self
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -25,6 +25,15 @@ module ConvenientService
|
|
|
25
25
|
class Base
|
|
26
26
|
module Concern
|
|
27
27
|
module ClassMethods
|
|
28
|
+
##
|
|
29
|
+
# @param option [ConvenientService::Config::Entities::Option]
|
|
30
|
+
# @param detail_keys [Array<Symbol>]
|
|
31
|
+
# @return [ConvenientService::Core::Entities::Config::Entities::MethodMiddlewares::Entities::Middlewares::Base]
|
|
32
|
+
#
|
|
33
|
+
def from(option, *detail_keys)
|
|
34
|
+
::ConvenientService::Core::Entities::Config::Commands::BuildEntityFromConfigOption.call(base_entity: self, option: option, detail_keys: detail_keys)
|
|
35
|
+
end
|
|
36
|
+
|
|
28
37
|
##
|
|
29
38
|
# @return [ConvenientService::Core::Entities::Config::Entities::MethodMiddlewares::Entities::MiddlewareCreators::With]
|
|
30
39
|
#
|
|
@@ -19,6 +19,7 @@ module ConvenientService
|
|
|
19
19
|
[
|
|
20
20
|
:essential,
|
|
21
21
|
:callbacks,
|
|
22
|
+
:strictness,
|
|
22
23
|
:inspect,
|
|
23
24
|
:recalculation,
|
|
24
25
|
:result_parents_trace,
|
|
@@ -36,6 +37,7 @@ module ConvenientService
|
|
|
36
37
|
[
|
|
37
38
|
:essential,
|
|
38
39
|
:callbacks,
|
|
40
|
+
:strictness,
|
|
39
41
|
:inspect,
|
|
40
42
|
:recalculation,
|
|
41
43
|
:result_parents_trace,
|