convenient_service 0.15.0 → 0.17.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (136) hide show
  1. checksums.yaml +4 -4
  2. data/.github/contributing.md +15 -0
  3. data/.github/workflows/cd.yml +5 -4
  4. data/.github/workflows/ci.yml +5 -5
  5. data/.gitignore +10 -1
  6. data/.ruby-version +1 -1
  7. data/.tool-versions +1 -1
  8. data/.yardopts +1 -1
  9. data/CHANGELOG.md +37 -0
  10. data/COMM-LICENSE.txt +99 -0
  11. data/LICENSE.txt +7 -19
  12. data/README.md +1 -1
  13. data/ROADMAP.md +14 -7
  14. data/convenient_service.gemspec +24 -5
  15. data/docs/.gitkeep +0 -0
  16. data/docs/api/.gitkeep +0 -0
  17. data/lib/convenient_service/common/plugins/can_have_user_provided_entity/commands/find_or_create_entity.rb +7 -2
  18. data/lib/convenient_service/common/plugins/can_have_user_provided_entity/exceptions.rb +4 -4
  19. data/lib/convenient_service/common/plugins/has_around_callbacks/exceptions.rb +2 -2
  20. data/lib/convenient_service/common/plugins/has_around_callbacks/middleware.rb +2 -2
  21. data/lib/convenient_service/common/plugins/has_instance_proxy/commands/create_instance_proxy_class.rb +83 -0
  22. data/lib/convenient_service/common/plugins/has_instance_proxy/commands.rb +3 -0
  23. data/lib/convenient_service/common/plugins/has_instance_proxy/concern.rb +22 -0
  24. data/lib/convenient_service/common/plugins/has_instance_proxy/entities/instance_proxy.rb +76 -0
  25. data/lib/convenient_service/common/plugins/has_instance_proxy/entities.rb +3 -0
  26. data/lib/convenient_service/common/plugins/has_instance_proxy/middleware.rb +20 -0
  27. data/lib/convenient_service/common/plugins/has_instance_proxy.rb +6 -0
  28. data/lib/convenient_service/common/plugins.rb +1 -0
  29. data/lib/convenient_service/core/concern/class_methods.rb +7 -2
  30. data/lib/convenient_service/core/concern/instance_methods.rb +7 -2
  31. data/lib/convenient_service/core/entities/config/commands/track_method_missing_commit_trigger.rb +1 -1
  32. data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/caller/commands/define_method_middlewares_caller.rb +2 -2
  33. data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/middlewares/base/commands/create_observable_middleware.rb +3 -0
  34. data/lib/convenient_service/core/entities/config/exceptions.rb +4 -4
  35. data/lib/convenient_service/core/entities/config.rb +1 -1
  36. data/lib/convenient_service/dependencies/extractions/active_support_backtrace_cleaner/backtrace_cleaner.rb +28 -8
  37. data/lib/convenient_service/dependencies/extractions/active_support_backtrace_cleaner.rb +3 -3
  38. data/lib/convenient_service/dependencies/extractions/b.rb +2 -0
  39. data/lib/convenient_service/dependencies/extractions/ce.rb +16 -0
  40. data/lib/convenient_service/dependencies/extractions.rb +1 -0
  41. data/lib/convenient_service/dependencies.rb +6 -1
  42. data/lib/convenient_service/examples/dry/gemfile.rb +3 -1
  43. data/lib/convenient_service/examples/dry/v1/gemfile.rb +3 -1
  44. data/lib/convenient_service/examples/rails/gemfile.rb +3 -1
  45. data/lib/convenient_service/examples/rails/v1/gemfile.rb +3 -1
  46. data/lib/convenient_service/examples/standard/cowsay.rb +3 -1
  47. data/lib/convenient_service/examples/standard/date_time.rb +3 -1
  48. data/lib/convenient_service/examples/standard/factorial.rb +3 -1
  49. data/lib/convenient_service/examples/standard/gemfile.rb +3 -1
  50. data/lib/convenient_service/examples/standard/request_params.rb +3 -2
  51. data/lib/convenient_service/examples/standard/v1/request_params.rb +0 -1
  52. data/lib/convenient_service/exception.rb +98 -10
  53. data/lib/convenient_service/feature/configs/standard.rb +8 -0
  54. data/lib/convenient_service/feature/plugins/can_have_entries/commands/define_entries.rb +49 -0
  55. data/lib/convenient_service/feature/plugins/can_have_entries/commands/define_entry.rb +29 -3
  56. data/lib/convenient_service/feature/plugins/can_have_entries/commands.rb +1 -0
  57. data/lib/convenient_service/feature/plugins/can_have_entries/concern.rb +14 -5
  58. data/lib/convenient_service/feature/plugins/can_have_entries/exceptions.rb +45 -0
  59. data/lib/convenient_service/feature/plugins/can_have_entries.rb +1 -0
  60. data/lib/convenient_service/logger.rb +4 -1
  61. data/lib/convenient_service/rspec/helpers/classes/stub_service/entities/result_spec.rb +0 -8
  62. data/lib/convenient_service/rspec/helpers/classes/wrap_method/entities/wrapped_method.rb +5 -5
  63. data/lib/convenient_service/rspec/helpers/classes/wrap_method/exceptions.rb +2 -2
  64. data/lib/convenient_service/rspec/matchers/classes/results/base/entities/validator/commands/validate_result_step.rb +1 -1
  65. data/lib/convenient_service/rspec/matchers/classes/results/base/exceptions.rb +2 -2
  66. data/lib/convenient_service/rspec/primitive_helpers/classes/ignoring_exception/exceptions.rb +2 -2
  67. data/lib/convenient_service/rspec/primitive_helpers/classes/ignoring_exception.rb +1 -1
  68. 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
  69. data/lib/convenient_service/rspec/primitive_matchers/classes/delegate_to/entities/matcher/entities/chainings_collection/exceptions.rb +7 -7
  70. data/lib/convenient_service/rspec/primitive_matchers/classes/delegate_to/entities/matcher/entities/chainings_collection.rb +3 -3
  71. data/lib/convenient_service/service/plugins/can_have_fallbacks/concern.rb +2 -2
  72. data/lib/convenient_service/service/plugins/can_have_fallbacks/exceptions.rb +4 -4
  73. data/lib/convenient_service/service/plugins/can_have_fallbacks/middleware.rb +1 -1
  74. data/lib/convenient_service/service/plugins/can_have_steps/concern.rb +3 -3
  75. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/commands/define_method_in_container.rb +2 -2
  76. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/concern/instance_methods.rb +1 -1
  77. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/callers/alias.rb +2 -2
  78. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/callers/proc.rb +1 -1
  79. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/callers/raw.rb +1 -1
  80. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/callers/reassignment.rb +2 -2
  81. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/callers/usual.rb +2 -2
  82. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/directions/input.rb +2 -2
  83. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/directions/output.rb +1 -1
  84. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/exceptions.rb +26 -26
  85. data/lib/convenient_service/service/plugins/can_have_steps/entities/step/concern/instance_methods.rb +1 -1
  86. data/lib/convenient_service/service/plugins/can_have_steps/entities/step/exceptions.rb +2 -2
  87. data/lib/convenient_service/service/plugins/can_have_steps/entities/step/plugins/can_be_result_step/can_be_executed/exceptions.rb +2 -2
  88. data/lib/convenient_service/service/plugins/can_have_steps/entities/step/plugins/can_be_result_step/can_be_executed/middleware.rb +1 -1
  89. data/lib/convenient_service/service/plugins/can_have_steps/entities/step/plugins/raises_on_not_result_return_value/exceptions.rb +2 -2
  90. data/lib/convenient_service/service/plugins/can_have_steps/entities/step/plugins/raises_on_not_result_return_value/middleware.rb +1 -1
  91. data/lib/convenient_service/service/plugins/has_inspect/concern.rb +0 -1
  92. 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
  93. data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/entities/code/concern/instance_methods.rb +24 -0
  94. 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
  95. 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
  96. data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/exceptions.rb +2 -2
  97. data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/raises_on_not_checked_result_status/exceptions.rb +2 -2
  98. data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/raises_on_not_checked_result_status/middleware.rb +1 -1
  99. data/lib/convenient_service/service/plugins/has_j_send_result/exceptions.rb +2 -2
  100. data/lib/convenient_service/service/plugins/has_j_send_result.rb +39 -0
  101. data/lib/convenient_service/service/plugins/has_j_send_result_short_syntax/error/exceptions.rb +6 -6
  102. data/lib/convenient_service/service/plugins/has_j_send_result_short_syntax/error/middleware.rb +3 -3
  103. data/lib/convenient_service/service/plugins/has_j_send_result_short_syntax/failure/exceptions.rb +6 -6
  104. data/lib/convenient_service/service/plugins/has_j_send_result_short_syntax/failure/middleware.rb +3 -3
  105. 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
  106. data/lib/convenient_service/service/plugins/has_j_send_result_short_syntax/success/exceptions.rb +2 -2
  107. data/lib/convenient_service/service/plugins/has_j_send_result_status_check_short_syntax/concern.rb +0 -8
  108. data/lib/convenient_service/service/plugins/has_result/concern.rb +1 -1
  109. data/lib/convenient_service/service/plugins/has_result/exceptions.rb +2 -2
  110. data/lib/convenient_service/service/plugins/raises_on_double_result/exceptions.rb +2 -2
  111. data/lib/convenient_service/service/plugins/raises_on_double_result/middleware.rb +1 -1
  112. data/lib/convenient_service/service/plugins/raises_on_not_result_return_value/exceptions.rb +2 -2
  113. data/lib/convenient_service/service/plugins/raises_on_not_result_return_value/middleware.rb +1 -1
  114. data/lib/convenient_service/support/abstract_method/exceptions.rb +2 -2
  115. data/lib/convenient_service/support/abstract_method.rb +1 -1
  116. data/lib/convenient_service/support/backtrace_cleaner.rb +123 -0
  117. data/lib/convenient_service/support/cache/exceptions.rb +2 -2
  118. data/lib/convenient_service/support/cache.rb +1 -1
  119. data/lib/convenient_service/support/castable/exceptions.rb +4 -4
  120. data/lib/convenient_service/support/castable.rb +1 -1
  121. data/lib/convenient_service/support/command.rb +3 -3
  122. data/lib/convenient_service/support/counter.rb +6 -6
  123. data/lib/convenient_service/support/dependency_container/commands/assert_valid_container.rb +1 -1
  124. data/lib/convenient_service/support/dependency_container/commands/assert_valid_method.rb +1 -1
  125. data/lib/convenient_service/support/dependency_container/commands/assert_valid_scope.rb +1 -1
  126. data/lib/convenient_service/support/dependency_container/exceptions.rb +8 -8
  127. data/lib/convenient_service/support/dependency_container/export.rb +1 -1
  128. data/lib/convenient_service/support/finite_loop.rb +6 -6
  129. data/lib/convenient_service/support.rb +1 -0
  130. data/lib/convenient_service/utils/array/exceptions.rb +2 -2
  131. data/lib/convenient_service/utils/array/merge.rb +1 -1
  132. data/lib/convenient_service/utils/hash/assert_valid_keys.rb +1 -1
  133. data/lib/convenient_service/version.rb +1 -1
  134. data/lib/convenient_service.rb +98 -0
  135. metadata +28 -42
  136. data/lib/convenient_service/examples/standard/v1/gemfile/services/print_shell_command.rb +0 -47
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ConvenientService
4
+ module Common
5
+ module Plugins
6
+ module HasInstanceProxy
7
+ module Concern
8
+ include Support::Concern
9
+
10
+ class_methods do
11
+ ##
12
+ # @return [Class] Can be any type.
13
+ #
14
+ def instance_proxy_class
15
+ @instance_proxy_class ||= Commands::CreateInstanceProxyClass[target_class: self]
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ConvenientService
4
+ module Common
5
+ module Plugins
6
+ module HasInstanceProxy
7
+ module Entities
8
+ class InstanceProxy
9
+ ##
10
+ # @api private
11
+ #
12
+ # @param target [Object] Can be any type.
13
+ # @return [void]
14
+ #
15
+ def initialize(target:)
16
+ @__convenient_service_instance_proxy_target__ = target
17
+ end
18
+
19
+ ##
20
+ # @api public
21
+ #
22
+ # @return [Object] Can be any type.
23
+ #
24
+ def instance_proxy_target
25
+ @__convenient_service_instance_proxy_target__
26
+ end
27
+
28
+ ##
29
+ # @api public
30
+ #
31
+ # @param other [Object] Can be any type.
32
+ # @return [Boolean, nil]
33
+ #
34
+ # @internal
35
+ # TODO: Direct Specs.
36
+ #
37
+ def ==(other)
38
+ return unless other.instance_of?(self.class)
39
+
40
+ return false if instance_proxy_target != other.instance_proxy_target
41
+
42
+ true
43
+ end
44
+
45
+ private
46
+
47
+ ##
48
+ # @see https://thoughtbot.com/blog/always-define-respond-to-missing-when-overriding
49
+ # @see https://blog.marc-andre.ca/2010/11/15/methodmissing-politely
50
+ # @see https://stackoverflow.com/a/3304683/12201472
51
+ #
52
+ # @param method_name [Symbol, String]
53
+ # @param include_private [Boolean]
54
+ # @return [Boolean]
55
+ #
56
+ # @internal
57
+ # IMPORTANT: `respond_to_missing?` is like `initialize`. It is always `private`.
58
+ # - https://ruby-doc.org/core-2.7.0/Object.html#method-i-respond_to_missing-3F
59
+ # - https://github.com/ruby/spec/blob/master/language/def_spec.rb#L65
60
+ #
61
+ def respond_to_missing?(method_name, include_private = false)
62
+ instance_proxy_target.respond_to?(method_name, include_private)
63
+ end
64
+
65
+ ##
66
+ # @return [Object] Can be any type.
67
+ #
68
+ def method_missing(...)
69
+ instance_proxy_target.public_send(...)
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "entities/instance_proxy"
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ConvenientService
4
+ module Common
5
+ module Plugins
6
+ module HasInstanceProxy
7
+ class Middleware < MethodChainMiddleware
8
+ intended_for :new, scope: :class, entity: any_entity
9
+
10
+ ##
11
+ # @return [ConvenientService::Common::Plugins::HasInstanceProxy::Entities::InstanceProxy]
12
+ #
13
+ def next(...)
14
+ entity.instance_proxy_class.new(target: chain.next(...))
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "has_instance_proxy/commands"
4
+ require_relative "has_instance_proxy/concern"
5
+ require_relative "has_instance_proxy/entities"
6
+ require_relative "has_instance_proxy/middleware"
@@ -14,6 +14,7 @@ require_relative "plugins/has_around_callbacks"
14
14
  require_relative "plugins/has_constructor"
