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
@@ -54,10 +54,13 @@ module ConvenientService
54
54
  # - https://github.com/ruby/ruby/blob/v3_3_0/hash.c#L3719
55
55
  # - https://belighted.com/blog/overriding-equals-equals
56
56
  #
57
+ # NOTE: Avoid comparing object ids. Prefer `equal?`.
58
+ # - https://bugs.ruby-lang.org/issues/15408
59
+ #
57
60
  def eql?(other)
58
61
  return unless other.instance_of?(self.class)
59
62
 
60
- object_id == other.object_id
63
+ equal?(other)
61
64
  end
62
65
 
63
66
  ##
@@ -30,3 +30,16 @@ require_relative "support/middleware"
30
30
  require_relative "support/raw_value"
31
31
  require_relative "support/safe_method"
32
32
  require_relative "support/thread_safe_counter"
33
+
34
+ module ConvenientService
35
+ ##
36
+ # Namespace for Convenient Service utilities that can NOT be expressed as "functions".
37
+ #
38
+ # @api private
39
+ # @since 1.0.0
40
+ # @note Utilities from the `Support` module are NOT expected to be used by the end-users directly, but they still may interact with them when the `Support` instances are returned from the Convenient Service public methods.
41
+ # @note Plugin developers usually can rely on the `Support` 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.
42
+ #
43
+ module Support
44
+ end
45
+ end
@@ -31,16 +31,25 @@ module ConvenientService
31
31
  @block = block
32
32
  end
33
33
 
34
- ##
35
- # @return [Object] Can be any type.
36
- #
37
- # @note Works with custom `Enumerable` objects.
38
- # @see https://ruby-doc.org/core-2.7.0/Enumerable.html
39
- #
40
- def call
41
- array.reverse_each { |item| return item if block.call(item) }
34
+ if Dependencies.ruby.version >= 4.0
35
+ ##
36
+ # @return [Object] Can be any type.
37
+ #
38
+ # @note Does NOT work with custom `Enumerable` objects.
39
+ # @note Use `ConvenientService::Utils::Enumerable.find_last` for custom enumerables.
40
+ #
41
+ def call
42
+ array.rfind(&block)
43
+ end
44
+ else
45
+ ##
46
+ # @return [Object] Can be any type.
47
+ #
48
+ def call
49
+ array.reverse_each { |item| return item if block.call(item) }
42
50
 
43
- nil
51
+ nil
52
+ end
44
53
  end
45
54
  end
46
55
  end
@@ -5,18 +5,18 @@
5
5
  # @license LGPLv3 <https://www.gnu.org/licenses/lgpl-3.0.html>
6
6
  ##
7
7
 
8
- ##
9
- # @example Usual class.
10
- # ConvenientService::Utils::Class::DisplayName.call(String)
11
- # # => "String"
12
- #
13
- # @example Anonymous class.
14
- # ConvenientService::Utils::Class::DisplayName.call(Сlass.new)
15
- # # => "AnonymousClass(#76940)"
16
- #
17
8
  module ConvenientService
18
9
  module Utils
19
10
  module Class
11
+ ##
12
+ # @example Usual class.
13
+ # ConvenientService::Utils::Class::DisplayName.call(String)
14
+ # # => "String"
15
+ #
16
+ # @example Anonymous class.
17
+ # ConvenientService::Utils::Class::DisplayName.call(Сlass.new)
18
+ # # => "AnonymousClass(#76940)"
19
+ #
20
20
  class DisplayName < Support::Command
21
21
  ##
22
22
  # @api private
@@ -0,0 +1,48 @@
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 Enumerable
11
+ class FindLast < Support::Command
12
+ ##
13
+ # @!attribute [r] enumerable
14
+ # @return [Enumerable]
15
+ #
16
+ attr_reader :enumerable
17
+
18
+ ##
19
+ # @!attribute [r] block
20
+ # @return [Proc]
21
+ #
22
+ attr_reader :block
23
+
24
+ ##
25
+ # @param enumerable [Enumerable]
26
+ # @param block [Proc, nil]
27
+ # @return [void]
28
+ #
29
+ def initialize(enumerable, &block)
30
+ @enumerable = enumerable
31
+ @block = block
32
+ end
33
+
34
+ ##
35
+ # @return [Object] Can be any type.
36
+ #
37
+ # @note Works with custom `Enumerable` objects.
38
+ # @see https://ruby-doc.org/core-2.7.0/Enumerable.html
39
+ #
40
+ def call
41
+ enumerable.reverse_each { |item| return item if block.call(item) }
42
+
43
+ nil
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,20 @@
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
+ require_relative "enumerable/find_last"
9
+
10
+ module ConvenientService
11
+ module Utils
12
+ module Enumerable
13
+ class << self
14
+ def find_last(...)
15
+ FindLast.call(...)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -5,13 +5,13 @@
5
5
  # @license LGPLv3 <https://www.gnu.org/licenses/lgpl-3.0.html>
