convenient_service 0.20.0 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +8 -4
  3. data/lib/convenient_service/aliases.rb +113 -1
  4. data/lib/convenient_service/common/plugins/aliases.rb +69 -0
  5. data/lib/convenient_service/common/plugins/can_have_callbacks/entities/type_collection.rb +2 -2
  6. data/lib/convenient_service/common/plugins/has_instance_proxy/entities/instance_proxy.rb +8 -8
  7. data/lib/convenient_service/common.rb +14 -0
  8. data/lib/convenient_service/config.rb +8 -0
  9. data/lib/convenient_service/core/aliases.rb +84 -0
  10. data/lib/convenient_service/dependencies/built_in.rb +15 -1
  11. data/lib/convenient_service/dependencies/only_queries.rb +0 -6
  12. data/lib/convenient_service/dependencies/queries/gems/minitest.rb +55 -0
  13. data/lib/convenient_service/dependencies/queries/gems/rspec.rb +1 -1
  14. data/lib/convenient_service/dependencies/queries/gems.rb +2 -0
  15. data/lib/convenient_service/dependencies/queries/ruby.rb +2 -2
  16. data/lib/convenient_service/dependencies/queries.rb +67 -16
  17. data/lib/convenient_service/dependencies.rb +6 -6
  18. data/lib/convenient_service/extras/alias.rb +4 -1
  19. data/lib/convenient_service/feature/configs/standard.rb +34 -13
  20. data/lib/convenient_service/feature/core.rb +41 -0
  21. data/lib/convenient_service/feature/plugins/aliases.rb +29 -0
  22. data/lib/convenient_service/feature/plugins/can_have_rspec_stubbed_entries/concern.rb +34 -0
  23. data/lib/convenient_service/{rspec/helpers/classes/stub_entry/entities.rb → feature/plugins/can_have_rspec_stubbed_entries.rb} +1 -2
  24. data/lib/convenient_service/feature/plugins/can_have_stubbed_entries/commands/delete_feature_stubbed_entry.rb +71 -0
  25. data/lib/convenient_service/feature/plugins/can_have_stubbed_entries/commands/fetch_all_features_stubbed_entries_cache.rb +16 -2
  26. data/lib/convenient_service/feature/plugins/can_have_stubbed_entries/commands/fetch_feature_stubbed_entries_cache.rb +1 -1
  27. data/lib/convenient_service/feature/plugins/can_have_stubbed_entries/commands.rb +2 -0
  28. data/lib/convenient_service/feature/plugins/can_have_stubbed_entries/concern.rb +23 -0
  29. data/lib/convenient_service/feature/plugins/can_have_stubbed_entries/entities/feature_stub.rb +123 -0
  30. data/lib/convenient_service/feature/plugins/can_have_stubbed_entries/entities/feature_unstub.rb +122 -0
  31. data/lib/convenient_service/feature/plugins/can_have_stubbed_entries/entities/value_mock.rb +118 -0
  32. data/lib/convenient_service/feature/plugins/can_have_stubbed_entries/entities/value_unmock.rb +88 -0
  33. data/lib/convenient_service/feature/plugins/can_have_stubbed_entries/entities.rb +12 -0
  34. data/lib/convenient_service/feature/plugins/can_have_stubbed_entries.rb +1 -14
  35. data/lib/convenient_service/feature/plugins/has_amazing_print_inspect/concern.rb +34 -0
  36. data/lib/convenient_service/feature/{configs/standard/commands.rb → plugins/has_amazing_print_inspect.rb} +1 -2
  37. data/lib/convenient_service/feature/plugins/has_awesome_print_inspect/concern.rb +34 -0
  38. data/lib/convenient_service/{rspec/helpers/classes/stub_service/entities.rb → feature/plugins/has_awesome_print_inspect.rb} +1 -2
  39. data/lib/convenient_service/feature/plugins/has_inspect/concern.rb +27 -0
  40. data/lib/convenient_service/{service/configs/standard/commands.rb → feature/plugins/has_inspect.rb} +1 -2
  41. data/lib/convenient_service/feature/plugins.rb +1 -0
  42. data/lib/convenient_service/feature.rb +16 -0
  43. data/lib/convenient_service/logger.rb +11 -12
  44. data/lib/convenient_service/rspec/helpers/classes.rb +0 -2
  45. data/lib/convenient_service/rspec/helpers/stub_entry.rb +23 -5
  46. data/lib/convenient_service/rspec/helpers/stub_service.rb +79 -11
  47. data/lib/convenient_service/rspec/matchers/classes/cache_its_value.rb +2 -1
  48. data/lib/convenient_service/rspec/matchers/classes/delegate_to.rb +3 -5
  49. data/lib/convenient_service/rspec/matchers/classes/include_config.rb +4 -0
  50. data/lib/convenient_service/service/configs/aliases.rb +42 -0
  51. data/lib/convenient_service/service/configs/standard/aliases.rb +24 -0
  52. data/lib/convenient_service/service/configs/standard/v1.rb +17 -0
  53. data/lib/convenient_service/service/configs/standard.rb +50 -25
  54. data/lib/convenient_service/service/core.rb +39 -0
  55. data/lib/convenient_service/service/plugins/aliases.rb +48 -0
  56. data/lib/convenient_service/service/plugins/can_have_rollbacks/middleware.rb +33 -2
  57. data/lib/convenient_service/service/plugins/can_have_rspec_stubbed_results/concern.rb +34 -0
  58. data/lib/convenient_service/service/plugins/can_have_rspec_stubbed_results.rb +8 -0
  59. data/lib/convenient_service/service/plugins/can_have_stubbed_results/commands/delete_service_stubbed_result.rb +63 -0
  60. data/lib/convenient_service/service/plugins/can_have_stubbed_results/commands/fetch_all_services_stubbed_results_cache.rb +15 -10
  61. data/lib/convenient_service/service/plugins/can_have_stubbed_results/commands/fetch_service_stubbed_results_cache.rb +3 -3
  62. data/lib/convenient_service/service/plugins/can_have_stubbed_results/commands.rb +2 -0
  63. data/lib/convenient_service/service/plugins/can_have_stubbed_results/concern.rb +25 -0
  64. data/lib/convenient_service/service/plugins/can_have_stubbed_results/entities/result_mock.rb +254 -0
  65. data/lib/convenient_service/service/plugins/can_have_stubbed_results/entities/result_unmock.rb +82 -0
  66. data/lib/convenient_service/service/plugins/can_have_stubbed_results/entities/service_stub.rb +135 -0
  67. data/lib/convenient_service/service/plugins/can_have_stubbed_results/entities/service_unstub.rb +113 -0
  68. data/lib/convenient_service/service/plugins/can_have_stubbed_results/entities.rb +12 -0
  69. data/lib/convenient_service/service/plugins/can_have_stubbed_results.rb +1 -14
  70. data/lib/convenient_service/service/plugins/forbids_convenient_service_entities_as_constructor_arguments/exceptions.rb +84 -0
  71. data/lib/convenient_service/service/plugins/forbids_convenient_service_entities_as_constructor_arguments/middleware.rb +84 -32
  72. data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/concern.rb +42 -2
  73. data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/can_be_called/exceptions.rb +3 -2
  74. 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 +5 -0
  75. data/lib/convenient_service/service.rb +16 -0
  76. data/lib/convenient_service/specification.rb +42 -12
  77. data/lib/convenient_service/support/backtrace_cleaner.rb +6 -7
  78. data/lib/convenient_service/support/middleware/stack_builder/entities/builders/custom.rb +4 -0
  79. data/lib/convenient_service/support/middleware/stack_builder/entities/builders/ruby_middleware.rb +4 -0
  80. data/lib/convenient_service/support/unique_value.rb +4 -1
  81. data/lib/convenient_service/support.rb +13 -0
  82. data/lib/convenient_service/utils/array/find_last.rb +18 -9
  83. data/lib/convenient_service/utils/class/display_name.rb +9 -9
  84. data/lib/convenient_service/utils/enumerable/find_last.rb +48 -0
  85. data/lib/convenient_service/utils/enumerable.rb +20 -0
  86. data/lib/convenient_service/utils/hash/assert_valid_keys.rb +4 -4
  87. data/lib/convenient_service/utils/hash/except.rb +5 -4
  88. data/lib/convenient_service/utils/hash/triple_equality_compare.rb +8 -8
  89. data/lib/convenient_service/utils/kernel/silence_warnings.rb +4 -4
  90. data/lib/convenient_service/utils/module/fetch_own_const.rb +36 -31
  91. data/lib/convenient_service/utils/module/get_namespace.rb +26 -21
  92. data/lib/convenient_service/utils/module/get_own_const.rb +21 -16
  93. data/lib/convenient_service/utils/object/clamp_class.rb +50 -47
  94. data/lib/convenient_service/utils/object/duck_class.rb +84 -81
  95. data/lib/convenient_service/utils/object/get_own_method.rb +1 -1
  96. data/lib/convenient_service/utils/object/instance_variable_delete.rb +0 -3
  97. data/lib/convenient_service/utils/object/instance_variable_fetch.rb +0 -3
  98. data/lib/convenient_service/utils/object/memoize_including_falsy_values.rb +0 -3
  99. data/lib/convenient_service/utils/object/resolve_type.rb +13 -11
  100. data/lib/convenient_service/utils/object/safe_send.rb +2 -0
  101. data/lib/convenient_service/utils/string/enclose.rb +11 -11
  102. data/lib/convenient_service/utils/string/tab.rb +60 -0
  103. data/lib/convenient_service/utils/string.rb +5 -0
  104. data/lib/convenient_service/utils.rb +9 -0
  105. data/lib/convenient_service/version.rb +8 -1
  106. data/lib/convenient_service.rb +232 -14
  107. metadata +37 -754
  108. data/lib/convenient_service/feature/configs/standard/commands/is_feature.rb +0 -39
  109. data/lib/convenient_service/feature/configs/standard/commands/is_feature_class.rb +0 -41
  110. data/lib/convenient_service/rspec/helpers/classes/stub_entry/constants.rb +0 -25
  111. data/lib/convenient_service/rspec/helpers/classes/stub_entry/entities/stubbed_feature.rb +0 -128
  112. data/lib/convenient_service/rspec/helpers/classes/stub_entry/entities/value_spec.rb +0 -79
  113. data/lib/convenient_service/rspec/helpers/classes/stub_entry.rb +0 -48
  114. data/lib/convenient_service/rspec/helpers/classes/stub_service/constants.rb +0 -25
  115. data/lib/convenient_service/rspec/helpers/classes/stub_service/entities/result_spec.rb +0 -211
  116. data/lib/convenient_service/rspec/helpers/classes/stub_service/entities/stubbed_service.rb +0 -119
  117. data/lib/convenient_service/rspec/helpers/classes/stub_service.rb +0 -43
  118. data/lib/convenient_service/service/configs/standard/commands/is_service.rb +0 -39
  119. data/lib/convenient_service/service/configs/standard/commands/is_service_class.rb +0 -41