15
15
  require_relative "plugins/has_constructor_without_initialize"
16
16
  require_relative "plugins/has_internals"
17
+ require_relative "plugins/has_instance_proxy"
17
18
  require_relative "plugins/has_j_send_result_duck_short_syntax"
18
19
 
19
20
  require_relative "plugins/aliases"
@@ -70,6 +70,7 @@ module ConvenientService
70
70
 
71
71
  ##
72
72
  # @see https://thoughtbot.com/blog/always-define-respond-to-missing-when-overriding
73
+ # @see https://blog.marc-andre.ca/2010/11/15/methodmissing-politely
73
74
  # @see https://stackoverflow.com/a/3304683/12201472
74
75
  #
75
76
  # @param method_name [Symbol, String]
@@ -112,12 +113,16 @@ module ConvenientService
112
113
  #
113
114
  # TODO: Include `method` into trigger metadata.
114
115
  #
116
+ # IMPORTANT: Ruby 2.7 and Ruby 3.0+ invoke this `method_missing` differently, check the following files/links:
117
+ # - `lib/convenient_service/core/entities/config/entities/method_middlewares/entities/caller/commands/define_method_middlewares_caller.rb`
118
+ # - https://gist.github.com/marian13/9c25041f835564e945d978839097d419
119
+ #
115
120
  def method_missing(method, *args, **kwargs, &block)
