convenient_service 0.16.0 → 0.17.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +30 -0
  3. data/README.md +1 -1
  4. data/convenient_service.gemspec +24 -5
  5. data/lib/convenient_service/common/plugins/can_have_user_provided_entity/commands/find_or_create_entity.rb +7 -2
  6. data/lib/convenient_service/common/plugins/can_have_user_provided_entity/exceptions.rb +4 -4
  7. data/lib/convenient_service/common/plugins/has_around_callbacks/exceptions.rb +2 -2
  8. data/lib/convenient_service/common/plugins/has_around_callbacks/middleware.rb +2 -2
  9. data/lib/convenient_service/common/plugins/has_instance_proxy/commands/create_instance_proxy_class.rb +83 -0
  10. data/lib/convenient_service/common/plugins/has_instance_proxy/commands.rb +3 -0
  11. data/lib/convenient_service/common/plugins/has_instance_proxy/concern.rb +22 -0
  12. data/lib/convenient_service/common/plugins/has_instance_proxy/entities/instance_proxy.rb +76 -0
  13. data/lib/convenient_service/common/plugins/has_instance_proxy/entities.rb +3 -0
  14. data/lib/convenient_service/common/plugins/has_instance_proxy/middleware.rb +20 -0
  15. data/lib/convenient_service/common/plugins/has_instance_proxy.rb +6 -0
  16. data/lib/convenient_service/common/plugins.rb +1 -0
  17. data/lib/convenient_service/core/concern/class_methods.rb +7 -2
  18. data/lib/convenient_service/core/concern/instance_methods.rb +7 -2
  19. data/lib/convenient_service/core/entities/config/commands/track_method_missing_commit_trigger.rb +1 -1
  20. data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/caller/commands/define_method_middlewares_caller.rb +2 -2
  21. data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/middlewares/base/commands/create_observable_middleware.rb +3 -0
  22. data/lib/convenient_service/core/entities/config/exceptions.rb +4 -4
  23. data/lib/convenient_service/core/entities/config.rb +1 -1
  24. data/lib/convenient_service/dependencies/extractions/active_support_backtrace_cleaner/backtrace_cleaner.rb +28 -8
  25. data/lib/convenient_service/dependencies/extractions/active_support_backtrace_cleaner.rb +3 -3
  26. data/lib/convenient_service/dependencies/extractions/b.rb +2 -0
  27. data/lib/convenient_service/dependencies/extractions/ce.rb +16 -0
  28. data/lib/convenient_service/dependencies/extractions.rb +1 -0
  29. data/lib/convenient_service/dependencies.rb +6 -1
  30. data/lib/convenient_service/examples/standard/request_params.rb +0 -1
  31. data/lib/convenient_service/examples/standard/v1/request_params.rb +0 -1
  32. data/lib/convenient_service/exception.rb +98 -10
  33. data/lib/convenient_service/feature/configs/standard.rb +8 -0
  34. data/lib/convenient_service/feature/plugins/can_have_entries/commands/define_entries.rb +49 -0
  35. data/lib/convenient_service/feature/plugins/can_have_entries/commands/define_entry.rb +18 -4
  36. data/lib/convenient_service/feature/plugins/can_have_entries/commands.rb +1 -0
  37. data/lib/convenient_service/feature/plugins/can_have_entries/concern.rb +13 -4
  38. data/lib/convenient_service/feature/plugins/can_have_entries/exceptions.rb +14 -4
  39. data/lib/convenient_service/logger.rb +4 -1
  40. data/lib/convenient_service/rspec/helpers/classes/stub_service/entities/result_spec.rb +0 -8
  41. data/lib/convenient_service/rspec/helpers/classes/wrap_method/entities/wrapped_method.rb +5 -5
  42. data/lib/convenient_service/rspec/helpers/classes/wrap_method/exceptions.rb +2 -2
  43. data/lib/convenient_service/rspec/matchers/classes/results/base/entities/validator/commands/validate_result_step.rb +1 -1
  44. data/lib/convenient_service/rspec/matchers/classes/results/base/exceptions.rb +2 -2
  45. data/lib/convenient_service/rspec/primitive_helpers/classes/ignoring_exception/exceptions.rb +2 -2
  46. data/lib/convenient_service/rspec/primitive_helpers/classes/ignoring_exception.rb +1 -1
  47. data/lib/convenient_service/rspec/primitive_matchers/classes/delegate_to/entities/matcher/entities/chainings/sub_matchers/arguments/commands/apply_stub_to_track_delegations.rb +4 -0
  48. data/lib/convenient_service/rspec/primitive_matchers/classes/delegate_to/entities/matcher/entities/chainings_collection/exceptions.rb +7 -7
  49. data/lib/convenient_service/rspec/primitive_matchers/classes/delegate_to/entities/matcher/entities/chainings_collection.rb +3 -3
  50. data/lib/convenient_service/service/plugins/can_have_fallbacks/concern.rb +2 -2
  51. data/lib/convenient_service/service/plugins/can_have_fallbacks/exceptions.rb +4 -4
  52. data/lib/convenient_service/service/plugins/can_have_fallbacks/middleware.rb +1 -1
  53. data/lib/convenient_service/service/plugins/can_have_steps/concern.rb +3 -3
  54. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/commands/define_method_in_container.rb +2 -2
  55. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/concern/instance_methods.rb +1 -1
  56. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/callers/alias.rb +2 -2
  57. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/callers/proc.rb +1 -1
  58. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/callers/raw.rb +1 -1
  59. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/callers/reassignment.rb +2 -2
  60. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/callers/usual.rb +2 -2
  61. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/directions/input.rb +2 -2
  62. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/directions/output.rb +1 -1
  63. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/exceptions.rb +26 -26
  64. data/lib/convenient_service/service/plugins/can_have_steps/entities/step/concern/instance_methods.rb +1 -1
  65. data/lib/convenient_service/service/plugins/can_have_steps/entities/step/exceptions.rb +2 -2
  66. data/lib/convenient_service/service/plugins/can_have_steps/entities/step/plugins/can_be_result_step/can_be_executed/exceptions.rb +2 -2
  67. data/lib/convenient_service/service/plugins/can_have_steps/entities/step/plugins/can_be_result_step/can_be_executed/middleware.rb +1 -1
  68. data/lib/convenient_service/service/plugins/can_have_steps/entities/step/plugins/raises_on_not_result_return_value/exceptions.rb +2 -2
  69. data/lib/convenient_service/service/plugins/can_have_steps/entities/step/plugins/raises_on_not_result_return_value/middleware.rb +1 -1
  70. data/lib/convenient_service/service/plugins/has_inspect/concern.rb +0 -1
  71. 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
  72. data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/entities/data/concern/instance_methods.rb +1 -1
  73. data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/entities/status/concern/instance_methods.rb +14 -0
  74. data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/exceptions.rb +2 -2
  75. data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/raises_on_not_checked_result_status/exceptions.rb +2 -2
  76. data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/raises_on_not_checked_result_status/middleware.rb +1 -1
  77. data/lib/convenient_service/service/plugins/has_j_send_result/exceptions.rb +2 -2
  78. data/lib/convenient_service/service/plugins/has_j_send_result.rb +39 -0
  79. data/lib/convenient_service/service/plugins/has_j_send_result_short_syntax/error/exceptions.rb +6 -6
  80. data/lib/convenient_service/service/plugins/has_j_send_result_short_syntax/error/middleware.rb +3 -3
  81. data/lib/convenient_service/service/plugins/has_j_send_result_short_syntax/failure/exceptions.rb +6 -6
  82. data/lib/convenient_service/service/plugins/has_j_send_result_short_syntax/failure/middleware.rb +3 -3
  83. data/lib/convenient_service/service/plugins/has_j_send_result_short_syntax/success/commands/refute_kwargs_contain_j_send_and_extra_keys.rb +1 -1
  84. data/lib/convenient_service/service/plugins/has_j_send_result_short_syntax/success/exceptions.rb +2 -2
  85. data/lib/convenient_service/service/plugins/has_j_send_result_status_check_short_syntax/concern.rb +0 -8
  86. data/lib/convenient_service/service/plugins/has_result/concern.rb +1 -1
  87. data/lib/convenient_service/service/plugins/has_result/exceptions.rb +2 -2
  88. data/lib/convenient_service/service/plugins/raises_on_double_result/exceptions.rb +2 -2
  89. data/lib/convenient_service/service/plugins/raises_on_double_result/middleware.rb +1 -1
  90. data/lib/convenient_service/service/plugins/raises_on_not_result_return_value/exceptions.rb +2 -2
  91. data/lib/convenient_service/service/plugins/raises_on_not_result_return_value/middleware.rb +1 -1
  92. data/lib/convenient_service/support/abstract_method/exceptions.rb +2 -2
  93. data/lib/convenient_service/support/abstract_method.rb +1 -1
  94. data/lib/convenient_service/support/backtrace_cleaner.rb +123 -0
  95. data/lib/convenient_service/support/cache/exceptions.rb +2 -2
  96. data/lib/convenient_service/support/cache.rb +1 -1
  97. data/lib/convenient_service/support/castable/exceptions.rb +4 -4
  98. data/lib/convenient_service/support/castable.rb +1 -1
  99. data/lib/convenient_service/support/command.rb +3 -3
  100. data/lib/convenient_service/support/counter.rb +6 -6
  101. data/lib/convenient_service/support/dependency_container/commands/assert_valid_container.rb +1 -1
  102. data/lib/convenient_service/support/dependency_container/commands/assert_valid_method.rb +1 -1
  103. data/lib/convenient_service/support/dependency_container/commands/assert_valid_scope.rb +1 -1
  104. data/lib/convenient_service/support/dependency_container/exceptions.rb +8 -8
  105. data/lib/convenient_service/support/dependency_container/export.rb +1 -1
  106. data/lib/convenient_service/support/finite_loop.rb +6 -6
  107. data/lib/convenient_service/support.rb +1 -0
  108. data/lib/convenient_service/utils/array/exceptions.rb +2 -2
  109. data/lib/convenient_service/utils/array/merge.rb +1 -1
  110. data/lib/convenient_service/utils/hash/assert_valid_keys.rb +1 -1
  111. data/lib/convenient_service/version.rb +1 -1
  112. data/lib/convenient_service.rb +98 -0
  113. metadata +22 -41
  114. data/lib/convenient_service/examples/standard/v1/gemfile/services/print_shell_command.rb +0 -47
