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
@@ -9,14 +9,6 @@ require_relative "queries/version"
9
9
  require_relative "queries/ruby"
10
10
  require_relative "queries/gems"
11
11
 
12
- ##
13
- # `ConvenientService::Dependencies` can dynamically require plugins/extensions that have external dependencies.
14
- #
15
- # @internal
16
- # - https://github.com/marian13/convenient_service/wiki/Docs:-Dependencies
17
- #
18
- # TODO: Add `plugin`, `config` suffixes to `require` methods.
19
- #
20
12
  module ConvenientService
21
13
  module Dependencies
22
14
  ##
@@ -30,6 +22,39 @@ module ConvenientService
30
22
  #
31
23
  extend self
32
24
 
25
+ ##
26
+ # Returns `true` when Convenient Service is in debug mode. In other words `$CONVENIENT_SERVICE_DEBUG` env variable is set to `true`.
27
+ #
28
+ # @api private
29
+ # @since 1.0.0
30
+ # @return [Boolean]
31
+ #
32
+ def debug?
33
+ ::ENV["CONVENIENT_SERVICE_DEBUG"] == "true"
34
+ end
35
+
36
+ ##
37
+ # Returns `true` when Convenient Service is in benchmark mode. In other words `$CONVENIENT_SERVICE_BENCHMARK` env variable is set to `true`.
38
+ #
39
+ # @api private
40
+ # @since 1.0.0
41
+ # @return [Boolean]
42
+ #
43
+ def benchmark?
44
+ ::ENV["CONVENIENT_SERVICE_BENCHMARK"] == "true"
45
+ end
46
+
47
+ ##
48
+ # Returns `true` when Convenient Service is in CI mode. In other words `$CONVENIENT_SERVICE_CI` env variable is set to `true`.
49
+ #
50
+ # @api private
51
+ # @since 1.0.0
52
+ # @return [Boolean]
53
+ #
54
+ def ci?
55
+ ::ENV["CONVENIENT_SERVICE_CI"] == "true"
56
+ end
57
+
33
58
  ##
34
59
  # @api private
35
60
  #
@@ -38,7 +63,7 @@ module ConvenientService
38
63
  # @see https://github.com/deivid-rodriguez/byebug/issues/289
39
64
  #
40
65
  # @internal
41
- # NOTE: Ruby 3.5 does not ship with the `readline` by default. That is why `byebug` throws the following error:
66
+ # NOTE: Ruby 4.0 does not ship with the `readline` by default. That is why `byebug` throws the following error:
42
67
  # Sorry, you can't use byebug without Readline. To solve this, you need to
43
68
  # rebuild Ruby with Readline support. If using Ubuntu, try `sudo apt-get
44
69
  # install libreadline-dev` and then reinstall your Ruby.
@@ -50,7 +75,7 @@ module ConvenientService
50
75
  # In other words, the full Docker image source should be copied, extended, and built locally.
51
76
  #
52
77
  def support_byebug?
53
- ruby.mri? && ruby.version < 3.5
78
+ ruby.mri? && ruby.version < 4.0
54
79
  end
55
80
 
56
81
  ##
@@ -151,6 +176,7 @@ module ConvenientService
151
176
  require "convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/entities/status/plugins/has_amazing_print_inspect"
152
177
  require "convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/entities/code/plugins/has_amazing_print_inspect"
153
178
  require "convenient_service/service/plugins/can_have_steps/entities/step/plugins/has_amazing_print_inspect"
179
+ require "convenient_service/feature/plugins/has_amazing_print_inspect"
154
180
  end
155
181
 
156
182
  ##
@@ -257,6 +283,7 @@ module ConvenientService
257
283
  require "convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/entities/status/plugins/has_awesome_print_inspect"
258
284
  require "convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/entities/code/plugins/has_awesome_print_inspect"
259
285
  require "convenient_service/service/plugins/can_have_steps/entities/step/plugins/has_awesome_print_inspect"