116
121
  commit_config!(trigger: Constants::Triggers::CLASS_METHOD_MISSING)
117
122
 
118
- return super unless Utils::Module.class_method_defined?(self, method, public: true, protected: false, private: false)
123
+ return ::ConvenientService.reraise { super } unless Utils::Module.class_method_defined?(self, method, public: true, protected: false, private: false)
119
124
 
120
- return super if middlewares(method, scope: :class).defined_without_super_method?
125
+ return ::ConvenientService.reraise { super } if middlewares(method, scope: :class).defined_without_super_method?
121
126
 
122
127
  ConvenientService.logger.debug { "[Core] Committed config for `#{self}` | Triggered by `method_missing` | Method: `.#{method}`" }
123
128
 
@@ -17,6 +17,7 @@ module ConvenientService
17
17
 
18
18
  ##
19
19
  # @see https://thoughtbot.com/blog/always-define-respond-to-missing-when-overriding
20
+ # @see https://blog.marc-andre.ca/2010/11/15/methodmissing-politely
20
21
  # @see https://stackoverflow.com/a/3304683/12201472
21
22
  #
22
23
  # @param method_name [Symbol, String]
@@ -59,12 +60,16 @@ module ConvenientService
59
60
  #
60
61
  # TODO: Include `method` into trigger metadata.