@@ -42,7 +42,7 @@ module ConvenientService
42
42
  rescue exception
43
43
  Support::UNDEFINED
44
44
  else
45
- raise Exceptions::IgnoredExceptionIsNotRaised.new(exception: exception)
45
+ ::ConvenientService.raise Exceptions::IgnoredExceptionIsNotRaised.new(exception: exception)
46
46
  end
47
47
  end
48
48
  end
@@ -45,6 +45,10 @@ module ConvenientService
45
45
  # NOTE: That is why `and_wrap_original` is used.
46
46
  # https://relishapp.com/rspec/rspec-mocks/docs/configuring-responses/wrapping-the-original-implementation
47
47
  #
48
+ # TODO: Check whether `matcher.object.frozen?` in order to show more explanatory exception instead of the following (provide an example of how to avoid it in the exception message):
49
+ # ArgumentError:
50
+ # Cannot proxy frozen objects, rspec-mocks relies on proxies for method stubbing and expectations
51
+ #
48
52
  allow(matcher.object).to receive(matcher.method).and_wrap_original do |original, *actual_args, **actual_kwargs, &actual_block|
49
53
  ##
50
54
  # TODO: Add backtrace for easier reason tracing.
@@ -11,38 +11,38 @@ module ConvenientService
11
11
  class ChainingsCollection