286
+ require "convenient_service/feature/plugins/has_awesome_print_inspect"
260
287
  end
261
288
 
262
289
  ##
@@ -319,6 +346,11 @@ module ConvenientService
319
346
  require "convenient_service/service/plugins/has_j_send_result_params_validations/using_dry_validation"
320
347
  end
321
348
 
349
+ ##
350
+ # @api private
351
+ #
352
+ # @return [Boolean]
353
+ #
322
354
  def require_has_memoization_using_memo_wise_plugin
323
355
  ##
324
356
  # - https://github.com/panorama-ed/memo_wise
@@ -356,6 +388,8 @@ module ConvenientService
356
388
  # - https://github.com/deivid-rodriguez/byebug/issues/179#issuecomment-152727003
357
389
  #
358
390
  def require_development_tools(amazing_print: false, awesome_print: true)
391
+ return if ci?
392
+
359
393
  ##
360
394
  # - https://github.com/awesome-print/awesome_print
361
395
  #
@@ -400,7 +434,7 @@ module ConvenientService
400
434
  ##
401
435
  # - https://github.com/rouge-ruby/rouge
402
436
  #
403
- require "rouge"
437
+ require "rouge" if support_byebug?
404
438
 
405
439
  ##
406
440
  # - https://ruby-doc.org/stdlib-2.7.0/libdoc/tempfile/rdoc/Tempfile.html
@@ -428,6 +462,11 @@ module ConvenientService
428
462
  # @note Expected to be called from `spec_helper.rb`.
429
463
  #
430
464
  def require_test_tools
465
+ ##
466
+ # - https://github.com/janlelis/paint
467
+ #
468
+ require "paint"
469
+
431
470
  ##
432
471
  # - https://github.com/faker-ruby/faker
433
472
  #
@@ -465,6 +504,9 @@ module ConvenientService
465
504
  require "rspec/matchers"
466
505
  require "rspec/mocks"
467
506
 
507
+ require "convenient_service/service/plugins/can_have_rspec_stubbed_results"
508
+ require "convenient_service/feature/plugins/can_have_rspec_stubbed_entries"
509
+
468
510
  require "convenient_service/rspec"
469
511
  end
470
512
 
@@ -575,7 +617,7 @@ module ConvenientService
575
617
  ##
576
618
  # @api private
577
619
  #
578
- # @return [ConvenientService::Dependencies::Queries::Ruby]
620
+ # @return [Class<ConvenientService::Dependencies::Queries::Ruby>]
579
621
  #
580
622
  def ruby
581
623
  Ruby
@@ -584,7 +626,16 @@ module ConvenientService
584
626
  ##
585
627
  # @api private
586
628
  #
587
- # @return [ConvenientService::Dependencies::Queries::RSpec]
629
+ # @return [Class<ConvenientService::Dependencies::Queries::Gems::Minitest>]
630
+ #
631
+ def minitest
632
+ Gems::Minitest
633
+ end
634
+
635
+ ##
636
+ # @api private
637
+ #
638
+ # @return [Class<ConvenientService::Dependencies::Queries::Gems::RSpec>]
588
639
  #
589
640
  def rspec
590
641
  Gems::RSpec
@@ -593,7 +644,7 @@ module ConvenientService
593
644
  ##
594
645
  # @api private
595
646
  #
596
- # @return [ConvenientService::Dependencies::Queries::Gems::ActiveModel]
647
+ # @return [Class<ConvenientService::Dependencies::Queries::Gems::ActiveModel>]
597
648
  #
598
649
  def active_model
599
650
  Gems::ActiveModel
@@ -602,7 +653,7 @@ module ConvenientService
602
653
  ##
603
654
  # @api private
604
655
  #
605
- # @return [ConvenientService::Dependencies::Queries::Gems::Logger]
656
+ # @return [Class<ConvenientService::Dependencies::Queries::Gems::Logger>]
606
657
  #
607
658
  def logger
608
659
  Gems::Logger
@@ -611,7 +662,7 @@ module ConvenientService
611
662
  ##