6
6
  ##
7
7
 
8
- ##
9
- # @example
10
- # ConvenientService::Utils::Hash::AssertValidKeys.call({foo: "foo", bar: "bar"}, [:foo, :bar])
11
- #
12
8
  module ConvenientService
13
9
  module Utils
14
10
  module Hash
11
+ ##
12
+ # @example Common usage.
13
+ # ConvenientService::Utils::Hash::AssertValidKeys.call({foo: "foo", bar: "bar"}, [:foo, :bar])
14
+ #
15
15
  class AssertValidKeys < Support::Command
16
16
  ##
17
17
  # @!attribute [r] hash
@@ -5,13 +5,14 @@
5
5
  # @license LGPLv3 <https://www.gnu.org/licenses/lgpl-3.0.html>
6
6
  ##
7
7
 
8
- ##
9
- # @example
10
- # ConvenientService::Utils::Hash::Except.call({foo: :bar, baz: :qux}, [:foo])
11
- #
12
8
  module ConvenientService
13
9
  module Utils
14
10
  module Hash
11
+ ##
12
+ # @example Common usage.
13
+ # ConvenientService::Utils::Hash::Except.call({foo: :bar, baz: :qux}, [:foo])
14
+ # # => {baz: :qux}
15
+ #
15
16
  class Except < Support::Command
16
17
  ##
17
18
  # @!attribute [r] hash
@@ -5,17 +5,17 @@
5
5
  # @license LGPLv3 <https://www.gnu.org/licenses/lgpl-3.0.html>
6
6
  ##
7
7
 
8
- ##
9
- # @example
10
- # {foo: (1..10), bar: /abc/} == {foo: 5, bar: :abc}
11
- # # => false, since values are compared by `#==` under the hood.
12
- #
13
- # ConvenientService::Utils::Hash::TripleEqualityCompare.call({foo: (1..10), bar: /abc/}, {foo: 5, bar: :abc})
14
- # # => true, since values are compared by `#===` under the hood.
15
- #
16
8
  module ConvenientService
17
9
  module Utils
18
10
  module Hash
11
+ ##
12
+ # @example Common usage.
13
+ # {foo: (1..10), bar: /abc/} == {foo: 5, bar: :abc}
14
+ # # => false, since values are compared by `#==` under the hood.
15
+ #
16
+ # ConvenientService::Utils::Hash::TripleEqualityCompare.call({foo: (1..10), bar: /abc/}, {foo: 5, bar: :abc})
17
+ # # => true, since values are compared by `#===` under the hood.
18
+ #
19
19
  class TripleEqualityCompare < Support::Command
20
20
  ##
21
21
  # @!attribute [r] hash
@@ -5,13 +5,13 @@
5
5
  # @license LGPLv3 <https://www.gnu.org/licenses/lgpl-3.0.html>
6
6
  ##
7
7
 
8
- ##
9
- # @example
10
- # ConvenientService::Utils::Kernel::SilenceWarnings.call { String = String }
11
- #
12
8
  module ConvenientService
13
9
  module Utils
14
10
  module Kernel
11
+ ##
12
+ # @example Common usage.
13
+ # ConvenientService::Utils::Kernel::SilenceWarnings.call { String = String }
14
+ #
15
15
  class SilenceWarnings < Support::Command
16
16
  ##
17
17
  # @!attribute [r] block
@@ -5,40 +5,45 @@
5
5
  # @license LGPLv3 <https://www.gnu.org/licenses/lgpl-3.0.html>
6
6
  ##
7
7
 
8
- ##
9
- # @example Two args form (works as GetOwnConst).
10
- # module Test
11
- # end
12
- #
13
- # ConvenientService::Utils::Module::FetchOwnConst.call(Test, :File)
14
- # # => nil, not File from Ruby Core.
15
- #
16
- # module Test
17
- # class File
18
- # end
19
- # end
20
- #
21
- # ConvenientService::Utils::Module::FetchOwnConst.call(Test, :File)
22
- # # => Test::File
23
- #
24
- # @example Two args + block form.
25
- # module Test
26
- # end
27
- #
28
- # ConvenientService::Utils::Module::FetchOwnConst.call(Test, :File) { Class.new }
29
- # # => Test::File, just created.
30
- #
31
- # module Test
32
- # class File
33
- # end
34
- # end
35
- #
36
- # ConvenientService::Utils::Module::FetchOwnConst.call(Test, :File)
37
- # # => Test::File, already existing.
38
- #
39
8
  module ConvenientService