61
62
  #
63
+ # IMPORTANT: Ruby 2.7 and Ruby 3.0+ invoke this `method_missing` differently, check the following files/links:
64
+ # - `lib/convenient_service/core/entities/config/entities/method_middlewares/entities/caller/commands/define_method_middlewares_caller.rb`
65
+ # - https://gist.github.com/marian13/9c25041f835564e945d978839097d419
66
+ #
62
67
  def method_missing(method, *args, **kwargs, &block)
63
68
  self.class.commit_config!(trigger: Constants::Triggers::INSTANCE_METHOD_MISSING)
64
69
 
65
- return super unless Utils::Module.instance_method_defined?(self.class, method, public: true, protected: false, private: false)
70
+ return ::ConvenientService.reraise { super } unless Utils::Module.instance_method_defined?(self.class, method, public: true, protected: false, private: false)
66
71
 
67
- return super if self.class.middlewares(method, scope: :instance).defined_without_super_method?
72
+ return ::ConvenientService.reraise { super } if self.class.middlewares(method, scope: :instance).defined_without_super_method?
68
73
 
69
74
  ConvenientService.logger.debug { "[Core] Committed config for `#{self.class}` | Triggered by `method_missing` | Method: `##{method}`" }
70
75
 
@@ -35,7 +35,7 @@ module ConvenientService
35
35
  return unless method_missing_trigger_valid?