612
663
  # @api private
613
664
  #
614
- # @return [ConvenientService::Dependencies::Queries::Gems::Paint]
665
+ # @return [Class<ConvenientService::Dependencies::Queries::Gems::Paint>]
615
666
  #
616
667
  def paint
617
668
  Gems::Paint
@@ -9,13 +9,13 @@ require_relative "dependencies/built_in"
9
9
  require_relative "dependencies/extractions"
10
10
  require_relative "dependencies/queries"
11
11
 
12
- ##
13
- # `ConvenientService::Dependencies` can dynamically require plugins/extensions that have external dependencies.
14
- #
15
- # @internal
16
- # https://github.com/marian13/convenient_service/wiki/Docs:-Dependencies
17
- #
18
12
  module ConvenientService
13
+ ##
14
+ # `ConvenientService::Dependencies` can dynamically require plugins/extensions that have external dependencies.
15
+ #
16
+ # @internal
17
+ # https://github.com/marian13/convenient_service/wiki/Docs:-Dependencies
18
+ #
19
19
  module Dependencies
20
20
  extend Queries
21
21
  end
@@ -18,7 +18,10 @@ require "convenient_service"
18
18
  ConvenientService::Dependencies.require_alias
19
19
 
20
20
  ##
21
- # `CS` is just an alias for `ConvenientService`. It becames available by `require "convenient_service/alias"`.
21
+ # `CS` is just an alias for `ConvenientService`. It becames available by `require "convenient_service/extra/alias"`.
22
+ #
23
+ # @api public
24
+ # @since 1.0.0
22
25
  #
23
26
  # @internal
24
27
  # NOTE: Added for visibility in YARD docs.
@@ -5,8 +5,6 @@
5
5
  # @license LGPLv3 <https://www.gnu.org/licenses/lgpl-3.0.html>
6
6
  ##
7
7
 
8
- require_relative "standard/commands"
9
-
10
8
  module ConvenientService
11
9
  module Feature
12
10
  module Configs
@@ -16,9 +14,22 @@ module ConvenientService
16
14
  module Standard
17
15
  include ConvenientService::Config
18
16
 
17
+ available_options do
18
+ [
19
+ :essential,
20
+ :inspect,
21
+ :amazing_print_inspect,
22
+ :awesome_print_inspect,
23
+ :test,
24
+ :rspec
25
+ ]
26
+ end
27
+
19
28
  default_options do
20
29
  [
21
30
  :essential,
31
+ :inspect,
32
+ test: Dependencies.rspec.loaded? || Dependencies.minitest.loaded?,
22
33
  rspec: Dependencies.rspec.loaded?
23
34
  ]
24
35
  end
@@ -29,7 +40,11 @@ module ConvenientService
29
40
  concerns do
30
41
  use ConvenientService::Plugins::Feature::CanHaveEntries::Concern if options.enabled?(:essential)
31
42
  use ConvenientService::Plugins::Common::HasInstanceProxy::Concern if options.enabled?(:essential)
32
- use ConvenientService::Plugins::Feature::CanHaveStubbedEntries::Concern if options.enabled?(:rspec)
43
+ use ConvenientService::Plugins::Feature::CanHaveStubbedEntries::Concern if options.enabled?(:test) || options.enabled?(:rspec)
44
+ use ConvenientService::Plugins::Feature::CanHaveRSpecStubbedEntries::Concern if options.enabled?(:rspec)
45
+ use ConvenientService::Plugins::Feature::HasInspect::Concern if options.enabled?(:inspect)
46
+ use ConvenientService::Plugins::Feature::HasAwesomePrintInspect::Concern if options.enabled?(:awesome_print_inspect)
47
+ use ConvenientService::Plugins::Feature::HasAmazingPrintInspect::Concern if options.enabled?(:amazing_print_inspect)
33
48
  end
34
49
 
35
50
  middlewares :new, scope: :class do
@@ -37,11 +52,11 @@ module ConvenientService
37
52
  end