40
9
  module Utils
41
10
  module Module
11
+ ##
12
+ # Returns a constant that is defined directly in module or defines it there.
13
+ #
14
+ # @api private
15
+ # @since 1.0.0
16
+ #
17
+ # @example Two args form (works as GetOwnConst).
18
+ # module Test
19
+ # end
20
+ #
21
+ # ConvenientService::Utils::Module::FetchOwnConst.call(Test, :File)
22
+ # # => nil, not File from Ruby Core.
23
+ #
24
+ # module Test
25
+ # class File
26
+ # end
27
+ # end
28
+ #
29
+ # ConvenientService::Utils::Module::FetchOwnConst.call(Test, :File)
30
+ # # => Test::File
31
+ #
32
+ # @example Two args + block form.
33
+ # module Test
34
+ # end
35
+ #
36
+ # ConvenientService::Utils::Module::FetchOwnConst.call(Test, :File) { Class.new }
37
+ # # => Test::File, just created.
38
+ #
39
+ # module Test
40
+ # class File
41
+ # end
42
+ # end
43
+ #
44
+ # ConvenientService::Utils::Module::FetchOwnConst.call(Test, :File)
45
+ # # => Test::File, already existing.
46
+ #
42
47
  class FetchOwnConst < Support::Command
43
48
  ##
44
49
  # @!attribute [r] mod
@@ -5,30 +5,35 @@
5
5
  # @license LGPLv3 <https://www.gnu.org/licenses/lgpl-3.0.html>
6
6
  ##
7
7
 
8
- ##
9
- # @example
10
- # module Foo
11
- # module Bar
12
- # class Baz
13
- # end
14
- # end
15
- # end
16
- #
17
- # ConvenientService::Utils::Module::GetNamespace.call(Foo)
18
- # # => nil
19
- #
20
- # ConvenientService::Utils::Module::GetNamespace.call(Foo::Bar)
21
- # # => Foo
22
- #
23
- # ConvenientService::Utils::Module::GetNamespace.call(Foo::Bar::Baz)
24
- # # => Foo::Bar
25
- #
26
- # ConvenientService::Utils::Module::GetNamespace.call(Module.new)
27
- # # => nil
28
- #
29
8
  module ConvenientService
30
9
  module Utils
31
10
  module Module
11
+ ##
12
+ # Returns parent namespace of class or module.
13
+ #
14
+ # @api private
15
+ # @since 1.0.0
16
+ #
17
+ # @example Common usage.
18
+ # module Foo
19
+ # module Bar
20
+ # class Baz
21
+ # end
22
+ # end
23
+ # end
24
+ #
25
+ # ConvenientService::Utils::Module::GetNamespace.call(Foo)
26
+ # # => nil
27
+ #
28
+ # ConvenientService::Utils::Module::GetNamespace.call(Foo::Bar)
29
+ # # => Foo
30
+ #
31
+ # ConvenientService::Utils::Module::GetNamespace.call(Foo::Bar::Baz)
32
+ # # => Foo::Bar
33
+ #
34
+ # ConvenientService::Utils::Module::GetNamespace.call(Module.new)
35
+ # # => nil
36
+ #
32
37
  class GetNamespace < Support::Command
33
38
  ##
34
39
  # @!attribute [r] mod
@@ -5,25 +5,30 @@
5
5
  # @license LGPLv3 <https://www.gnu.org/licenses/lgpl-3.0.html>
6
6
  ##
7
7
 
8
- ##
9
- # @example
10
- # module Test
11
- # end
12
- #
13
- # ConvenientService::Utils::Module::GetOwnConst.call(Test, :File)
14
- # # => nil, not File from Ruby Core.
15
- #
16
- # module Test
17
- # class File
18
- # end
19
- # end
20
- #
21
- # ConvenientService::Utils::Module::GetOwnConst.call(Test, :File)
22
- # # => Test::File
23
- #
24
8
  module ConvenientService
25
9
  module Utils
26
10
  module Module