12
12
  module Exceptions
13
13
  class CallOriginalChainingIsAlreadySet < ::ConvenientService::Exception
14
- def initialize
14
+ def initialize_without_arguments
15
15
  message = <<~TEXT
16
16
  Call original chaining is already set.
17
17
 
18
18
  Did you use `with_calling_original` or `without_calling_original` multiple times? Or a combination of them?
19
19
  TEXT
20
20
 
21
- super(message)
21
+ initialize(message)
22
22
  end
23
23
  end
24
24
 
25
25
  class ArgumentsChainingIsAlreadySet < ::ConvenientService::Exception
26
- def initialize
26
+ def initialize_without_arguments
27
27
  message = <<~TEXT
28
28
  Arguments chaining is already set.
29
29
 
30
30
  Did you use `with_arguments` or `without_arguments` multiple times? Or a combination of them?
31
31
  TEXT
32
32
 
33
- super(message)
33
+ initialize(message)
34
34
  end
35
35
  end
36
36
 
37
37
  class ReturnItsValueChainingIsAlreadySet < ::ConvenientService::Exception
38
- def initialize
38
+ def initialize_without_arguments
39
39
  message = <<~TEXT
40
40
  Returns its value chaining is already set.
41
41
 
42
- Did you use `and_returns_its_value` multiple times?
42
+ Did you use `and_return_its_value` multiple times?
43
43
  TEXT
44
44
 
45
- super(message)
45
+ initialize(message)
46
46
  end
47
47
  end
48
48
  end
@@ -136,7 +136,7 @@ module ConvenientService
136
136
  # @raise [ConvenientService::RSpec::PrimitiveMatchers::Classes::DelegateTo::Exceptions::ReturnItsValueChainingIsAlreadySet]
137
137
  #
138
138
  def call_original=(chaining)
139
- raise Exceptions::CallOriginalChainingIsAlreadySet.new if @call_original
139
+ ::ConvenientService.raise Exceptions::CallOriginalChainingIsAlreadySet.new if @call_original
140
140
 
141
141
  @call_original = chaining
142
142
  end
@@ -146,7 +146,7 @@ module ConvenientService
146
146
  # @raise [ConvenientService::RSpec::PrimitiveMatchers::Classes::DelegateTo::Exceptions::ArgumentsChainingIsAlreadySet]
147
147
  #