36
36
  return if method_missing_commits_counter_incremented?
37
37
 
38
- raise Exceptions::TooManyCommitsFromMethodMissing.new(config: config)
38
+ ::ConvenientService.raise Exceptions::TooManyCommitsFromMethodMissing.new(config: config)
39
39
  end
40
40
 
41
41
  ##
@@ -90,9 +90,9 @@ module ConvenientService
90
90
  # prefix = "#{prefix}"
91
91
  #
92
92
  # NOTE: Check the following link in order to get an idea why two versions of `define_method_middlewares_caller` exist.
93
- # https://gist.github.com/marian13/9c25041f835564e945d978839097d419
93
+ # - https://gist.github.com/marian13/9c25041f835564e945d978839097d419
94
94
  #
95
- if ::RUBY_VERSION >= "3.0"
95
+ if Dependencies.ruby.version >= 3.0
96
96
  def define_method_middlewares_caller
97
97
  <<~RUBY.tap { |code| methods_middlewares_callers.module_eval(code, __FILE__, __LINE__ + 1) }
98
98
  def #{method}(*args, **kwargs, &block)
@@ -39,6 +39,9 @@ module ConvenientService
39
39
  # @param other [Object] Can be any type.
40
40
  # @return [Boolean, nil]
41
41
  #
42
+ # @internal
43
+ # TODO: Try `self.middleware == other.middleware if self < ::ConvenientService::Core::Entities::Config::Entities::MethodMiddlewares::Entities::Middlewares::Base`.
44
+ #
42
45
  define_singleton_method(:==) { |other| self.middleware == other.middleware if other.respond_to?(:middleware) }
43
46
 
44
47
  ##
@@ -10,14 +10,14 @@ module ConvenientService
10
10
  # @param config [ConvenientService::Core::Entities::Config]