@@ -5,91 +5,94 @@
5
5
  # @license LGPLv3 <https://www.gnu.org/licenses/lgpl-3.0.html>
6
6
  ##
7
7
 
8
- ##
9
- # Converts an object to a "duck" class in terms of `Module#method_defined?` or `Module#define_method`.
10
- #
11
- # @example Avoid `if` condition for `Module#method_defined?`.
12
- #
13
- # object = Person.new # || Person
14
- #
15
- # if object.is_a?(Module)
16
- # ##
17
- # # class Person
18
- # # def self.foo
19
- # # end
20
- # # end
21
- # #
22
- # # Does `Person` has class method `foo`?
23
- # #
24
- # object.singleton_class.method_defined?(:foo)
25
- # else
26
- # ##
27
- # # class Person
28
- # # def foo
29
- # # end
30
- # # end
31
- # #
32
- # # Does `Person` has instance method `foo`?
33
- # #
34
- # object.class.method_defined?(:foo)
35
- # end
36
- #
37
- # ##
38
- # # With `ConvenientService::Utils::Object.duck_class` it can be rewritten in the following way:
39
- # #
40
- # ConvenientService::Utils::Object.duck_class(object).method_defined?(:foo)
41
- #
42
- # @example Avoid `if` condition for `Module#define_method`.
43
- #
44
- # object = Person.new # || Person
45
- #
46
- # if object.is_a?(Module)
47
- # ##
48
- # # Defines class method `foo` in `Person` class.
49
- # #
50
- # object.singleton_class.define_method(:foo) { :bar }
51
- # else
52
- # ##
53
- # # Defines instance method `foo` in `Person` class.
54
- # #
55
- # object.class.define_method(:foo) { :bar }
56
- # end
57
- #
58
- # ##
59
- # # With `ConvenientService::Utils::Object.duck_class` it can be rewritten in the following way:
60
- # #
61
- # ConvenientService::Utils::Object.duck_class(object).define_method(:foo) { :bar }
62
- #
63
- # @example Possible return values.
64
- #
65
- # module Musician
66
- # end
67
- #
68
- # class Person
69
- # end
70
- #
71
- # person = Person.new
72
- #
73
- # ConvenientService::Utils::Object::DuckClass.call(42)
74
- # # => Integer
75
- #
76
- # ConvenientService::Utils::Object::DuckClass.call("foo")
77
- # # => String
78
- #
79
- # ConvenientService::Utils::Object::DuckClass.call(person)
80
- # # => Person
81
- #
82
- # ConvenientService::Utils::Object::DuckClass.call(Person)
83
- # # => #<Class:Person>
84
- #
85
- # ConvenientService::Utils::Object::DuckClass.call(Musician)
86
- # # => #<Class:Musician>
87
- #
88
8
  module ConvenientService