148
148
  def arguments=(chaining)
149
- raise Exceptions::ArgumentsChainingIsAlreadySet.new if @arguments
149
+ ::ConvenientService.raise Exceptions::ArgumentsChainingIsAlreadySet.new if @arguments
150
150
 
151
151
  @arguments = chaining
152
152
  end
@@ -156,7 +156,7 @@ module ConvenientService
156
156
  # @raise [ConvenientService::RSpec::PrimitiveMatchers::Classes::DelegateTo::Exceptions::ReturnItsValueChainingIsAlreadySet]
157
157
  #
158
158
  def return_its_value=(chaining)
159
- raise Exceptions::ReturnItsValueChainingIsAlreadySet.new if @return_its_value
159
+ ::ConvenientService.raise Exceptions::ReturnItsValueChainingIsAlreadySet.new if @return_its_value
160
160
 
161
161
  @return_its_value = chaining
162
162
  end
@@ -14,7 +14,7 @@ module ConvenientService
14
14
  # @raise [ConvenientService::Service::Plugins::CanHaveFallbacks::Exceptions::FallbackResultIsNotOverridden]
15
15
  #
16
16
  def fallback_failure_result
17
- raise Exceptions::FallbackResultIsNotOverridden.new(service: self, status: :failure)
17
+ ::ConvenientService.raise Exceptions::FallbackResultIsNotOverridden.new(service: self, status: :failure)
18
18
  end
19
19
 
20
20
  ##
@@ -23,7 +23,7 @@ module ConvenientService
23
23
  # @raise [ConvenientService::Service::Plugins::CanHaveFallbacks::Exceptions::FallbackResultIsNotOverridden]
24
24
  #
25
25
  def fallback_error_result
26
- raise Exceptions::FallbackResultIsNotOverridden.new(service: self, status: :error)
26
+ ::ConvenientService.raise Exceptions::FallbackResultIsNotOverridden.new(service: self, status: :error)
27
27
  end
28
28
  end
29
29
 
@@ -6,19 +6,19 @@ module ConvenientService
6
6
  module CanHaveFallbacks
7
7
  module Exceptions
8
8
  class FallbackResultIsNotOverridden < ::ConvenientService::Exception
9
- def initialize(service:, status:)
9
+ def initialize_with_kwargs(service:, status:)
10
10
  message = <<~TEXT
11
11
  Fallback #{status} result method (#fallback_#{status}_result) of `#{service.class}` is NOT overridden.
12
12
 
13
13
  NOTE: Make sure overridden `fallback_#{status}_result` returns `success` with reasonable "null" data.
14
14
  TEXT
15
15
 
16
- super(message)
16
+ initialize(message)
17
17
  end
18
18
  end
19
19
 
20
20
  class ServiceFallbackReturnValueNotSuccess < ::ConvenientService::Exception
21
- def initialize(service:, result:, status:)
21
+ def initialize_with_kwargs(service:, result:, status:)
22
22
  message = <<~TEXT
23
23
  Return value of service `#{service.class}` `#{status}` fallback is NOT a `success`.
24
24
  It is `#{result.status}`.
@@ -26,7 +26,7 @@ module ConvenientService
26
26
  Did you accidentally call `failure` or `error` instead of `success` from the `fallback_#{status}_result` method?
27
27
  TEXT
28
28
 
29
- super(message)
29
+ initialize(message)
30
30
  end
31
31
  end
32
32
  end
@@ -15,7 +15,7 @@ module ConvenientService
15
15
  def next(...)
16
16
  fallback_result = chain.next(...)
17
17
 
18
- raise Exceptions::ServiceFallbackReturnValueNotSuccess.new(service: entity, result: fallback_result, status: status) unless fallback_result.success?
18
+ ::ConvenientService.raise Exceptions::ServiceFallbackReturnValueNotSuccess.new(service: entity, result: fallback_result, status: status) unless fallback_result.success?
19
19
 
20
20
  fallback_result.copy(overrides: {kwargs: {method => true}})
21
21
  .tap { |result| result.success? }
@@ -12,10 +12,10 @@ module ConvenientService
12
12
  # @api public
13
13
  #
14
14
  # @note May be useful for debugging purposes.
15
- # @see https://marian13.github.io/convenient_service_docs/guides/how_to_debug_services_via_callbacks
15
+ # @see https://userdocs.convenientservice.org/guides/how_to_debug_services_via_callbacks
16
16
  #
17
17
  # @note `steps` are frozen.
18
- # @see https://marian13.github.io/convenient_service_docs/faq#is-it-possible-to-modify-the-step-collection-from-a-callback
18
+ # @see https://userdocs.convenientservice.org/faq#is-it-possible-to-modify-the-step-collection-from-a-callback
19
19
  #