38
53
 
39
54
  middlewares :trigger, scope: :class do
40
- use ConvenientService::Plugins::Feature::CanHaveStubbedEntries::Middleware if options.enabled?(:rspec)
55
+ use ConvenientService::Plugins::Feature::CanHaveStubbedEntries::Middleware if options.enabled?(:test) || options.enabled?(:rspec)
41
56
  end
42
57
 
43
58
  middlewares :trigger do
44
- use ConvenientService::Plugins::Feature::CanHaveStubbedEntries::Middleware if options.enabled?(:rspec)
59
+ use ConvenientService::Plugins::Feature::CanHaveStubbedEntries::Middleware if options.enabled?(:test) || options.enabled?(:rspec)
45
60
  end
46
61
  end
47
62
 
@@ -65,14 +80,19 @@ module ConvenientService
65
80
  # end
66
81
  # end
67
82
  #
68
- # ConvenientService::Feature::Configs::Standard.feature_class?(Feature)
83
+ # ConvenientService::Feature::Configs::Standard.feature_class?(Feature)
84
+ # # => false
85
+ #
86
+ # ConvenientService::Feature::Configs::Standard.feature_class?(Feature.new)
69
87
  # # => true
70
88
  #
71
- # ConvenientService::Feature::Configs::Standard.feature_class?(42)
89
+ # ConvenientService::Feature::Configs::Standard.feature_class?(42)
72
90
  # # => false
73
91
  #
74
92
  def feature_class?(feature_class)
75
- Commands::IsFeatureClass[feature_class: feature_class]
93
+ return false unless feature_class.instance_of?(::Class)
94
+
95
+ feature_class.include?(Feature::Core)
76
96
  end
77
97
 
78
98
  ##
@@ -94,16 +114,17 @@ module ConvenientService
94
114
  # end
95
115
  # end
96
116
  #
97
- # feature = Feature.new
98
- #
99
- # ConvenientService::Feature::Configs::Standard.feature?(feature)
117
+ # ConvenientService::Feature::Configs::Standard.feature?(Feature.new)
100
118
  # # => true
101
119
  #
102
- # ConvenientService::Feature::Configs::Standard.feature?(42)
120
+ # ConvenientService::Feature::Configs::Standard.feature?(Feature)
121
+ # # => false
122
+ #
123
+ # ConvenientService::Feature::Configs::Standard.feature?(42)
103
124
  # # => false
104
125
  #
105
126
  def feature?(feature)
106
- Commands::IsFeature[feature: feature]
127
+ feature_class?(feature.class)
107
128
  end
108
129
  end
109
130
  end
@@ -13,6 +13,47 @@ module ConvenientService
13
13
  included do
14
14
  include ::ConvenientService::Core
15
15
  end
16
+
17
+ instance_methods do
18
+ ##
19
+ # Returns string representation of feature.
20
+ #
21
+ # @api public
22
+ # @since 1.0.0
23
+ #
24
+ # @param format [Symbol]
25
+ # @return [String]
26
+ #
27
+ # @note Intended to be used for debugging purposes.
28
+ #
29
+ # @example Common usage.
30
+ # class Feature
31
+ # include ConvenientFeature::Feature::Standard::Config
32
+ #
33
+ # entry :main
34
+ #
35
+ # def main
36
+ # :main_entry_value
37
+ # end
38
+ # end
39
+ #
40
+ # puts Feature.new
41
+ # # <Feature>
42
+ # # => nil
43
+ #
44
+ # Feature.new.to_s
45
+ # # => "<Feature>"
46
+ #
47
+ # Feature.new.to_s(format: :inspect)
48
+ # # => "<Feature>"
49
+ #
50
+ # Feature.new.to_s(format: :original)
51
+ # # => "#<Feature:0x00005639cd363000>"
52
+ #
53
+ def to_s(format: :inspect)
54
+ (format == :inspect) ? inspect : super()
55
+ end
56
+ end
16
57
  end
17
58
  end
18
59
  end