89
9
  module Utils
90
10
  module Object
91
11
  ##
92
- # TODO: A better name.
12
+ # Converts an object to a "duck" class in terms of `Module#method_defined?` or `Module#define_method`.
13
+ #
14
+ # @api private
15
+ # @since 1.0.0
16
+ #
17
+ # @example Avoid `if` condition for `Module#method_defined?`.
18
+ #
19
+ # object = Person.new # || Person
20
+ #
21
+ # if object.is_a?(Module)
22
+ # ##
23
+ # # class Person
24
+ # # def self.foo
25
+ # # end
26
+ # # end
27
+ # #
28
+ # # Does `Person` has class method `foo`?
29
+ # #
30
+ # object.singleton_class.method_defined?(:foo)
31
+ # else
32
+ # ##
33
+ # # class Person
34
+ # # def foo
35
+ # # end
36
+ # # end
37
+ # #
38
+ # # Does `Person` has instance method `foo`?
39
+ # #
40
+ # object.class.method_defined?(:foo)
41
+ # end
42
+ #
43
+ # ##
44
+ # # With `ConvenientService::Utils::Object.duck_class` it can be rewritten in the following way:
45
+ # #
46
+ # ConvenientService::Utils::Object.duck_class(object).method_defined?(:foo)
47
+ #
48
+ # @example Avoid `if` condition for `Module#define_method`.
49
+ #
50
+ # object = Person.new # || Person
51
+ #
52
+ # if object.is_a?(Module)
53
+ # ##
54
+ # # Defines class method `foo` in `Person` class.
55
+ # #
56
+ # object.singleton_class.define_method(:foo) { :bar }
57
+ # else
58
+ # ##
59
+ # # Defines instance method `foo` in `Person` class.
60
+ # #
61
+ # object.class.define_method(:foo) { :bar }
62
+ # end
63
+ #
64
+ # ##
65
+ # # With `ConvenientService::Utils::Object.duck_class` it can be rewritten in the following way:
66
+ # #
67
+ # ConvenientService::Utils::Object.duck_class(object).define_method(:foo) { :bar }
68
+ #
69
+ # @example Possible return values.
70
+ #
71
+ # module Musician
72
+ # end
73
+ #
74
+ # class Person
75
+ # end
76
+ #
77
+ # person = Person.new
78
+ #
79
+ # ConvenientService::Utils::Object::DuckClass.call(42)
80
+ # # => Integer
81
+ #
82
+ # ConvenientService::Utils::Object::DuckClass.call("foo")
83
+ # # => String
84
+ #
85
+ # ConvenientService::Utils::Object::DuckClass.call(person)
86
+ # # => Person
87
+ #
88
+ # ConvenientService::Utils::Object::DuckClass.call(Person)
89
+ # # => #<Class:Person>
90
+ #
91
+ # ConvenientService::Utils::Object::DuckClass.call(Musician)
92
+ # # => #<Class:Musician>
93
+ #
94
+ # @internal
95
+ # TODO: A better name.
93
96
  #
