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
@@ -34,7 +34,7 @@ module ConvenientService
34
34
  def cast!(other, **options)
35
35
  casted = cast(other, **options)
36
36
 
37
- raise Exceptions::FailedToCast.new(other: other, klass: self) unless casted
37
+ ::ConvenientService.raise Exceptions::FailedToCast.new(other: other, klass: self) unless casted
38
38
 
39
39
  casted
40
40
  end
@@ -8,12 +8,12 @@ module ConvenientService
8
8
  class Command
9
9
  module Exceptions
10
10
  class CallIsNotOverridden < ::ConvenientService::Exception
11
- def initialize(command:)
11
+ def initialize_with_kwargs(command:)
12
12
  message = <<~TEXT
13
13
  Call method (#call) of `#{command.class}` is NOT overridden.
14
14
  TEXT
15
15
 
16
- super(message)
16
+ initialize(message)
17
17
  end
18
18
  end
19
19
  end
@@ -57,7 +57,7 @@ module ConvenientService
57
57
  # @raise [ConvenientService::Support::Command::Exceptions::CallIsNotOverridden]
58
58
  #
59
59
  def call
60
- raise Exceptions::CallIsNotOverridden.new(command: self)
60
+ ::ConvenientService.raise Exceptions::CallIsNotOverridden.new(command: self)
61
61
  end
62
62
  end
63
63
  end
@@ -19,7 +19,7 @@ module ConvenientService
19
19
  # @param max_value [Integer]
20
20
  # @return [void]
21
21
  #
22
- def initialize(n:, current_value:, max_value:)
22
+ def initialize_with_kwargs(n:, current_value:, max_value:)
23
23
  message = <<~TEXT
24
24
  Value after increment by `#{n}` is greater than the max value.
25
25
 
@@ -28,7 +28,7 @@ module ConvenientService
28
28
  Max value is `#{max_value}`.
29
29
  TEXT
30
30
 
31
- super(message)
31
+ initialize(message)
32
32
  end
33
33
  end
34
34
 
@@ -39,7 +39,7 @@ module ConvenientService
39
39
  # @param min_value [Integer]
40
40
  # @return [void]
41
41
  #
42
- def initialize(n:, current_value:, min_value:)
42
+ def initialize_with_kwargs(n:, current_value:, min_value:)
43
43
  message = <<~TEXT
44
44
  Value after decrement by `#{n}` is lower than the min value.
45
45
 
@@ -48,7 +48,7 @@ module ConvenientService
48
48
  Min value is `#{min_value}`.
49
49
  TEXT
50
50
 
51
- super(message)
51
+ initialize(message)
52
52
  end
53
53
  end
54
54
  end
@@ -123,7 +123,7 @@ module ConvenientService
123
123
  # - https://api.rubyonrails.org/classes/ActiveRecord/Persistence.html#method-i-save-21
124
124
  #
125
125
  def increment!(n = 1)
126
- raise Exceptions::ValueAfterIncrementIsGreaterThanMaxValue.new(n: n, current_value: @current_value, max_value: @max_value) if @current_value + n > @max_value
126
+ ::ConvenientService.raise Exceptions::ValueAfterIncrementIsGreaterThanMaxValue.new(n: n, current_value: @current_value, max_value: @max_value) if @current_value + n > @max_value
127
127
 
128
128
  @current_value += n
129
129
  end
@@ -176,7 +176,7 @@ module ConvenientService
176
176
  # - https://api.rubyonrails.org/classes/ActiveRecord/Persistence.html#method-i-save-21
177
177
  #
178
178
  def decrement!(n = 1)
179
- raise Exceptions::ValueAfterDecrementIsLowerThanMinValue.new(n: n, current_value: @current_value, min_value: @min_value) if @current_value - n < @min_value
179
+ ::ConvenientService.raise Exceptions::ValueAfterDecrementIsLowerThanMinValue.new(n: n, current_value: @current_value, min_value: @min_value) if @current_value - n < @min_value
180
180
 
181
181
  @current_value -= n
182
182
  end
@@ -24,7 +24,7 @@ module ConvenientService
24
24
  # @raise [ConvenientService::Support::DependencyContainer::Exceptions::NotExportableModule]
25
25
  #
26
26
  def call
27
- raise Exceptions::NotExportableModule.new(mod: container) unless Utils::Module.include_module?(container, DependencyContainer::Export)
27
+ ::ConvenientService.raise Exceptions::NotExportableModule.new(mod: container) unless Utils::Module.include_module?(container, DependencyContainer::Export)
28
28
  end
29
29
  end
30
30
  end
@@ -40,7 +40,7 @@ module ConvenientService
40
40
  # @raise [ConvenientService::Support::DependencyContainer::Exceptions::NotExportedMethod]
41
41
  #
42
42
  def call
43
- raise Exceptions::NotExportedMethod.new(method_name: slug, method_scope: scope, mod: container) unless method
43
+ ::ConvenientService.raise Exceptions::NotExportedMethod.new(method_name: slug, method_scope: scope, mod: container) unless method
44
44
  end
45
45
 
46
46
  private
@@ -24,7 +24,7 @@ module ConvenientService
24
24
  # @raise [ConvenientService::Support::DependencyContainer::Exceptions::InvalidScope]
25
25
  #
26
26
  def call
27
- raise Exceptions::InvalidScope.new(scope: scope) unless Constants::SCOPES.include?(scope)
27
+ ::ConvenientService.raise Exceptions::InvalidScope.new(scope: scope) unless Constants::SCOPES.include?(scope)
28
28
  end
29
29
  end
30
30
  end
@@ -9,14 +9,14 @@ module ConvenientService
9
9
  # @param scope [Object]
10
10
  # @return [void]
11
11
  #
12
- def initialize(scope:)
12
+ def initialize_with_kwargs(scope:)
13
13
  message = <<~TEXT
14
14
  Scope `#{scope.inspect}` is NOT valid.
15
15
 
16
16
  Valid options are #{printable_valid_scopes}.
17
17
  TEXT
18
18
 
19
- super(message)
19
+ initialize(message)
20
20
  end
21
21
 
22
22
  private
@@ -34,14 +34,14 @@ module ConvenientService
34
34
  # @param mod [Module]
35
35
  # @return [void]
36
36
  #
37
- def initialize(mod:)
37
+ def initialize_with_kwargs(mod:)
38
38
  message = <<~TEXT
39
39
  Module `#{mod}` can NOT export methods.
40
40
 
41
41
  Did you forget to include `ConvenientService::DependencyContainer::Export` into it?
42
42
  TEXT
43
43
 
44
- super(message)
44
+ initialize(message)
45
45
  end
46
46
  end
47
47
 
@@ -52,7 +52,7 @@ module ConvenientService
52
52
  # @param mod [Module]
53
53
  # @return [void]
54
54
  #
55
- def initialize(method_name:, method_scope:, mod:)
55
+ def initialize_with_kwargs(method_name:, method_scope:, mod:)
56
56
  message = <<~TEXT
57
57
  Module `#{mod}` does NOT export method `#{method_name}` with `#{method_scope}` scope.
58
58
 
@@ -65,7 +65,7 @@ module ConvenientService
65
65
  end
66
66
  TEXT
67
67
 
68
- super(message)
68
+ initialize(message)
69
69
  end
70
70
  end
71
71
 
@@ -74,12 +74,12 @@ module ConvenientService
74
74
  # @param klass [Class]
75
75
  # @return [void]
76
76
  #
77
- def initialize(klass:)
77
+ def initialize_with_kwargs(klass:)
78
78
  message = <<~TEXT
79
79
  `#{klass.inspect}` is NOT a Module.
80
80
  TEXT
81
81
 
82
- super(message)
82
+ initialize(message)
83
83
  end
84
84
  end
85
85
  end
@@ -11,7 +11,7 @@ module ConvenientService
11
11
  # @return [Module]
12
12
  #
13
13
  included do |klass|
14
- raise Exceptions::NotModule.new(klass: klass) unless klass.instance_of?(::Module)
14
+ ::ConvenientService.raise Exceptions::NotModule.new(klass: klass) unless klass.instance_of?(::Module)
15
15
  end
16
16
 
17
17
  class_methods do
@@ -14,14 +14,14 @@ module ConvenientService
14
14
  # @param limit [Integer]
15
15
  # @return [void]
16
16
  #
17
- def initialize(limit:)
17
+ def initialize_with_kwargs(limit:)
18
18
  message = <<~TEXT
19
19
  Max iteration count is exceeded. Current limit is #{limit}.
20
20
 
21
21
  Consider using `max_iteration_count` or `raise_on_exceedance` options if that is not the expected behavior.
22
22
  TEXT
23
23
 
24
- super(message)
24
+ initialize(message)
25
25
  end
26
26
  end
27
27
 
@@ -29,12 +29,12 @@ module ConvenientService
29
29
  ##
30
30
  # @return [void]
31
31
  #
32
- def initialize
32
+ def initialize_without_arguments
33
33
  message = <<~TEXT
34
34
  `finite_loop` always expects a block to be given.
35
35
  TEXT
36
36
 
37
- super(message)
37
+ initialize(message)
38
38
  end
39
39
  end
40
40
  end
@@ -67,13 +67,13 @@ module ConvenientService
67
67
  # end
68
68
  #
69
69
  def finite_loop(default: nil, max_iteration_count: MAX_ITERATION_COUNT, raise_on_exceedance: true, &block)
70
- raise Exceptions::NoBlockGiven.new unless block
70
+ ::ConvenientService.raise Exceptions::NoBlockGiven.new unless block
71
71
 
72
72
  loop.with_index do |_, index|
73
73
  if index >= max_iteration_count
74
74
  break default unless raise_on_exceedance
75
75
 
76
- raise Exceptions::MaxIterationCountExceeded.new(limit: max_iteration_count)
76
+ ::ConvenientService.raise Exceptions::MaxIterationCountExceeded.new(limit: max_iteration_count)
77
77
  end
78
78
 
79
79
  yield(index)
@@ -9,6 +9,7 @@ require_relative "support/concern"
9
9
 
10
10
  require_relative "support/abstract_method"
11
11
  require_relative "support/arguments"
12
+ require_relative "support/backtrace_cleaner"
12
13
  require_relative "support/cache"
13
14
  require_relative "support/castable"
14
15
  require_relative "support/command"
@@ -5,12 +5,12 @@ module ConvenientService
5
5
  module Array
6
6
  module Exceptions
7
7
  class NonIntegerIndex < ::ConvenientService::Exception
8
- def initialize(index:)
8
+ def initialize_with_kwargs(index:)
9
9
  message = <<~TEXT
10
10
  Index `#{index.inspect}` is NOT an integer.
11
11
  TEXT
12
12
 
13
- super(message)
13
+ initialize(message)
14
14
  end
15
15
  end
16
16
  end
@@ -55,7 +55,7 @@ module ConvenientService
55
55
 
56
56
  return if overrides.size == integer_key_overrides.size
57
57
 
58
- raise Exceptions::NonIntegerIndex.new(index: non_integer_index)
58
+ ::ConvenientService.raise Exceptions::NonIntegerIndex.new(index: non_integer_index)
59
59
  end
60
60
 
61
61
  ##
@@ -41,7 +41,7 @@ module ConvenientService
41
41
  hash.each_key do |key|
42
42
  next if valid_keys.include?(key)
43
43
 
44
- raise ::ArgumentError.new("Unknown key: #{key.inspect}. Valid keys are: #{valid_keys.map(&:inspect).join(", ")}")
44
+ ::ConvenientService.raise ::ArgumentError.new("Unknown key: #{key.inspect}. Valid keys are: #{valid_keys.map(&:inspect).join(", ")}")
45
45
  end
46
46
  end
47
47
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ConvenientService
4
- VERSION = "0.16.0"
4
+ VERSION = "0.17.0"
5
5
  end
@@ -51,5 +51,103 @@ module ConvenientService
51
51
  def logger
52
52
  Logger.instance
53
53
  end
54
+
55
+ ##
56
+ # Returns Convenient Service root folder. Inspired by `Rails.root`.
57
+ # For example, it may return something like: `/Users/user/.asdf/installs/ruby/2.7.0/lib/ruby/gems/2.7.0/gems/convenient_service-0.16.0`.
58
+ #
59
+ # @api public
60
+ #
61
+ # @return [Pathname]
62
+ #
63
+ # @see https://ruby-doc.org/core-2.7.1/Kernel.html#method-i-__dir__
64
+ # @see https://api.rubyonrails.org/classes/Rails.html#method-c-root
65
+ #
66
+ def root
67
+ @root ||= ::Pathname.new(::File.expand_path(::File.join(__dir__, "..")))
68
+ end
69
+
70
+ ##
71
+ # Returns Convenient Service Examples folder.
72
+ # For example, it may return something like: `/Users/user/.asdf/installs/ruby/2.7.0/lib/ruby/gems/2.7.0/gems/convenient_service-0.16.0/lib/convenient_service/examples`.
73
+ #
74
+ # @api private
75
+ #
76
+ # @return [Pathname]
77
+ #
78
+ def examples_root
79
+ @examples_root ||= ::Pathname.new(::File.join(root, "lib", "convenient_service", "examples"))
80
+ end
81
+
82
+ ##
83
+ # @api public
84
+ #
85
+ # @return [ConvenientService::Support::BacktraceCleaner]
86
+ #
87
+ def backtrace_cleaner
88
+ @backtrace_cleaner ||= Support::BacktraceCleaner.new
89
+ end
90
+
91
+ ##
92
+ # @api public
93
+ #
94
+ # @param original_exception [StandardError]
95
+ #
96
+ # @raise [StandardError]
97
+ #
98
+ # @internal
99
+ # NOTE: `rescue ::StandardError => exception` is the same as `rescue => exception`.
100
+ #
101
+ # IMPORTANT: CRuby `Kernel.raise` supports `cause` keyword starting from 2.6.
102
+ # JRuby 9.4 says that it is Ruby 3.1 compatible, but it still does NOT support `cause` keyword.
103
+ # - https://ruby-doc.org/core-2.5.0/Kernel.html#method-i-raise
104
+ # - https://ruby-doc.org/core-2.6/Kernel.html#method-i-raise
105
+ # - https://github.com/jruby/jruby/blob/9.4.0.0/core/src/main/java/org/jruby/RubyKernel.java#L881
106
+ # - https://github.com/ruby/spec/blob/master/core/kernel/raise_spec.rb#L5
107
+ #
108
+ if Dependencies.ruby.jruby?
109
+ def raise(original_exception)
110
+ ::Kernel.raise original_exception
111
+ rescue => exception
112
+ ::Kernel.raise exception.class, exception.message, backtrace_cleaner.clean(exception.backtrace)
113
+ end
114
+ else
115
+ def raise(original_exception)
116
+ ::Kernel.raise original_exception
117
+ rescue => exception
118
+ ::Kernel.raise exception.class, exception.message, backtrace_cleaner.clean(exception.backtrace), cause: exception.cause
119
+ end
120
+ end
121
+
122
+ ##
123
+ # @api public
124
+ #
125
+ # @return [Object] Can be any type.
126
+ #
127
+ # @raise [StandardError]
128
+ #
129
+ # @internal
130
+ # NOTE: `rescue ::StandardError => exception` is the same as `rescue => exception`.
131
+ #
132
+ # IMPORTANT: CRuby `Kernel.raise` supports `cause` keyword starting from 2.6.
133
+ # JRuby 9.4 says that it is Ruby 3.1 compatible, but it still does NOT support `cause` keyword.
134
+ # - https://ruby-doc.org/core-2.5.0/Kernel.html#method-i-raise
135
+ # - https://ruby-doc.org/core-2.6/Kernel.html#method-i-raise
136
+ # - https://github.com/jruby/jruby/blob/9.4.0.0/core/src/main/java/org/jruby/RubyKernel.java#L881
137
+ # - https://github.com/ruby/spec/blob/master/core/kernel/raise_spec.rb#L5
138
+ #
139
+ if Dependencies.ruby.jruby?
140
+ def reraise
141
+ yield
142
+ rescue => exception
143
+ ::Kernel.raise exception.class, exception.message, backtrace_cleaner.clean(exception.backtrace)
144
+ end
145
+ else
146
+ def reraise
147
+ yield
148
+ rescue => exception
149
+ ::Kernel.raise exception.class, exception.message, backtrace_cleaner.clean(exception.backtrace), cause: exception.cause
150
+ end
151
+ end
54
152
  end
55
153
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: convenient_service
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.0
4
+ version: 0.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marian Kostyk
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-06 00:00:00.000000000 Z
11
+ date: 2024-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: appraisal
@@ -84,16 +84,16 @@ dependencies:
84
84
  name: commonmarker
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">="
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '0'
89
+ version: 0.23.10
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ">="
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '0'
96
+ version: 0.23.10
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: debug
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -192,34 +192,6 @@ dependencies:
192
192
  - - "~>"
193
193
  - !ruby/object:Gem::Version
194
194
  version: 5.18.0
195
- - !ruby/object:Gem::Dependency
196
- name: mutant
197
- requirement: !ruby/object:Gem::Requirement
198
- requirements:
199
- - - "~>"
200
- - !ruby/object:Gem::Version
201
- version: 0.11.21
202
- type: :development
203
- prerelease: false
204
- version_requirements: !ruby/object:Gem::Requirement
205
- requirements:
206
- - - "~>"
207
- - !ruby/object:Gem::Version
208
- version: 0.11.21
209
- - !ruby/object:Gem::Dependency
210
- name: mutant-rspec
211
- requirement: !ruby/object:Gem::Requirement
212
- requirements:
213
- - - "~>"
214
- - !ruby/object:Gem::Version
215
- version: 0.11.21
216
- type: :development
217
- prerelease: false
218
- version_requirements: !ruby/object:Gem::Requirement
219
- requirements:
220
- - - "~>"
221
- - !ruby/object:Gem::Version
222
- version: 0.11.21
223
195
  - !ruby/object:Gem::Dependency
224
196
  name: paint
225
197
  requirement: !ruby/object:Gem::Requirement
@@ -450,28 +422,28 @@ dependencies:
450
422
  requirements:
451
423
  - - "~>"
452
424
  - !ruby/object:Gem::Version
453
- version: 0.9.28
425
+ version: 0.9.34
454
426
  type: :development
455
427
  prerelease: false
456
428
  version_requirements: !ruby/object:Gem::Requirement
457
429
  requirements:
458
430
  - - "~>"
459
431
  - !ruby/object:Gem::Version
460
- version: 0.9.28
432
+ version: 0.9.34
461
433
  - !ruby/object:Gem::Dependency
462
434
  name: yard-junk
463
435
  requirement: !ruby/object:Gem::Requirement
464
436
  requirements:
465
- - - ">="
437
+ - - "~>"
466
438
  - !ruby/object:Gem::Version
467
- version: '0'
439
+ version: 0.0.9
468
440
  type: :development
469
441
  prerelease: false
470
442
  version_requirements: !ruby/object:Gem::Requirement
471
443
  requirements:
472
- - - ">="
444
+ - - "~>"
473
445
  - !ruby/object:Gem::Version
474
- version: '0'
446
+ version: 0.0.9
475
447
  - !ruby/object:Gem::Dependency
476
448
  name: service_actor
477
449
  requirement: !ruby/object:Gem::Requirement
@@ -662,6 +634,13 @@ files:
662
634
  - lib/convenient_service/common/plugins/has_constructor/concern.rb
663
635
  - lib/convenient_service/common/plugins/has_constructor_without_initialize.rb
664
636
  - lib/convenient_service/common/plugins/has_constructor_without_initialize/concern.rb
637
+ - lib/convenient_service/common/plugins/has_instance_proxy.rb
638
+ - lib/convenient_service/common/plugins/has_instance_proxy/commands.rb
639
+ - lib/convenient_service/common/plugins/has_instance_proxy/commands/create_instance_proxy_class.rb
640
+ - lib/convenient_service/common/plugins/has_instance_proxy/concern.rb
641
+ - lib/convenient_service/common/plugins/has_instance_proxy/entities.rb
642
+ - lib/convenient_service/common/plugins/has_instance_proxy/entities/instance_proxy.rb
643
+ - lib/convenient_service/common/plugins/has_instance_proxy/middleware.rb
665
644
  - lib/convenient_service/common/plugins/has_internals.rb
666
645
  - lib/convenient_service/common/plugins/has_internals/commands.rb
667
646
  - lib/convenient_service/common/plugins/has_internals/commands/create_internals_class.rb
@@ -750,6 +729,7 @@ files:
750
729
  - lib/convenient_service/dependencies/extractions/active_support_concern/concern.rb
751
730
  - lib/convenient_service/dependencies/extractions/b.rb
752
731
  - lib/convenient_service/dependencies/extractions/byebug_syntax_highlighting.rb
732
+ - lib/convenient_service/dependencies/extractions/ce.rb
753
733
  - lib/convenient_service/dependencies/extractions/ruby_middleware.rb
754
734
  - lib/convenient_service/dependencies/extractions/ruby_middleware/middleware.rb
755
735
  - lib/convenient_service/dependencies/extractions/ruby_middleware/middleware/builder.rb
@@ -932,7 +912,6 @@ files:
932
912
  - lib/convenient_service/examples/standard/v1/gemfile/services/format_header.rb
933
913
  - lib/convenient_service/examples/standard/v1/gemfile/services/merge_sections.rb
934
914
  - lib/convenient_service/examples/standard/v1/gemfile/services/parse_content.rb
935
- - lib/convenient_service/examples/standard/v1/gemfile/services/print_shell_command.rb
936
915
  - lib/convenient_service/examples/standard/v1/gemfile/services/read_file_content.rb
937
916
  - lib/convenient_service/examples/standard/v1/gemfile/services/replace_file_content.rb
938
917
  - lib/convenient_service/examples/standard/v1/gemfile/services/run_shell_command.rb
@@ -984,6 +963,7 @@ files:
984
963
  - lib/convenient_service/feature/plugins/aliases.rb
985
964
  - lib/convenient_service/feature/plugins/can_have_entries.rb
986
965
  - lib/convenient_service/feature/plugins/can_have_entries/commands.rb
966
+ - lib/convenient_service/feature/plugins/can_have_entries/commands/define_entries.rb
987
967
  - lib/convenient_service/feature/plugins/can_have_entries/commands/define_entry.rb
988
968
  - lib/convenient_service/feature/plugins/can_have_entries/concern.rb
989
969
  - lib/convenient_service/feature/plugins/can_have_entries/exceptions.rb
@@ -1420,6 +1400,7 @@ files:
1420
1400
  - lib/convenient_service/support/abstract_method/exceptions.rb
1421
1401
  - lib/convenient_service/support/arguments.rb
1422
1402
  - lib/convenient_service/support/arguments/null_arguments.rb
1403
+ - lib/convenient_service/support/backtrace_cleaner.rb
1423
1404
  - lib/convenient_service/support/cache.rb
1424
1405
  - lib/convenient_service/support/cache/constants.rb
1425
1406
  - lib/convenient_service/support/cache/entities.rb
@@ -1,47 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- ##
4
- # Usage example:
5
- #
6
- # ConvenientService::Examples::Standard::V1::Gemfile::Services::PrintShellCommand.result(command: "ls -a")
7
- #
8
- module ConvenientService
9
- module Examples
10
- module Standard
11
- module V1
12
- class Gemfile
13
- module Services
14
- class PrintShellCommand
15
- include ConvenientService::Standard::V1::Config
16
-
17
- attr_reader :command, :skip, :out
18
-
19
- def initialize(command:, skip: false, out: $stdout)
20
- @command = command
21
- @skip = skip
22
- @out = out
23
- end
24
-
25
- def result
26
- return failure(command: "Command is `nil`") if command.nil?
27
- return failure(command: "Command is empty?") if command.empty?
28
-
29
- return error("Printing of shell command `#{command}` is skipped") if skip
30
-
31
- out.puts
32
-
33
- out.puts ::Paint["$ #{command}", :blue, :bold]
34
-
35
- success
36
- end
37
-
38
- def fallback_error_result
39
- success
40
- end
41
- end
42
- end
43
- end
44
- end
45
- end
46
- end
47
- end