@@ -7,6 +7,35 @@
7
7
 
8
8
  module ConvenientService
9
9
  module Plugins
10
+ ##
11
+ # Intermediate module/namespace to access plugins that can be applied only to features.
12
+ #
13
+ # @api public
14
+ # @since 1.0.0
15
+ # @return [Module]
16
+ #
17
+ # @example Feature plugin `CanHaveEntries` is used for features.
18
+ # ##
19
+ # # Since the `CanHaveEntries` feature plugin is included by default by the feature standard config,
20
+ # # the example below shows how to remove it instead of adding it.
21
+ # #
22
+ # class Feature
23
+ # include ConvenientService::Feature::Standard::Config
24
+ #
25
+ # concerns do
26
+ # delete ConvenientService::Plugins::Feature::CanHaveEntries::Concern
27
+ # end
28
+ #
29
+ # ##
30
+ # # Raises since `CanHaveEntries` is removed.
31
+ # #
32
+ # entry :main
33
+ #
34
+ # def main
35
+ # :main_entry_value
36
+ # end
37
+ # end
38
+ #
10
39
  Feature = ::ConvenientService::Feature::Plugins
11
40
  end
12
41
  end
@@ -0,0 +1,34 @@
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 Feature
10
+ module Plugins
11
+ module CanHaveRSpecStubbedEntries
12
+ module Concern
13
+ include Support::Concern
14
+
15
+ class_methods do
16
+ ##
17
+ # @return [RSpec::Core::Example, nil]
18
+ #
19
+ # @internal
20
+ # NOTE: `::RSpec.current_example` docs.
21
+ # - https://www.rubydoc.info/github/rspec/rspec-core/RSpec.current_example
22
+ # - https://github.com/rspec/rspec-core/blob/v3.12.0/lib/rspec/core.rb#L122
23
+ # - https://github.com/rspec/rspec-support/blob/v3.12.0/lib/rspec/support.rb#L92
24
+ # - https://relishapp.com/rspec/rspec-core/docs/metadata/current-example
25
+ #
26
+ def stubbed_entries_store
27
+ Dependencies.rspec.current_example
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -5,5 +5,4 @@
5
5
  # @license LGPLv3 <https://www.gnu.org/licenses/lgpl-3.0.html>
6
6
  ##
7
7
 
8
- require_relative "entities/stubbed_feature"
9
- require_relative "entities/value_spec"
8
+ require_relative "can_have_rspec_stubbed_entries/concern"
@@ -0,0 +1,71 @@
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 Feature
10
+ module Plugins
11
+ module CanHaveStubbedEntries
12
+ module Commands
13
+ class DeleteFeatureStubbedEntry < Support::Command
14
+ ##
15
+ # @!attribute [r] feature
16
+ # @return [ConvenientService::Feature]
17
+ #
18
+ attr_reader :feature
19
+
20
+ ##
21
+ # @!attribute [r] entry
22
+ # @return [Symbol, String]
23
+ #
24
+ attr_reader :entry
25
+
26
+ ##
27
+ # @!attribute [r] arguments
28
+ # @return [ConvenientService::Support::Arguments]
29
+ #
30
+ attr_reader :arguments
31
+
32
+ ##
33
+ # @param feature [ConvenientService::Feature]
34
+ # @param entry [Symbol, String]
35
+ # @param arguments [ConvenientService::Support::Arguments]
36
+ # @return [void]
37
+ #
38
+ def initialize(feature:, entry:, arguments:)
39
+ @feature = feature
40
+ @entry = entry
41
+ @arguments = arguments
42
+ end
43
+
44
+ ##
45
+ # @return [Object] Can be any type.
46
+ #
47
+ # @internal
48
+ # NOTE: `arguments.nil?` means "match any arguments".
49
+ #
50
+ def call
51
+ if arguments.nil?
52
+ cache.default = nil
53
+ else
54
+ cache.delete(cache.keygen(*arguments.args, **arguments.kwargs, &arguments.block))
55
+ end
56
+ end
57
+
58
+ private
59
+
60
+ ##
61
+ # @return [ConvenientService::Support::Cache]
62
+ #
63
+ def cache
64
+ @cache ||= Commands::FetchFeatureStubbedEntriesCache.call(feature: feature).scope(entry.to_sym, backed_by: :thread_safe_array)
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
@@ -11,6 +11,20 @@ module ConvenientService
11
11
  module CanHaveStubbedEntries
12
12
  module Commands
13
13
  class FetchAllFeaturesStubbedEntriesCache < Support::Command
14
+ ##
15
+ # @!attribute [r] feature
16
+ # @return [ConvenientService::Feature]
17
+ #
18
+ attr_reader :feature
19
+
20
+ ##
21
+ # @param feature [ConvenientService::Feature]
22
+ # @return [void]
23
+ #
24
+ def initialize(feature:)
25
+ @feature = feature
26
+ end
27
+
14
28
  ##
15
29
  # @return [ConvenientService::Support::Cache]
16
30
  #
@@ -21,8 +35,8 @@ module ConvenientService
21
35
  # - https://relishapp.com/rspec/rspec-core/docs/metadata/current-example
22
36
  #
23
37
  def call
24
- if Dependencies.rspec.current_example
25
- Utils::Object.memoize_including_falsy_values(Dependencies.rspec.current_example, :@__convenient_service_stubbed_entries__) { Support::Cache.backed_by(:thread_safe_hash).new }
38
+ if feature.stubbed_entries_store
39
+ Utils::Object.memoize_including_falsy_values(feature.stubbed_entries_store, :@__convenient_service_stubbed_entries__) { Support::Cache.backed_by(:thread_safe_hash).new }
26
40
  else
27
41
  Support::Cache.backed_by(:thread_safe_hash).new
28
42
  end
@@ -38,7 +38,7 @@ module ConvenientService
38
38
  # @return [ConvenientService::Support::Cache]
39
39
  #
40
40
  def cache
41
- @cache ||= Commands::FetchAllFeaturesStubbedEntriesCache.call
41
+ @cache ||= Commands::FetchAllFeaturesStubbedEntriesCache.call(feature: feature)
42
42
  end
43
43
  end
44
44
  end
@@ -7,4 +7,6 @@
7
7
 
8
8
  require_relative "commands/fetch_all_features_stubbed_entries_cache"
9
9
  require_relative "commands/fetch_feature_stubbed_entries_cache"
10
+
11
+ require_relative "commands/delete_feature_stubbed_entry"
10
12
  require_relative "commands/set_feature_stubbed_entry"
@@ -26,6 +26,13 @@ module ConvenientService
26
26
  end
27
27
 
28
28
  class_methods do
29
+ ##
30
+ # @return [Thread]
31
+ #
32
+ def stubbed_entries_store
33
+ ::Thread.current
34
+ end
35
+
29
36
  ##
30
37
  # @return [ConvenientService::Support::Cache]
31
38
  #
@@ -43,6 +50,22 @@ module ConvenientService
43
50
  def stubbed_entries
44
51
  Commands::FetchFeatureStubbedEntriesCache.call(feature: self)
45
52
  end
53
+
54
+ ##
55
+ # @param entry_name [Symbol, String]
56
+ # @return [ConvenientService::Feature::Plugins::CanHaveStubbedEntries::Entities::FeatureStub]
57
+ #
58
+ def stub_entry(entry_name)
59
+ Entities::FeatureStub.new(feature_class: self, entry_name: entry_name)
60
+ end
61
+
62
+ ##
63
+ # @param entry_name [Symbol, String]
64
+ # @return [ConvenientService::Feature::Plugins::CanHaveStubbedEntries::Entities::FeatureUnstub]
65
+ #
66
+ def unstub_entry(entry_name)
67
+ Entities::FeatureUnstub.new(feature_class: self, entry_name: entry_name)
68
+ end
46
69
  end
47
70
  end
48
71
  end