94
97
  class DuckClass < Support::Command
95
98
  ##
@@ -39,7 +39,7 @@ module ConvenientService
39
39
  end
40
40
 
41
41
  ##
42
- # @return [Class]
42
+ # @return [Method]
43
43
  #
44
44
  # @internal
45
45
  # NOTE: `own_method.bind(object).call` is logically the same as `own_method.bind_call(object)`.
@@ -5,9 +5,6 @@
5
5
  # @license LGPLv3 <https://www.gnu.org/licenses/lgpl-3.0.html>
6
6
  ##
7
7
 
8
- ##
9
- #
10
- #
11
8
  module ConvenientService
12
9
  module Utils
13
10
  module Object
@@ -5,9 +5,6 @@
5
5
  # @license LGPLv3 <https://www.gnu.org/licenses/lgpl-3.0.html>
6
6
  ##
7
7
 
8
- ##
9
- #
10
- #
11
8
  module ConvenientService
12
9
  module Utils
13
10
  module Object
@@ -5,9 +5,6 @@
5
5
  # @license LGPLv3 <https://www.gnu.org/licenses/lgpl-3.0.html>
6
6
  ##
7
7
 
8
- ##
9
- #
10
- #
11
8
  module ConvenientService
12
9
  module Utils
13
10
  module Object