11
11
  # @return [void]
12
12
  #
13
- def initialize(config:)
13
+ def initialize_with_kwargs(config:)
14
14
  message = <<~TEXT
15
15
  Config for `#{config.klass}` is already committed. Only uncommitted configs can be modified.
16
16
 
17
17
  Did you accidentally call `concerns(&configuration_block)` or `middlewares(method, scope: scope, &configuration_block)` after using any plugin, after calling `commit_config!`?
18
18
  TEXT
19
19
 
20
- super(message)
20
+ initialize(message)
21
21
  end
22
22
  end
23
23
 
@@ -30,7 +30,7 @@ module ConvenientService
30
30
  # TODO: Create a troubleshooting page with possible reasons (preliminary RSpec mocks etc).
31
31
  # Append a link to it to the error message.
32
32
  #
33
- def initialize(config:)
33
+ def initialize_with_kwargs(config:)
34
34
  message = <<~TEXT
35
35
  `#{config.klass}` config is committed too many times from `method_missing`.
36
36
 
@@ -54,7 +54,7 @@ module ConvenientService
54
54
  end
55
55
  TEXT
56
56
 
57
- super(message)
57
+ initialize(message)
58
58
  end
59
59
  end
60
60
  end
@@ -162,7 +162,7 @@ module ConvenientService
162
162
  def assert_not_committed!
163
163
  return unless committed?
164
164
 
165
- raise Exceptions::ConfigIsCommitted.new(config: self)
165
+ ::ConvenientService.raise Exceptions::ConfigIsCommitted.new(config: self)
166
166
  end
167
167
  end
168
168
  end
@@ -7,15 +7,17 @@ module ConvenientService
7
7
  # @internal
8
8
  # NOTE:
9
9
  # Copied from `rails/rails` without any logic modification.
10
- # Version: v7.0.4.3.
10
+ # Version: v7.1.2.
11
11
  # Wrapped in a namespace `ConvenientService::Dependencies::Extractions::ActiveSupportBacktraceCleaner`.
12
12
  #
13
- # - https://api.rubyonrails.org/v7.0.4.3/classes/ActiveSupport/BacktraceCleaner.html
14
- # - https://github.com/rails/rails/blob/v7.0.4.3/activesupport/lib/active_support/backtrace_cleaner.rb
13
+ # - https://api.rubyonrails.org/v7.1.2/classes/ActiveSupport/BacktraceCleaner.html
14
+ # - https://github.com/rails/rails/blob/v7.1.2/activesupport/lib/active_support/backtrace_cleaner.rb
15
15
  # - https://github.com/marian13/rails/blob/main/activesupport/lib/active_support/backtrace_cleaner.rb
16
16
  # - https://github.com/rails/rails
17
17
  #
18
18
  module ActiveSupportBacktraceCleaner
19
+ # = Backtrace Cleaner
20
+ #
19
21
  # Backtraces often include many lines that are not relevant for the context
20
22
  # under review. This makes it hard to find the signal amongst the backtrace
21
23
  # noise, and adds debugging time. With a BacktraceCleaner, filters and
@@ -34,7 +36,7 @@ module ConvenientService
34
36
  # bc.add_silencer { |line| /puma|rubygems/.match?(line) } # skip any lines from puma or rubygems
35
37
  # bc.clean(exception.backtrace) # perform the cleanup
36
38
  #
37
- # To reconfigure an existing BacktraceCleaner (like the default one in Rails)
39
+ # To reconfigure an existing BacktraceCleaner (like the default one in \Rails)
38
40
  # and show as much data as possible, you can always call
39
41
  # BacktraceCleaner#remove_silencers!, which will restore the
40
42
  # backtrace to a pristine state. If you need to reconfigure an existing
@@ -67,11 +69,29 @@ module ConvenientService
67
69
  end
68
70
  alias :filter :clean
69
71
 
