convenient_service 0.18.0 → 0.19.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +4 -3
  3. data/lib/convenient_service/commands/is_service.rb +28 -0
  4. data/lib/convenient_service/commands/is_service_class.rb +30 -0
  5. data/lib/convenient_service/commands.rb +4 -0
  6. data/lib/convenient_service/common/plugins.rb +2 -3
  7. data/lib/convenient_service/core/concern/class_methods.rb +3 -0
  8. data/lib/convenient_service/core/entities/config/entities/concerns/entities/stack.rb +22 -0
  9. data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/container/concern/instance_methods.rb +1 -1
  10. data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/middleware_creators/observable/entities/event.rb +13 -15
  11. data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/middlewares/chain/commands/normalize_env.rb +55 -0
  12. data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/middlewares/chain/commands.rb +1 -0
  13. data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/middlewares/chain/concern/instance_methods.rb +3 -3
  14. data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/middlewares/classic.rb +14 -0
  15. data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/stack.rb +22 -0
  16. data/lib/convenient_service/dependencies/built_in.rb +0 -7
  17. data/lib/convenient_service/dependencies/extractions/ds.rb +45 -0
  18. data/lib/convenient_service/dependencies/only_queries.rb +29 -0
  19. data/lib/convenient_service/dependencies/queries/gems/active_model.rb +38 -0
  20. data/lib/convenient_service/dependencies/queries/gems/logger.rb +39 -0
  21. data/lib/convenient_service/dependencies/queries/gems/paint.rb +39 -0
  22. data/lib/convenient_service/dependencies/queries/gems/rspec.rb +60 -0
  23. data/lib/convenient_service/dependencies/queries/ruby.rb +103 -0
  24. data/lib/convenient_service/dependencies/queries/version/null_version.rb +87 -0
  25. data/lib/convenient_service/dependencies/queries/version.rb +87 -0
  26. data/lib/convenient_service/dependencies/queries.rb +536 -0
  27. data/lib/convenient_service/dependencies.rb +2 -438
  28. data/lib/convenient_service/feature/configs/standard.rb +0 -2
  29. data/lib/convenient_service/service/configs/amazing_print_inspect/aliases.rb +7 -0
  30. data/lib/convenient_service/service/configs/amazing_print_inspect.rb +61 -0
  31. data/lib/convenient_service/service/configs/awesome_print_inspect.rb +1 -1
  32. data/lib/convenient_service/service/configs/{minimal.rb → essential.rb} +2 -107
  33. data/lib/convenient_service/service/configs/standard/v1.rb +5 -10
  34. data/lib/convenient_service/service/configs/standard.rb +19 -31
  35. data/lib/convenient_service/service/configs.rb +1 -1
  36. data/lib/convenient_service/service/plugins/can_have_connected_steps/entities/expressions/and.rb +4 -1
  37. data/lib/convenient_service/service/plugins/can_have_connected_steps/entities/expressions/empty.rb +4 -4
  38. data/lib/convenient_service/service/plugins/can_have_connected_steps/entities/step_collection.rb +7 -0
  39. data/lib/convenient_service/service/plugins/can_have_fallbacks/concern.rb +18 -0
  40. data/lib/convenient_service/service/plugins/can_have_fallbacks/exceptions.rb +22 -4
  41. data/lib/convenient_service/service/plugins/can_have_fallbacks/middleware.rb +3 -3
  42. data/lib/convenient_service/service/plugins/can_have_rollbacks/middleware.rb +66 -0
  43. data/lib/convenient_service/service/plugins/can_have_rollbacks.rb +3 -0
  44. data/lib/convenient_service/service/plugins/can_have_sequential_steps/entities/step_collection.rb +7 -0
  45. data/lib/convenient_service/service/plugins/can_have_steps/commands/is_step.rb +34 -0
  46. data/lib/convenient_service/service/plugins/can_have_steps/commands.rb +1 -0
  47. data/lib/convenient_service/service/plugins/can_have_steps/entities/step/concern/instance_methods.rb +22 -14
  48. data/lib/convenient_service/service/plugins/can_have_steps/entities/step/plugins/can_be_method_step/can_be_executed/middleware.rb +1 -15
  49. data/lib/convenient_service/service/plugins/can_have_steps/entities/step/plugins/can_have_fallbacks/exceptions.rb +53 -0
  50. data/lib/convenient_service/service/plugins/can_have_steps/entities/step/plugins/can_have_fallbacks/middleware.rb +60 -15
  51. data/lib/convenient_service/service/plugins/can_have_steps/entities/step/plugins/can_have_fallbacks.rb +1 -0
  52. data/lib/convenient_service/service/plugins/can_have_steps/entities/step/plugins/has_amazing_print_inspect/concern.rb +46 -0
  53. data/lib/convenient_service/service/plugins/can_have_steps/entities/step/plugins/has_amazing_print_inspect.rb +3 -0
  54. data/lib/convenient_service/service/plugins/can_have_steps/entities/step/plugins/has_awesome_print_inspect/concern.rb +3 -2
  55. data/lib/convenient_service/service/plugins/can_have_steps/entities/step/plugins/has_result/middleware.rb +26 -1
  56. data/lib/convenient_service/service/plugins/can_have_steps.rb +41 -0
  57. data/lib/convenient_service/service/plugins/can_have_stubbed_results/commands/fetch_all_services_stubbed_results_cache.rb +2 -2
  58. data/lib/convenient_service/service/plugins/forbids_convenient_service_entities_as_constructor_arguments/exceptions.rb +53 -0
  59. data/lib/convenient_service/service/plugins/forbids_convenient_service_entities_as_constructor_arguments/middleware.rb +108 -0
  60. data/lib/convenient_service/service/plugins/forbids_convenient_service_entities_as_constructor_arguments.rb +4 -0
  61. data/lib/convenient_service/service/plugins/has_amazing_print_inspect/concern.rb +39 -0
  62. data/lib/convenient_service/service/plugins/has_amazing_print_inspect.rb +3 -0
  63. data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/can_be_from_exception/concern.rb +32 -0
  64. data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/can_be_from_exception.rb +3 -0
  65. data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/can_have_step/concern.rb +7 -0
  66. data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_amazing_print_inspect/concern.rb +41 -0
  67. data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_amazing_print_inspect.rb +3 -0
  68. data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_awesome_print_inspect/concern.rb +2 -2
  69. data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/concern/instance_methods.rb +0 -140
  70. data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/entities/code/plugins/has_amazing_print_inspect/concern.rb +46 -0
  71. data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/entities/code/plugins/has_amazing_print_inspect.rb +3 -0
  72. data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/entities/data/plugins/has_amazing_print_inspect/concern.rb +46 -0
  73. data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/entities/data/plugins/has_amazing_print_inspect.rb +3 -0
  74. data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/entities/message/plugins/has_amazing_print_inspect/concern.rb +46 -0
  75. data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/entities/message/plugins/has_amazing_print_inspect.rb +3 -0
  76. data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/entities/status/plugins/has_amazing_print_inspect/concern.rb +46 -0
  77. data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/entities/status/plugins/has_amazing_print_inspect.rb +3 -0
  78. data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/helps_to_learn_similarities_with_common_objects/concern/instance_methods.rb +161 -0
  79. data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/helps_to_learn_similarities_with_common_objects/concern.rb +27 -0
  80. data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/helps_to_learn_similarities_with_common_objects/exceptions.rb +34 -0
  81. data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/helps_to_learn_similarities_with_common_objects.rb +4 -0
  82. data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins.rb +2 -0
  83. data/lib/convenient_service/service/plugins/has_mermaid_flowchart/concern.rb +6 -1
  84. data/lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions/middleware.rb +1 -0
  85. data/lib/convenient_service/service/plugins.rb +3 -1
  86. data/lib/convenient_service/support/counter.rb +2 -0
  87. data/lib/convenient_service/support/middleware/stack_builder.rb +37 -0
  88. data/lib/convenient_service/support/thread_safe_counter.rb +1 -0
  89. data/lib/convenient_service/support.rb +0 -3
  90. data/lib/convenient_service/utils/object/get_own_method.rb +54 -0
  91. data/lib/convenient_service/utils/object/safe_send.rb +84 -0
  92. data/lib/convenient_service/utils/object.rb +24 -0
  93. data/lib/convenient_service/utils/string/enclose.rb +52 -0
  94. data/lib/convenient_service/utils/string.rb +5 -0
  95. data/lib/convenient_service/version.rb +1 -1
  96. data/lib/convenient_service.rb +62 -0
  97. metadata +149 -16
  98. data/lib/convenient_service/common/plugins/normalizes_env/middleware.rb +0 -31
  99. data/lib/convenient_service/common/plugins/normalizes_env.rb +0 -3
  100. data/lib/convenient_service/service/plugins/can_have_steps/entities/step/plugins/can_have_fallbacks/result.rb +0 -3
  101. data/lib/convenient_service/services.rb +0 -4
  102. data/lib/convenient_service/support/gems/active_model.rb +0 -36
  103. data/lib/convenient_service/support/gems/logger.rb +0 -37
  104. data/lib/convenient_service/support/gems/paint.rb +0 -37
  105. data/lib/convenient_service/support/gems/rspec.rb +0 -58
  106. data/lib/convenient_service/support/ruby.rb +0 -53
  107. data/lib/convenient_service/support/version/null_version.rb +0 -85
  108. data/lib/convenient_service/support/version.rb +0 -75
  109. /data/lib/convenient_service/{support → dependencies/queries}/gems.rb +0 -0