11
+ ##
12
+ # Returns constant defined directly in `mod`.
13
+ #
14
+ # @api private
15
+ # @since 1.0.0
16
+ #
17
+ # @example Common usage.
18
+ # module Test
19
+ # end
20
+ #
21
+ # ConvenientService::Utils::Module::GetOwnConst.call(Test, :File)
22
+ # # => nil, not File from Ruby Core.
23
+ #
24
+ # module Test
25
+ # class File
26
+ # end
27
+ # end
28
+ #
29
+ # ConvenientService::Utils::Module::GetOwnConst.call(Test, :File)
30
+ # # => Test::File
31
+ #
27
32
  class GetOwnConst < Support::Command
28
33
  ##
29
34
  # @!attribute [r] mod
@@ -5,56 +5,59 @@
5
5
  # @license LGPLv3 <https://www.gnu.org/licenses/lgpl-3.0.html>
6
6
  ##
7
7
 
8
- ##
9
- # Returns class when `object` is a class, module when `object` is a module or object's class.
10
- #
11
- # @example Aloid `if` condition for `ConvenientService::Core::Concern::ClassMethod#middlewares`.
12
- #
13
- # service = Service.new # || Service
14
- #
15
- # if service.is_a?(Module)
16
- # service.middlewares(:result)
17
- # else
18
- # service.class.middelewares(:result)
19
- # end
20
- #
21
- # ##
22
- # # With `ConvenientService::Utils::Object::clamp_class` it can be rewritten in the followiing way:
23
- # #
24
- # ConvenientService::Utils::Object::clamp_class(service).middlewares(:result)
25
- #
26
- # @example Possible returns values.
27
- #
28
- # module Musician
29
- # end
30
- #
31
- # class Person
32
- # end
33
- #
34
- # person = Person.new
35
- #
36
- # ConvenientService::Utils::Object::ClampClass.call(42)
37
- # # => Integer
38
- #
39
- # ConvenientService::Utils::Object::ClampClass.call("foo")
40
- # # => String
41
- #
42
- # ConvenientService::Utils::Object::ClampClass.call(person)
43
- # # => Person
44
- #
45
- # ConvenientService::Utils::Object::ClampClass.call(Person)
46
- # # => Person
47
- #
48
- # ConvenientService::Utils::Object::ClampClass.call(Musician)
49
- # # => Musician
50
- #
51
- # @note Name is inspired by `Comparable#clamp`.
52
- #
53
- # @see https://ruby-doc.org/core-2.7.0/Comparable.html#method-i-clamp
54
- #
55
8
  module ConvenientService
56
9
  module Utils
57
10
  module Object
11
+ ##
12
+ # Returns class when `object` is a class, module when `object` is a module or object's class.
13
+ #
14
+ # @api private
15
+ # @since 1.0.0
16
+ #
17
+ # @example Aloid `if` condition for `ConvenientService::Core::Concern::ClassMethod#middlewares`.
18
+ #
19
+ # service = Service.new # || Service
20
+ #
21
+ # if service.is_a?(Module)
22
+ # service.middlewares(:result)
23
+ # else
24
+ # service.class.middelewares(:result)
25
+ # end
26
+ #
27
+ # ##
28
+ # # With `ConvenientService::Utils::Object::clamp_class` it can be rewritten in the followiing way:
29
+ # #
30
+ # ConvenientService::Utils::Object::clamp_class(service).middlewares(:result)
31
+ #
32
+ # @example Possible returns values.
33
+ #
34
+ # module Musician
35
+ # end
36
+ #
37
+ # class Person
38
+ # end
39
+ #
40
+ # person = Person.new
41
+ #
42
+ # ConvenientService::Utils::Object::ClampClass.call(42)
43
+ # # => Integer
44
+ #
45
+ # ConvenientService::Utils::Object::ClampClass.call("foo")
46
+ # # => String
47
+ #
48
+ # ConvenientService::Utils::Object::ClampClass.call(person)
49
+ # # => Person
50
+ #
51
+ # ConvenientService::Utils::Object::ClampClass.call(Person)
52
+ # # => Person
53
+ #
54
+ # ConvenientService::Utils::Object::ClampClass.call(Musician)
55
+ # # => Musician
56
+ #
57
+ # @note Name is inspired by `Comparable#clamp`.
58
+ #
59
+ # @see https://ruby-doc.org/core-2.7.0/Comparable.html#method-i-clamp
60
+ #
58
61
  class ClampClass < Support::Command
59
62
  ##
60
63
  # @!attribute [r] object