72
+ # Returns the frame with all filters applied.
73
+ # returns +nil+ if the frame was silenced.
74
+ def clean_frame(frame, kind = :silent)
75
+ frame = frame.to_s
76
+ @filters.each do |f|
77
+ frame = f.call(frame.to_s)
78
+ end
79
+
80
+ case kind
81
+ when :silent
82
+ frame unless @silencers.any? { |s| s.call(frame) }
83
+ when :noise
84
+ frame if @silencers.any? { |s| s.call(frame) }
85
+ else
86
+ frame
87
+ end
88
+ end
89
+
70
90
  # Adds a filter from the block provided. Each line in the backtrace will be
71
91
  # mapped against this filter.
72
92
  #
73
93
  # # Will turn "/my/rails/root/app/models/person.rb" into "/app/models/person.rb"
74
- # backtrace_cleaner.add_filter { |line| line.gsub(Rails.root, '') }
94
+ # backtrace_cleaner.add_filter { |line| line.gsub(Rails.root.to_s, '') }
75
95
  def add_filter(&block)
76
96
  @filters << block
77
97
  end
@@ -121,7 +141,7 @@ module ConvenientService
121
141
 
122
142
  def filter_backtrace(backtrace)
123
143
  @filters.each do |f|
124
- backtrace = backtrace.map { |line| f.call(line) }
144
+ backtrace = backtrace.map { |line| f.call(line.to_s) }
125
145
  end
126
146
 
127
147
  backtrace
@@ -129,7 +149,7 @@ module ConvenientService
129
149
 
130
150
  def silence(backtrace)
131
151
  @silencers.each do |s|
132
- backtrace = backtrace.reject { |line| s.call(line) }
152
+ backtrace = backtrace.reject { |line| s.call(line.to_s) }
133
153
  end
134
154
 
135
155
  backtrace
@@ -138,7 +158,7 @@ module ConvenientService
138
158
  def noise(backtrace)
139
159
  backtrace.select do |line|
140
160
  @silencers.any? do |s|
141
- s.call(line)
161
+ s.call(line.to_s)
142
162
  end
143
163
  end
144
164
  end
@@ -4,11 +4,11 @@
4
4
  # @internal
5
5
  # NOTE:
6
6
  # Copied from `rails/rails` without any logic modification.
7
- # Version: v7.0.4.3.
7
+ # Version: v7.1.2.
8
8
  # Wrapped in a namespace `ConvenientService::Dependencies::Extractions::ActiveSupportBacktraceCleaner`.
9
9
  #
10
- # - https://api.rubyonrails.org/v7.0.4.3/classes/ActiveSupport/BacktraceCleaner.html
11
- # - https://github.com/rails/rails/blob/v7.0.4.3/activesupport/lib/active_support/backtrace_cleaner.rb
10
+ # - https://api.rubyonrails.org/v7.1.2/classes/ActiveSupport/BacktraceCleaner.html
11
+ # - https://github.com/rails/rails/blob/v7.1.2/activesupport/lib/active_support/backtrace_cleaner.rb
12
12
  # - https://github.com/marian13/rails/blob/main/activesupport/lib/active_support/backtrace_cleaner.rb
13
13
  # - https://github.com/rails/rails
14
14
  #
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  ##
2
4
  # Works in a similar way as `p`, but for `byebug`.
3
5
  # @see https://ruby-doc.org/core-2.7.0/Kernel.html#method-i-p
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ ##
4
+ # @note `ce` is short for `catch_exception`.
5
+ #
6
+ # @example
7
+ # ce { some_code }
8
+ # e = ce { some_code }
9
+ #
10
+ def ce
11
+ yield
12
+
13
+ nil
14
+ rescue => exception
15
+ exception
16
+ end
@@ -7,4 +7,5 @@
7
7
  # https://github.com/marian13/convenient_service/wiki/Docs:-Dependencies
8
8
  #
9
9
  require_relative "extractions/active_support_concern"
10
+ require_relative "extractions/active_support_backtrace_cleaner"
10
11
  require_relative "extractions/ruby_middleware"
@@ -135,7 +135,7 @@ module ConvenientService
135
135
  # @return [Boolean]
136
136
  # @note Expected to be called from app entry points like `initializers` in Rails.
137
137
  #
138
- # @see https://marian13.github.io/convenient_service_docs/troubleshooting/i18n_translate_wrong_number_of_arguments
138
+ # @see https://userdocs.convenientservice.org/troubleshooting/i18n_translate_wrong_number_of_arguments
139
139
  #