@@ -5,20 +5,22 @@
5
5
  # @license LGPLv3 <https://www.gnu.org/licenses/lgpl-3.0.html>
6
6
  ##
7
7
 
8
- ##
9
- # @example
10
- # ConvenientService::Utils::Object::ResolveType.call("foo")
11
- # # => "instance"
12
- #
13
- # ConvenientService::Utils::Object::ResolveType.call(Array)
14
- # # => "class"
15
- #
16
- # ConvenientService::Utils::Object::ResolveType.call(Kernel)
17
- # # => "module"
18
- #
19
8
  module ConvenientService
20
9
  module Utils
21
10
  module Object
11
+ ##
12
+ # @api private
13
+ # @since 1.0.0
14
+ # @example Common usage.
15
+ # ConvenientService::Utils::Object::ResolveType.call("foo")
16
+ # # => "instance"
17
+ #
18
+ # ConvenientService::Utils::Object::ResolveType.call(Array)
19
+ # # => "class"
20
+ #
21
+ # ConvenientService::Utils::Object::ResolveType.call(Kernel)
22
+ # # => "module"
23
+ #
22
24
  class ResolveType < Support::Command
23
25
  ##
24
26
  # @!attribute [r] object
@@ -70,6 +70,8 @@ module ConvenientService
70
70
  ##
71
71
  # @return [Object] Can be any type.
72
72
  #
73
+ # @note `SafeSend` is similar to `JSON::SafeParse` in a sense that it never raises exceptions.
74
+ #
73
75
  # @internal
74
76
  # NOTE: `true` in `respond_to?(method, true)` means to look for protected and private methods as well.
75
77
  # - https://ruby-doc.org/core-2.7.0/Object.html#method-i-respond_to-3F
@@ -5,20 +5,20 @@
5
5
  # @license LGPLv3 <https://www.gnu.org/licenses/lgpl-3.0.html>
6
6
  ##
7
7
 
8
- ##
9
- # @example Common usage.
10
- # ConvenientService::Utils::String::Enclose.call("foo", "_")
11
- # # => "_foo_"
12
- #
13
- # ConvenientService::Utils::String::Enclose.call("", "_")
14
- # # => "_"
15
- #
16
- # ConvenientService::Utils::String::Enclose.call(nil, "_")
17
- # # => "_"
18
- #
19
8
  module ConvenientService
20
9
  module Utils
21
10
  module String