@@ -0,0 +1,103 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ConvenientService
4
+ module Dependencies
5
+ module Queries
6
+ ##
7
+ # @api private
8
+ #
9
+ class Ruby
10
+ class << self
11
+ ##
12
+ # @return [ConvenientService::Dependencies::Queries::Version]
13
+ #
14
+ # @internal
15
+ # NOTE: Ruby defines `RUBY_VERSION` global variable.
16
+ # - https://ruby-doc.org/core-2.7.2/doc/globals_rdoc.html
17
+ #
18
+ def version
19
+ @version ||= Version.new(::RUBY_VERSION)
20
+ end
21
+
22
+ ##
23
+ # @return [String]
24
+ #
25
+ # @internal
26
+ # TODO: Add direct specs.
27
+ #
28
+ def engine
29
+ ::RUBY_ENGINE.to_s
30
+ end
31
+
32
+ ##
33
+ # @return [ConvenientService::Dependencies::Queries::Version]
34
+ #
35
+ # @internal
36
+ # NOTE: Ruby defines `RUBY_ENGINE_VERSION` global variable.
37
+ # - https://ruby-doc.org/core-2.7.2/doc/globals_rdoc.html
38
+ #
39
+ # NOTE: JRuby defines `RUBY_ENGINE_VERSION` global variable.
40
+ # - https://github.com/jruby/jruby/blob/9.4.0.0/spec/jruby/compat_spec.rb#L6
41
+ #
42
+ # NOTE: TruffleRuby defines `RUBY_ENGINE_VERSION` global variable.
43
+ # - https://github.com/oracle/truffleruby/blob/vm-22.3.0/spec/truffle/identity_spec.rb#L23
44
+ #
45
+ # TODO: Add direct specs.
46
+ #
47
+ def engine_version
48
+ @engine_version ||= Version.new(::RUBY_ENGINE_VERSION)
49
+ end
50
+
51
+ ##
52
+ # Returns `true` when MRI, `false` otherwise.
53
+ #
54
+ # @return [Boolean]
55
+ #
56
+ # @see https://github.com/janlelis/ruby_engine
57
+ #
58
+ # @internal
59
+ # NOTE: Gratefully copied from the `ruby_engine` gem. Version `1.1.4`.
60
+ # - https://github.com/janlelis/ruby_engine/blob/v2.0.0/lib/ruby_engine.rb#L19
61
+ #
62
+ def mri?
63
+ ::RUBY_ENGINE.to_s == "ruby"
64
+ end
65
+
66
+ alias_method :ruby?, :mri?
67
+
68
+ ##
69
+ # Returns `true` when JRuby, `false` otherwise.
70
+ #
71
+ # @return [Boolean]
72
+ #
73
+ # @see https://github.com/rdp/os
74
+ #
75
+ # @internal
76
+ # NOTE: Gratefully copied from the `os` gem. Version `1.1.4`.
77
+ # - https://github.com/rdp/os/blob/v1.1.4/lib/os.rb#L101
78
+ #
79
+ # NOTE: Modified original implementation in order to return a boolean.
80
+ # NOTE: Consider to use `RUBY_ENGINE` as for others?
81
+ #
82
+ def jruby?
83
+ ::RUBY_PLATFORM.to_s.match?(/java/)
84
+ end
85
+
86
+ ##
87
+ # Returns `true` when TruffleRuby, `false` otherwise.
88
+ #
89
+ # @return [Boolean]
90
+ #
91
+ # @internal
92
+ # NOTE: Taken from irb testing. May NOT be stable.
93
+ #
94
+ # TODO: Find a confirmation of stability.
95
+ #
96
+ def truffleruby?
97
+ ::RUBY_ENGINE.to_s.match?(/truffleruby/)
98
+ end
99
+ end
100
+ end
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,87 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ConvenientService
4
+ module Dependencies
5
+ module Queries
6
+ class Version
7
+ ##
8
+ # @api private
9
+ #
10
+ # @internal
11
+ # - https://thoughtbot.com/blog/rails-refactoring-example-introduce-null-object
12
+ # - https://avdi.codes/null-objects-and-falsiness/
13
+ #
14
+ class NullVersion
15
+ ##
16
+ # @return [Boolean]
17
+ #
18
+ def null_version?
19
+ true
20
+ end
21
+
22
+ ##
23
+ # @return [nil]
24
+ #
25
+ def gem_version
26
+ nil
27
+ end
28
+
29
+ ##
30
+ # @param other [Object] Can be any type.
31
+ # @return [nil]
32
+ #
33
+ def <=>(other)
34
+ nil
35
+ end
36
+
37
+ ##
38
+ # @param other [Object] Can be any type.
39
+ # @return [nil]
40
+ #
41
+ def <(other)
42
+ nil
43
+ end
44
+
45
+ ##
46
+ # @param other [Object] Can be any type.
47
+ # @return [nil]
48
+ #
49
+ def <=(other)
50
+ nil
51
+ end
52
+
53
+ ##
54
+ # @param other [Object] Can be any type.
55
+ # @return [nil]
56
+ #
57
+ def ==(other)
58
+ nil
59
+ end
60
+
61
+ ##
62
+ # @param other [Object] Can be any type.
63
+ # @return [nil]
64
+ #
65
+ def >(other)
66
+ nil
67
+ end
68
+
69
+ ##
70
+ # @param other [Object] Can be any type.
71
+ # @return [nil]
72
+ #
73
+ def >=(other)
74
+ nil
75
+ end
76
+
77
+ ##
78
+ # @return [String]
79
+ #
80
+ def to_s
81
+ ""
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,87 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "version/null_version"
4
+
5
+ module ConvenientService
6
+ module Dependencies
7
+ module Queries
8
+ class Version
9
+ include ::Comparable
10
+
11
+ undef_method :between?
12
+
13
+ undef_method :clamp
14
+
15
+ ##
16
+ # @param value [String]
17
+ # @return [void]
18
+ #
19
+ def initialize(value)
20
+ @value = value
21
+ end
22
+
23
+ class << self
24
+ ##
25
+ # @return [ConvenientService::Dependencies::Queries::Version::NullVersion]
26
+ #
27
+ def null_version
28
+ @null_version ||= Version::NullVersion.new
29
+ end
30
+ end
31
+
32
+ ##
33
+ # @return [Boolean]
34
+ #
35
+ def null_version?
36
+ false
37
+ end
38
+
39
+ ##
40
+ # @return [Gem::Version, nil]
41
+ #
42
+ def gem_version
43
+ cast_gem_version(value)
44
+ end
45
+
46
+ ##
47
+ # @return [String]
48
+ #
49
+ # @internal
50
+ # TODO: Add direct specs.
51
+ #
52
+ def major_minor
53
+ to_s[/\d+\.\d+/]
54
+ end
55
+
56
+ ##
57
+ # @param other [Object] Can be any type.
58
+ # @return [Boolean, nil]
59
+ #
60
+ def <=>(other)
61
+ gem_version <=> cast_gem_version(other)
62
+ end
63
+
64
+ ##
65
+ # @return [String]
66
+ #
67
+ def to_s
68
+ gem_version.to_s
69
+ end
70
+
71
+ private
72
+
73
+ ##
74
+ # @return [String]
75
+ #
76
+ attr_reader :value
77
+
78
+ ##
79
+ # @return [Gem::Version, nil]
80
+ #
81
+ def cast_gem_version(value)
82
+ ::Gem::Version.create(value.to_s) if ::Gem::Version.correct?(value.to_s)
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end