20
20
  # @return [Array<ConvenientService::Service::Plugins::CanHaveSteps::Entities::Step>]
21
21
  #
@@ -62,7 +62,7 @@ module ConvenientService
62
62
 
63
63
  ##
64
64
  # Allows to pass a value to `in` method without its intermediate processing.
65
- # @see https://marian13.github.io/convenient_service_docs/basics/step_to_result_translation_table
65
+ # @see https://userdocs.convenientservice.org/basics/step_to_result_translation_table
66
66
  #
67
67
  # @example `:chat_v2` is passed to `AssertFeatureEnabled` as it is.
68
68
  # step AssertFeatureEnabled, in: {name: raw(:chat_v2)}
@@ -28,9 +28,9 @@ module ConvenientService
28
28
  def #{name}
29
29
  step, key, method_name = steps[#{index}], :#{key}, :#{name}
30
30
 
31
- raise #{not_completed_step_error}.new(step: step, method_name: method_name) unless step.completed?
31
+ ::ConvenientService.raise #{not_completed_step_error}.new(step: step, method_name: method_name) unless step.completed?
32
32
 
33
- raise #{not_existing_step_result_data_attribute_error}.new(step: step, key: key) unless step.result.unsafe_data.has_attribute?(key)
33
+ ::ConvenientService.raise #{not_existing_step_result_data_attribute_error}.new(step: step, key: key) unless step.result.unsafe_data.has_attribute?(key)
34
34
 
35
35
  step.result.unsafe_data[key]
36
36
  end
@@ -61,7 +61,7 @@ module ConvenientService
61
61
  # @raise [ConvenientService::Service::Plugins::CanHaveSteps::Entities::Method::Exceptions::MethodHasNoOrganizer]
62
62
  #
63
63
  def organizer(raise_when_missing: true)
64
- raise Exceptions::MethodHasNoOrganizer.new(method: self) if @organizer.nil? && raise_when_missing
64
+ ::ConvenientService.raise Exceptions::MethodHasNoOrganizer.new(method: self) if @organizer.nil? && raise_when_missing
65
65
 
66
66
  @organizer
67
67
  end
@@ -16,13 +16,13 @@ module ConvenientService
16
16
  def validate_as_input_for_container!(container, method:)
17
17
  return true if container.has_defined_method?(method)
18
18
 
19
- raise Exceptions::AliasInputMethodIsNotDefinedInContainer.new(method: method, container: container)
19
+ ::ConvenientService.raise Exceptions::AliasInputMethodIsNotDefinedInContainer.new(method: method, container: container)
20
20
  end
21
21
 
22
22
  def validate_as_output_for_container!(container, method:)
23
23
  return true unless container.has_defined_method?(method)
24
24
 
25
- raise Exceptions::AliasOutputMethodIsDefinedInContainer.new(method: method, container: container)
25
+ ::ConvenientService.raise Exceptions::AliasOutputMethodIsDefinedInContainer.new(method: method, container: container)
26
26
  end
27
27
 
28
28
  def define_output_in_container!(container, index:, method:)
@@ -21,7 +21,7 @@ module ConvenientService
21
21
  ##
22
22
  # TODO: Better error message.
23
23
  #
24
- raise Exceptions::OutputMethodProc.new(method: method, container: container)
24
+ ::ConvenientService.raise Exceptions::OutputMethodProc.new(method: method, container: container)
25
25
  end
26
26
 
27
27
  def define_output_in_container!(container, index:, method:)
@@ -21,7 +21,7 @@ module ConvenientService
21
21
  ##
22
22
  # TODO: Better error message.
23
23
  #
24
- raise Exceptions::OutputMethodRawValue.new(container: container, method: method)
24
+ ::ConvenientService.raise Exceptions::OutputMethodRawValue.new(container: container, method: method)
25
25
  end
26
26
 
27
27
  def define_output_in_container!(container, index:, method:)
@@ -22,11 +22,11 @@ module ConvenientService
22
22
  # TODO: Separate `in` and `out` methods?
23
23
  #
24
24
  def calculate_value(method)
25
- raise Exceptions::CallerCanNotCalculateReassignment.new(method: method)
25
+ ::ConvenientService.raise Exceptions::CallerCanNotCalculateReassignment.new(method: method)
26
26
  end
27
27
 
28
28
  def validate_as_input_for_container!(container, method:)
29
- raise Exceptions::InputMethodReassignment.new(method: method, container: container)
29
+ ::ConvenientService.raise Exceptions::InputMethodReassignment.new(method: method, container: container)
30
30
  end
31
31
 
32
32
  def validate_as_output_for_container!(container, method:)
@@ -16,13 +16,13 @@ module ConvenientService
16
16
  def validate_as_input_for_container!(container, method:)
17
17
  return true if container.has_defined_method?(method)
18
18
 
19
- raise Exceptions::InputMethodIsNotDefinedInContainer.new(method: method, container: container)
19
+ ::ConvenientService.raise Exceptions::InputMethodIsNotDefinedInContainer.new(method: method, container: container)
20
20
  end
21
21
 
22
22
  def validate_as_output_for_container!(container, method:)
23
23
  return true unless container.has_defined_method?(method)
24
24
 
25
- raise Exceptions::OutputMethodIsDefinedInContainer.new(method: method, container: container)
25
+ ::ConvenientService.raise Exceptions::OutputMethodIsDefinedInContainer.new(method: method, container: container)
26
26
  end
27
27
 
28
28
  def define_output_in_container!(container, index:, method:)
@@ -14,11 +14,11 @@ module ConvenientService
14
14
  end
15
15
 
16
16
  def validate_as_output_for_container!(container, method:)
17
- raise Exceptions::MethodIsNotOutputMethod.new(method: method, container: container)
17
+ ::ConvenientService.raise Exceptions::MethodIsNotOutputMethod.new(method: method, container: container)
18
18
  end
19
19
 
20
20
  def define_output_in_container!(container, index:, method:)
21
- raise Exceptions::MethodIsNotOutputMethod.new(method: method, container: container)
21
+ ::ConvenientService.raise Exceptions::MethodIsNotOutputMethod.new(method: method, container: container)
22
22
  end
23
23
  end
24
24
  end
@@ -10,7 +10,7 @@ module ConvenientService
10
10
  module Directions
11
11
  class Output < Base
12
12
  def validate_as_input_for_container!(container, method:)
13
- raise Exceptions::MethodIsNotInputMethod.new(method: method, container: container)
13
+ ::ConvenientService.raise Exceptions::MethodIsNotInputMethod.new(method: method, container: container)
14
14
  end
15
15
 
16
16
  def validate_as_output_for_container!(container, method:)
@@ -15,14 +15,14 @@ module ConvenientService
15
15
  # @internal
16
16
  # TODO: Introduce `Method#step` for more verbose message?
17
17
  #
18
- def initialize(method:)
18
+ def initialize_with_kwargs(method:)
19
19
  message = <<~TEXT
20
20
  Organizer for method `:#{method.name}` is NOT assigned yet.
21
21
 
22
22
  Did you forget to set it?
23
23
  TEXT
24
24
 
25
- super(message)
25
+ initialize(message)
26
26
  end
27
27
  end
28
28
 
@@ -32,14 +32,14 @@ module ConvenientService
32
32
  # @param container [ConvenientService::Service::Plugins::CanHaveSteps::Entities::Service]
33
33
  # @return [void]
34
34
  #
35
- def initialize(method:, container:)
35
+ def initialize_with_kwargs(method:, container:)
36
36
  message = <<~TEXT
37
37
  `in` method `#{method.name}` is NOT defined in `#{container.klass}`.
38
38
 
39
39
  Did you forget to define it?
40
40
  TEXT
41
41
 
42
- super(message)
42
+ initialize(message)
43
43
  end
44
44
  end
45
45
 
@@ -49,14 +49,14 @@ module ConvenientService
49
49
  # @param container [ConvenientService::Service::Plugins::CanHaveSteps::Entities::Service]
50
50
  # @return [void]
51
51
  #
52
- def initialize(method:, container:)
52
+ def initialize_with_kwargs(method:, container:)
53
53
  message = <<~TEXT
54
54
  `out` method `#{method.name}` is already defined in `#{container.klass}`.
55
55
 
56
56
  Did you forget to remove it?
57
57
  TEXT
58
58
 
59
- super(message)
59
+ initialize(message)
60
60
  end
61
61
  end
62
62
 
@@ -66,14 +66,14 @@ module ConvenientService
66
66
  # @param container [ConvenientService::Service::Plugins::CanHaveSteps::Entities::Service]
67
67
  # @return [void]
68
68
  #
69
- def initialize(method:, container:)
69
+ def initialize_with_kwargs(method:, container:)
70
70
  message = <<~TEXT
71
71
  Alias `in` method `#{method.name}` is NOT defined in `#{container.klass}`.
72
72
 
73
73
  Did you forget to define it?
74
74
  TEXT
75
75
 
76
- super(message)
76
+ initialize(message)
77
77
  end
78
78
  end
79
79
 
@@ -83,14 +83,14 @@ module ConvenientService
83
83
  # @param container [ConvenientService::Service::Plugins::CanHaveSteps::Entities::Service]
84
84
  # @return [void]
85
85
  #
86
- def initialize(method:, container:)
86
+ def initialize_with_kwargs(method:, container:)
87
87
  message = <<~TEXT
88
88
  Alias `out` method `#{method.name}` is already defined in `#{container.klass}`.
89
89
 
90
90
  Did you forget to remove it?
91
91
  TEXT
92
92
 
93
- super(message)
93
+ initialize(message)
94
94
  end
95
95
  end
96
96
 
@@ -100,12 +100,12 @@ module ConvenientService
100
100
  # @param container [ConvenientService::Service::Plugins::CanHaveSteps::Entities::Service]
101
101
  # @return [void]
102
102
  #
103
- def initialize(method:, container:)
103
+ def initialize_with_kwargs(method:, container:)
104
104
  message = <<~TEXT
105
105
  Procs are not allowed for `out` methods.
106
106
  TEXT
107
107
 
108
- super(message)
108
+ initialize(message)
109
109
  end
110
110
  end
111
111
 
@@ -115,12 +115,12 @@ module ConvenientService
115
115
  # @param container [ConvenientService::Service::Plugins::CanHaveSteps::Entities::Service]
116
116
  # @return [void]
117
117
  #
118
- def initialize(method:, container:)
118
+ def initialize_with_kwargs(method:, container:)
119
119
  message = <<~TEXT
120
120
  Raw values are not allowed for `out` methods.
121
121
  TEXT
122
122
 
123
- super(message)
123
+ initialize(message)
124
124
  end
125
125
  end
126
126
 
@@ -129,14 +129,14 @@ module ConvenientService
129
129
  # @param method [ConvenientService::Service::Plugins::CanHaveSteps::Entities::Method]
130
130
  # @return [void]
131
131
  #
132
- def initialize(method:)
132
+ def initialize_with_kwargs(method:)
133
133
  message = <<~TEXT
134
134
  Method caller failed to calculate reassignment for `#{method.name}`.
135
135
 
136
136
  Method callers can calculate only `in` methods, while reassignments are always `out` methods.
137
137
  TEXT
138
138
 
139
- super(message)
139
+ initialize(message)
140
140
  end
141
141
  end
142
142
 
@@ -146,12 +146,12 @@ module ConvenientService
146
146
  # @param container [ConvenientService::Service::Plugins::CanHaveSteps::Entities::Service]
147
147
  # @return [void]
148
148
  #
149
- def initialize(method:, container:)
149
+ def initialize_with_kwargs(method:, container:)
150
150
  message = <<~TEXT
151
151
  Reassignments are not allowed for `in` methods.
152
152
  TEXT
153
153
 
154
- super(message)
154
+ initialize(message)
155
155
  end
156
156
  end
157
157
 
@@ -161,12 +161,12 @@ module ConvenientService
161
161
  # @param container [ConvenientService::Service::Plugins::CanHaveSteps::Entities::Service]
162
162
  # @return [void]
163
163
  #
164
- def initialize(method:, container:)
164
+ def initialize_with_kwargs(method:, container:)
165
165
  message = <<~TEXT
166
166
  Method `#{method.name}` is NOT an `in` method.
167
167
  TEXT
168
168
 
169
- super(message)
169
+ initialize(message)
170
170
  end
171
171
  end
172
172
 
@@ -176,12 +176,12 @@ module ConvenientService
176
176
  # @param container [ConvenientService::Service::Plugins::CanHaveSteps::Entities::Service]
177
177
  # @return [void]
178
178
  #
179
- def initialize(method:, container:)
179
+ def initialize_with_kwargs(method:, container:)
180
180
  message = <<~TEXT
181
181
  Method `#{method.name}` is NOT an `out` method.
182
182
  TEXT
183
183
 
184
- super(message)
184
+ initialize(message)
185
185
  end
186
186
  end
187
187
 
@@ -191,14 +191,14 @@ module ConvenientService
191
191
  # @param step [ConvenientService::Service::Plugins::CanHaveSteps::Entities::Step]
192
192
  # @return [void]
193
193
  #
194
- def initialize(method_name:, step:)
194
+ def initialize_with_kwargs(method_name:, step:)
195
195
  message = <<~TEXT
196
196
  `out` method `#{method_name}` is called before its corresponding step `#{step.printable_service}` is completed.
197
197
 
198
198
  Maybe it makes sense to change the steps order?
199
199
  TEXT
200
200
 
201
- super(message)
201
+ initialize(message)
202
202
  end
203
203
  end
204
204
 
@@ -208,7 +208,7 @@ module ConvenientService
208
208
  # @param step [ConvenientService::Service::Plugins::CanHaveSteps::Entities::Step]
209
209
  # @return [void]
210
210
  #
211
- def initialize(key:, step:)
211
+ def initialize_with_kwargs(key:, step:)
212
212
  message = <<~TEXT
213
213
  Step `#{step.printable_service}` result does NOT return `#{key}` data attribute.
214
214
 
@@ -217,7 +217,7 @@ module ConvenientService
217
217
  Or `success` of `#{step.printable_service}` accepts a wrong key?
218
218
  TEXT
219
219
 
220
- super(message)
220
+ initialize(message)
221
221
  end
222
222
  end
223
223
  end
@@ -178,7 +178,7 @@ module ConvenientService
178
178
  def organizer(raise_when_missing: true)
179
179
  @organizer ||= params.organizer
180
180
 
181
- raise Exceptions::StepHasNoOrganizer.new(step: self) if @organizer.nil? && raise_when_missing
181
+ ::ConvenientService.raise Exceptions::StepHasNoOrganizer.new(step: self) if @organizer.nil? && raise_when_missing
182
182
 
183
183
  @organizer
184
184
  end
@@ -8,14 +8,14 @@ module ConvenientService
8
8
  class Step
9
9
  module Exceptions
10
10
  class StepHasNoOrganizer < ::ConvenientService::Exception
11
- def initialize(step:)
11
+ def initialize_with_kwargs(step:)
12
12
  message = <<~TEXT
13
13
  Step `#{step.printable_service}` has not assigned organizer.
14
14
 
15
15
  Did you forget to set it?
16
16
  TEXT
17
17
 
18
- super(message)
18
+ initialize(message)
19
19
  end
20
20
  end
21
21
  end
@@ -16,14 +16,14 @@ module ConvenientService
16
16
  # @param method_name [Symbol]
17
17
  # @return [void]
18
18
  #
19
- def initialize(service_class:, method_name:)
19
+ def initialize_with_kwargs(service_class:, method_name:)
20
20
  message = <<~TEXT
21
21
  Service `#{service_class}` tries to use `:#{method_name}` method in a step, but it is NOT defined.
22
22
 
23
23
  Did you forget to define it?
24
24
  TEXT
25
25
 
26
- super(message)
26
+ initialize(message)
27
27
  end
28
28
  end
29
29
  end
@@ -24,7 +24,7 @@ module ConvenientService
24
24
 
25
25
  return own_method.call if own_method
26
26
 
27
- raise Exceptions::MethodForStepIsNotDefined.new(service_class: organizer.class, method_name: method_name)
27
+ ::ConvenientService.raise Exceptions::MethodForStepIsNotDefined.new(service_class: organizer.class, method_name: method_name)
28
28
  end
29
29
 
30
30
  private
@@ -10,7 +10,7 @@ module ConvenientService
10
10
  module RaisesOnNotResultReturnValue
11
11
  module Exceptions
12
12
  class ReturnValueNotKindOfResult < ::ConvenientService::Exception
13
- def initialize(step:, result:)
13
+ def initialize_with_kwargs(step:, result:)
14
14
  message = <<~TEXT
15
15
  Return value of step `#{step.printable_service}` is NOT a `Result`.
16
16
  It is `#{result.class}`.
@@ -18,7 +18,7 @@ module ConvenientService
18
18
  Did you forget to call `success`, `failure`, or `error`?
19
19
  TEXT
20
20
 
21
- super(message)
21
+ initialize(message)
22
22
  end
23
23
  end
24
24
  end
@@ -20,7 +20,7 @@ module ConvenientService
20
20
 
21
21
  return original_result if commands.is_result?(original_result)
22
22
 
23
- raise Exceptions::ReturnValueNotKindOfResult.new(step: entity, result: original_result)
23
+ ::ConvenientService.raise Exceptions::ReturnValueNotKindOfResult.new(step: entity, result: original_result)
24
24
  end
25
25
  end
26
26
  end
@@ -10,7 +10,6 @@ module ConvenientService
10
10
  instance_methods do
11
11
  ##
12
12
  # @return [String]
13
- # @since 0.2.0
14
13
  #
15
14
  def inspect
16
15
  "<#{inspect_values[:name]}>"
@@ -165,6 +165,13 @@ module ConvenientService
165
165
  **extra_kwargs
166
166
  )
167
167
  end
168
+
169
+ ##
170
+ # @return [Boolean, nil]
171
+ #
172
+ def to_bool
173
+ status.to_bool
174
+ end
168
175
  end
169
176
  end
170
177
  end
@@ -146,7 +146,7 @@ module ConvenientService
146
146
  # @raise [ConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::HasJSendStatusAndAttributes::Exceptions::NotExistingAttribute]
147
147
  #
148
148
  def [](key)
149
- value.fetch(key.to_sym) { raise Exceptions::NotExistingAttribute.new(attribute: key) }
149
+ value.fetch(key.to_sym) { ::ConvenientService.raise Exceptions::NotExistingAttribute.new(attribute: key) }
150
150
  end
151
151
 
152
152
  ##