11
+ ##
12
+ # @example Common usage.
13
+ # ConvenientService::Utils::String::Enclose.call("foo", "_")
14
+ # # => "_foo_"
15
+ #
16
+ # ConvenientService::Utils::String::Enclose.call("", "_")
17
+ # # => "_"
18
+ #
19
+ # ConvenientService::Utils::String::Enclose.call(nil, "_")
20
+ # # => "_"
21
+ #
22
22
  class Enclose < Support::Command
23
23
  ##
24
24
  # @!attribute [r] string
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ ##
4
+ # @author Marian Kostyk <mariankostyk13895@gmail.com>
5
+ # @license LGPLv3 <https://www.gnu.org/licenses/lgpl-3.0.html>
6
+ ##
7
+
8
+ module ConvenientService
9
+ module Utils
10
+ module String
11
+ ##
12
+ # @example Common usage.
13
+ # ConvenientService::Utils::String::Tab.call("foo\nbar\nbaz")
14
+ # # => " foo\n bar\n baz"
15
+ #
16
+ # ConvenientService::Utils::String::Tab.call("foo\nbar\nbaz", tab_size: 4)
17
+ # # => " foo\n bar\n baz"
18
+ #
19
+ class Tab < Support::Command
20
+ ##
21
+ # @!attribute [r] string
22
+ # @return [String]
23
+ #
24
+ attr_reader :string
25
+
26
+ ##
27
+ # @!attribute [r] tab_size
28
+ # @return [Integer]
29
+ #
30
+ attr_reader :tab_size
31
+
32
+ ##
33
+ # @param string [String]
34
+ # @param tab_size [Integer]
35
+ # @return [void]
36
+ #
37
+ def initialize(string, tab_size: 2)
38
+ @string = string.to_s
39
+ @tab_size = tab_size
40
+ end
41
+
42
+ ##
43
+ # @return [String]
44
+ #
45
+ def call
46
+ string.lines.map { |line| "#{tab}#{line}" }.join
47
+ end
48
+
49
+ private
50
+
51
+ ##
52
+ # @return [String]
53
+ #
54
+ def tab
55
+ @tab ||= " " * tab_size
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -9,6 +9,7 @@ require_relative "string/camelize"
9
9
  require_relative "string/demodulize"
10
10
  require_relative "string/enclose"
11
11
  require_relative "string/split"
12
+ require_relative "string/tab"
12
13
  require_relative "string/truncate"
13
14
 
14
15
  module ConvenientService
@@ -27,6 +28,10 @@ module ConvenientService
27
28
  Enclose.call(...)
28
29
  end
29
30
 
31
+ def tab(...)
32
+ Tab.call(...)
33
+ end
34
+
30
35
  def split(...)
31
36
  Split.call(...)
32
37
  end
@@ -8,6 +8,7 @@
8
8
  require_relative "utils/array"
9
9
  require_relative "utils/bool"
10
10
  require_relative "utils/class"
11
+ require_relative "utils/enumerable"
11
12
  require_relative "utils/hash"
12
13
  require_relative "utils/kernel"
13
14
  require_relative "utils/method"
@@ -17,6 +18,14 @@ require_relative "utils/string"
17
18
  require_relative "utils/object"
18
19
 
19
20
  module ConvenientService
21
+ ##
22
+ # Namespace for Convenient Service utilities that can be expressed as "functions".
23
+ #
24
+ # @api private
25
+ # @since 1.0.0
26
+ # @note Utilities from the `Utils` module are NOT expected to be used by the end-users directly.
27
+ # @note Plugin developers usually can rely on the `Utils` module, but it is always a good idea to open an issue with the corresponding usage example. This way, the custom plugin may be added to the CI pipeline. So that any breaking change is caught before the new Convenient Service release.
28
+ #
20
29
  module Utils
21
30
  class << self
22
31
  ##
@@ -6,5 +6,12 @@
6
6
  ##
7
7
 
8
8
  module ConvenientService
9
- VERSION = "0.20.0"
9
+ ##
10
+ # Returns current Convenient Service version.
11
+ #
12
+ # @api public
13
+ # @since 1.0.0
14
+ # @return [String]
15
+ #
16
+ VERSION = "0.21.0"
10
17
  end