140
140
  def require_has_j_send_result_params_validations_using_active_model_validations
141
141
  ##
@@ -244,6 +244,11 @@ module ConvenientService
244
244
  require_relative "dependencies/extractions/byebug_syntax_highlighting" unless ruby.jruby?
245
245
 
246
246
  require_relative "dependencies/extractions/b" unless ruby.jruby?
247
+
248
+ ##
249
+ #
250
+ #
251
+ require_relative "dependencies/extractions/ce"
247
252
  end
248
253
 
249
254
  ##
@@ -16,7 +16,9 @@ module ConvenientService
16
16
  class Gemfile
17
17
  include ConvenientService::Feature::Standard::Config
18
18
 
19
- entry :format do |path|
19
+ entry :format
20
+
21
+ def format(path)
20
22
  Services::Format[path: path]
21
23
  end
22
24
  end
@@ -17,7 +17,9 @@ module ConvenientService
17
17
  class Gemfile
18
18
  include ConvenientService::Feature::Standard::Config
19
19
 
20
- entry :format do |path|
20
+ entry :format
21
+
22
+ def format(path)
21
23
  Services::Format[path: path]
22
24
  end
23
25
  end
@@ -16,7 +16,9 @@ module ConvenientService
16
16
  class Gemfile
17
17
  include ConvenientService::Feature::Standard::Config
18
18
 
19
- entry :format do |path|
19
+ entry :format
20
+
21
+ def format(path)
20
22
  Services::Format[path: path]
21
23
  end
22
24
  end
@@ -17,7 +17,9 @@ module ConvenientService
17
17
  class Gemfile
18
18
  include ConvenientService::Feature::Standard::Config
19
19
 
20
- entry :format do |path|
20
+ entry :format
21
+
22
+ def format(path)
21
23
  Services::Format[path: path]
22
24
  end
23
25
  end
@@ -15,7 +15,9 @@ module ConvenientService
15
15
  class Cowsay
16
16
  include ConvenientService::Feature::Standard::Config
17
17
 
18
- entry :print do |text = "Hello World!", out: $stdout|
18
+ entry :print
19
+
20
+ def print(text = "Hello World!", out: $stdout)
19
21
  Services::Print[text: text, out: out]
20
22
  end
21
23
  end
@@ -14,7 +14,9 @@ module ConvenientService
14
14
  class DateTime
15
15
  include ConvenientService::Feature::Standard::Config
16
16
 
17
- entry :safe_parse do |string, format|
17
+ entry :safe_parse
18
+
19
+ def safe_parse(string, format)
18
20
  Services::SafeParse[string: string, format: format]
19
21
  end
20
22
  end
@@ -15,7 +15,9 @@ module ConvenientService
15
15
  class Factorial
16
16
  include ConvenientService::Feature::Standard::Config
17
17
 
18
- entry :calculate do |number|
18
+ entry :calculate
19
+
20
+ def calculate(number)
19
21
  Services::Calculate[number: number]
20
22
  end
21
23
  end
@@ -15,7 +15,9 @@ module ConvenientService
15
15
  class Gemfile
16
16
  include ConvenientService::Feature::Standard::Config
17
17
 
18
- entry :format do |path|
18
+ entry :format
19
+
20
+ def format(path)
19
21
  Services::Format[path: path]
20
22
  end
21
23
  end
@@ -6,7 +6,6 @@ require_relative "request_params/services"
6
6
  require_relative "request_params/utils"
7
7
 
8
8
  ##
9
- # @since 0.3.0
10
9
  #
11
10
  # @internal
12
11
  # Usage example:
@@ -39,7 +38,9 @@ module ConvenientService
39
38
  class RequestParams
40
39
  include ConvenientService::Feature::Standard::Config
41
40
 
42
- entry :prepare do |request|
41
+ entry :prepare
42
+
43
+ def prepare(request)
43
44
  Services::Prepare[request: request]
44
45
  end
45
46
  end
@@ -6,7 +6,6 @@ require_relative "request_params/services"
6
6
  require_relative "request_params/utils"
7
7
 
8
8
  ##
9
- # @since 0.3.0
10
9
  #
11
10
  # @internal
12
11
  # Usage example: