convenient_service 0.7.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +36 -0
  3. data/ROADMAP.md +2 -0
  4. data/lib/convenient_service/aliases.rb +9 -0
  5. data/lib/convenient_service/common/plugins/has_constructor_without_initialize/concern.rb +19 -0
  6. data/lib/convenient_service/configs/minimal.rb +176 -0
  7. data/lib/convenient_service/configs/standard.rb +16 -104
  8. data/lib/convenient_service/configs.rb +1 -0
  9. data/lib/convenient_service/dependencies.rb +8 -0
  10. data/lib/convenient_service/examples/dry/gemfile/dry_service/config.rb +5 -5
  11. data/lib/convenient_service/examples/rails/gemfile/rails_service/config.rb +7 -7
  12. data/lib/convenient_service/rspec/helpers/custom/ignoring_error.rb +3 -0
  13. data/lib/convenient_service/rspec/helpers/custom/wrap_method/entities/wrapped_method.rb +29 -3
  14. data/lib/convenient_service/rspec/matchers/custom/results/base.rb +5 -0
  15. data/lib/convenient_service/service/plugins/has_result/concern/class_methods.rb +3 -3
  16. data/lib/convenient_service/service/plugins/has_result/constants.rb +0 -3
  17. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/data.rb +13 -0
  18. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_result_short_syntax/concern.rb +33 -1
  19. data/lib/convenient_service/service/plugins/raises_on_double_result/middleware.rb +37 -2
  20. data/lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions/commands/format_backtrace.rb +80 -0
  21. data/lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions/commands/format_cause.rb +78 -0
  22. data/lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions/commands/format_exception.rb +169 -0
  23. data/lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions/commands/format_line.rb +40 -0
  24. data/lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions/commands.rb +7 -0
  25. data/lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions/constants.rb +13 -0
  26. data/lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions/middleware.rb +58 -0
  27. data/lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions.rb +5 -0
  28. data/lib/convenient_service/support/dependency_container/errors.rb +14 -0
  29. data/lib/convenient_service/support/dependency_container/export.rb +8 -0
  30. data/lib/convenient_service/support/undefined.rb +9 -0
  31. data/lib/convenient_service/support.rb +2 -0
  32. data/lib/convenient_service/utils/object/memoize_including_falsy_values.rb +61 -0
  33. data/lib/convenient_service/utils/object.rb +11 -0
  34. data/lib/convenient_service/version.rb +1 -1
  35. metadata +13 -3
  36. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_result_short_syntax/concern/instance_methods.rb +0 -28
@@ -6,6 +6,14 @@ module ConvenientService
6
6
  module Export
7
7
  include Support::Concern
8
8
 
9
+ ##
10
+ # @param klass [Class, Module]
11
+ # @return [Module]
12
+ #
13
+ included do |klass|
14
+ raise Errors::NotModule.new(klass: klass) unless klass.instance_of?(::Module)
15
+ end
16
+
9
17
  class_methods do
10
18
  ##
11
19
  # @param full_name [String, Symbol]
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ConvenientService
4
+ module Support
5
+ UNDEFINED = ::Object.new.tap do |object|
6
+ object.define_singleton_method(:inspect) { "undefined" }
7
+ end
8
+ end
9
+ end
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "support/not_passed"
4
+ require_relative "support/undefined"
5
+
4
6
  require_relative "support/concern"
5
7
 
6
8
  require_relative "support/abstract_method"
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ ##
4
+ #
5
+ #
6
+ module ConvenientService
7
+ module Utils
8
+ module Object
9
+ ##
10
+ # Can be used instead of `return @ivar if defined? @ivar`.
11
+ # @see https://www.justinweiss.com/articles/4-simple-memoization-patterns-in-ruby-and-one-gem/
12
+ #
13
+ # @note: `false` and `nil` are the only values that are considered `falsy` in Ruby.
14
+ # @see https://riptutorial.com/ruby/example/2092/truthy-and-falsy-values
15
+ # @see https://www.ruby-lang.org/en/documentation/faq/6/
16
+ #
17
+ # @internal
18
+ # NOTE: `falsy` is probably more common than `falsey`.
19
+ # - https://developer.mozilla.org/en-US/docs/Glossary/Falsy
20
+ #
21
+ class MemoizeIncludingFalsyValues < Support::Command
22
+ ##
23
+ # @!attribute [r] object
24
+ # @return [Object]
25
+ #
26
+ attr_reader :object
27
+
28
+ ##
29
+ # @!attribute [r] ivar_name
30
+ # @return [Symbol, String]
31
+ #
32
+ attr_reader :ivar_name
33
+
34
+ ##
35
+ # @!attribute [r] value_block
36
+ # @return [Proc, nil]
37
+ #
38
+ attr_reader :value_block
39
+
40
+ ##
41
+ # @param object [Object]
42
+ # @param ivar_name [Symbol]
43
+ # @param value_block [Proc]
44
+ # @return [void]
45
+ #
46
+ def initialize(object, ivar_name, &value_block)
47
+ @object = object
48
+ @ivar_name = ivar_name
49
+ @value_block = value_block
50
+ end
51
+
52
+ ##
53
+ # @return [Object] Value of ivar. Can be any type.
54
+ #
55
+ def call
56
+ Utils::Object.instance_variable_fetch(object, ivar_name, &value_block)
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require_relative "object/instance_variable_delete"
4
4
  require_relative "object/instance_variable_fetch"
5
+ require_relative "object/memoize_including_falsy_values"
5
6
  require_relative "object/resolve_type"
6
7
 
7
8
  module ConvenientService
@@ -24,6 +25,16 @@ module ConvenientService
24
25
  InstanceVariableFetch.call(...)
25
26
  end
26
27
 
28
+ ##
29
+ # @example
30
+ # object = Object.new.tap { |object| object.instance_eval { self.class.attr_reader :foo } }
31
+ #
32
+ # ConvenientService::Utils::Object.memoize_including_falsy_values(object, :@foo) { false }
33
+ #
34
+ def memoize_including_falsy_values(...)
35
+ MemoizeIncludingFalsyValues.call(...)
36
+ end
37
+
27
38
  ##
28
39
  # @example
29
40
  # ConvenientService::Utils::Object.resolve_type("foo")
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ConvenientService
4
- VERSION = "0.7.0"
4
+ VERSION = "0.9.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: convenient_service
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marian Kostyk
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-13 00:00:00.000000000 Z
11
+ date: 2023-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: appraisal
@@ -427,6 +427,7 @@ files:
427
427
  - lib/convenient_service/common/plugins/normalizes_env/middleware.rb
428
428
  - lib/convenient_service/configs.rb
429
429
  - lib/convenient_service/configs/aliases.rb
430
+ - lib/convenient_service/configs/minimal.rb
430
431
  - lib/convenient_service/configs/standard.rb
431
432
  - lib/convenient_service/core.rb
432
433
  - lib/convenient_service/core/aliases.rb
@@ -727,7 +728,6 @@ files:
727
728
  - lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/structs/jsend_attributes.rb
728
729
  - lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_result_short_syntax.rb
729
730
  - lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_result_short_syntax/concern.rb
730
- - lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_result_short_syntax/concern/instance_methods.rb
731
731
  - lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_step.rb
732
732
  - lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_step/concern.rb
733
733
  - lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_step/initialize.rb
@@ -825,6 +825,14 @@ files:
825
825
  - lib/convenient_service/service/plugins/raises_on_double_result.rb
826
826
  - lib/convenient_service/service/plugins/raises_on_double_result/errors.rb
827
827
  - lib/convenient_service/service/plugins/raises_on_double_result/middleware.rb
828
+ - lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions.rb
829
+ - lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions/commands.rb
830
+ - lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions/commands/format_backtrace.rb
831
+ - lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions/commands/format_cause.rb
832
+ - lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions/commands/format_exception.rb
833
+ - lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions/commands/format_line.rb
834
+ - lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions/constants.rb
835
+ - lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions/middleware.rb
828
836
  - lib/convenient_service/service/plugins/wraps_result_in_db_transaction.rb
829
837
  - lib/convenient_service/service/plugins/wraps_result_in_db_transaction/middleware.rb
830
838
  - lib/convenient_service/services.rb
@@ -867,6 +875,7 @@ files:
867
875
  - lib/convenient_service/support/not_passed.rb
868
876
  - lib/convenient_service/support/raw_value.rb
869
877
  - lib/convenient_service/support/ruby.rb
878
+ - lib/convenient_service/support/undefined.rb
870
879
  - lib/convenient_service/support/version.rb
871
880
  - lib/convenient_service/support/version/null_version.rb
872
881
  - lib/convenient_service/utils.rb
@@ -897,6 +906,7 @@ files:
897
906
  - lib/convenient_service/utils/object.rb
898
907
  - lib/convenient_service/utils/object/instance_variable_delete.rb
899
908
  - lib/convenient_service/utils/object/instance_variable_fetch.rb
909
+ - lib/convenient_service/utils/object/memoize_including_falsy_values.rb
900
910
  - lib/convenient_service/utils/object/resolve_type.rb
901
911
  - lib/convenient_service/utils/proc.rb
902
912
  - lib/convenient_service/utils/proc/conjunct.rb
@@ -1,28 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ConvenientService
4
- module Service
5
- module Plugins
6
- module HasResult
7
- module Entities
8
- class Result
9
- module Plugins
10
- module HasResultShortSyntax
11
- module Concern
12
- module InstanceMethods
13
- ##
14
- # NOTE: `Support::Delegate` is NOT used intentionally in order to NOT pollute the public interface.
15
- #
16
- def [](key)
17
- data[key]
18
- end
19
- end
20
- end
21
- end
22
- end
23
- end
24
- end
25
- end
26
- end
27
- end
28
- end