convenient_service 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. checksums.yaml +4 -4
  2. data/.gem_release.yml +0 -12
  3. data/.github/issue_template.md +35 -0
  4. data/.github/pull_request_template.md +31 -0
  5. data/.github/workflows/cd.yml +15 -2
  6. data/CHANGELOG.md +18 -0
  7. data/README.md +12 -3
  8. data/ROADMAP.md +19 -8
  9. data/Taskfile.yml +2 -10
  10. data/lib/convenient_service/common/plugins/caches_return_value/middleware.rb +17 -2
  11. data/lib/convenient_service/common/plugins/caches_return_value.rb +0 -1
  12. data/lib/convenient_service/common/plugins/has_constructor/concern.rb +13 -0
  13. data/lib/convenient_service/common/plugins/has_constructor_without_initialize/concern.rb +27 -0
  14. data/lib/convenient_service/common/plugins/has_constructor_without_initialize.rb +3 -0
  15. data/lib/convenient_service/common/plugins/has_internals/entities/internals/plugins/has_cache/concern.rb +8 -4
  16. data/lib/convenient_service/common/plugins/has_internals/entities/internals/plugins/has_cache.rb +0 -1
  17. data/lib/convenient_service/common/plugins.rb +1 -0
  18. data/lib/convenient_service/configs/standard.rb +16 -0
  19. data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/container/commands/cast_container.rb +0 -2
  20. data/lib/convenient_service/dependencies.rb +1 -0
  21. data/lib/convenient_service/examples/dry/gemfile.rb +5 -4
  22. data/lib/convenient_service/examples/rails/gemfile.rb +5 -4
  23. data/lib/convenient_service/examples/standard/cowsay/services/build_cloud.rb +42 -0
  24. data/lib/convenient_service/examples/standard/cowsay/services/build_cow.rb +38 -0
  25. data/lib/convenient_service/examples/standard/cowsay/services/print.rb +32 -0
  26. data/lib/convenient_service/examples/standard/cowsay/services.rb +5 -0
  27. data/lib/convenient_service/examples/standard/cowsay.rb +24 -0
  28. data/lib/convenient_service/examples/standard/gemfile/services/format.rb +2 -0
  29. data/lib/convenient_service/examples/standard/gemfile.rb +5 -4
  30. data/lib/convenient_service/rspec/helpers/custom/stub_service/entities/result_spec.rb +96 -7
  31. data/lib/convenient_service/rspec/helpers/custom/wrap_method/entities/wrapped_method.rb +44 -8
  32. data/lib/convenient_service/rspec/helpers/custom/wrap_method/errors.rb +11 -9
  33. data/lib/convenient_service/rspec/matchers/custom/call_chain_next.rb +2 -0
  34. data/lib/convenient_service/rspec/matchers/custom/results/be_success.rb +6 -0
  35. data/lib/convenient_service/service/plugins/aliases.rb +1 -0
  36. data/lib/convenient_service/service/plugins/has_inspect/concern.rb +23 -0
  37. data/lib/convenient_service/service/plugins/has_inspect.rb +3 -0
  38. data/lib/convenient_service/service/plugins/has_result/commands/create_result_class.rb +10 -0
  39. data/lib/convenient_service/service/plugins/has_result/concern/class_methods.rb +23 -14
  40. data/lib/convenient_service/service/plugins/has_result/concern/instance_methods.rb +17 -1
  41. data/lib/convenient_service/service/plugins/has_result/entities/result/concern.rb +4 -3
  42. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_inspect/concern.rb +31 -0
  43. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_inspect.rb +3 -0
  44. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/commands/cast_jsend_attributes.rb +37 -0
  45. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/commands.rb +3 -0
  46. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/concern/instance_methods.rb +115 -0
  47. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/concern.rb +27 -0
  48. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/code/class_methods.rb +34 -0
  49. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/code.rb +49 -0
  50. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/data/class_methods.rb +32 -0
  51. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/data.rb +49 -0
  52. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/message/class_methods.rb +34 -0
  53. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/message.rb +45 -0
  54. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/status/class_methods.rb +34 -0
  55. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/status.rb +73 -0
  56. data/lib/convenient_service/service/plugins/has_result/entities/result/{entities.rb → plugins/has_jsend_status_and_attributes/entities.rb} +0 -0
  57. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/errors.rb +29 -0
  58. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/middleware.rb +31 -0
  59. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/structs/jsend_attributes.rb +21 -0
  60. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/structs.rb +3 -0
  61. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes.rb +8 -0
  62. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins.rb +2 -0
  63. data/lib/convenient_service/service/plugins/has_result/entities/result.rb +0 -4
  64. data/lib/convenient_service/service/plugins/has_result_method_steps/middleware.rb +1 -1
  65. data/lib/convenient_service/service/plugins/has_result_method_steps/services/method_step_config.rb +30 -4
  66. data/lib/convenient_service/service/plugins/has_result_status_check_short_syntax/concern.rb +63 -0
  67. data/lib/convenient_service/service/plugins/has_result_status_check_short_syntax.rb +3 -0
  68. data/lib/convenient_service/service/plugins/has_result_steps/concern.rb +2 -1
  69. data/lib/convenient_service/service/plugins/has_result_steps/entities/step/plugins/has_inspect/concern.rb +31 -0
  70. data/lib/convenient_service/service/plugins/has_result_steps/entities/step/plugins/has_inspect.rb +3 -0
  71. data/lib/convenient_service/service/plugins/has_result_steps/entities/step/plugins.rb +3 -0
  72. data/lib/convenient_service/service/plugins/has_result_steps/entities/step.rb +1 -0
  73. data/lib/convenient_service/service/plugins.rb +2 -0
  74. data/lib/convenient_service/support/cache/key.rb +100 -0
  75. data/lib/convenient_service/support/cache.rb +131 -0
  76. data/lib/convenient_service/support/copyable.rb +3 -2
  77. data/lib/convenient_service/support/delegate.rb +3 -2
  78. data/lib/convenient_service/support.rb +1 -0
  79. data/lib/convenient_service/version.rb +1 -1
  80. data/logo.png +0 -0
  81. metadata +40 -21
  82. data/lib/convenient_service/common/plugins/caches_return_value/entities/key.rb +0 -79
  83. data/lib/convenient_service/common/plugins/caches_return_value/entities.rb +0 -3
  84. data/lib/convenient_service/common/plugins/has_internals/entities/internals/plugins/has_cache/entities/cache.rb +0 -81
  85. data/lib/convenient_service/common/plugins/has_internals/entities/internals/plugins/has_cache/entities.rb +0 -3
  86. data/lib/convenient_service/service/plugins/has_result/entities/result/commands/cast_result_params.rb +0 -33
  87. data/lib/convenient_service/service/plugins/has_result/entities/result/commands.rb +0 -3
  88. data/lib/convenient_service/service/plugins/has_result/entities/result/concern/instance_methods.rb +0 -64
  89. data/lib/convenient_service/service/plugins/has_result/entities/result/entities/code/class_methods.rb +0 -30
  90. data/lib/convenient_service/service/plugins/has_result/entities/result/entities/code.rb +0 -45
  91. data/lib/convenient_service/service/plugins/has_result/entities/result/entities/data/class_methods.rb +0 -28
  92. data/lib/convenient_service/service/plugins/has_result/entities/result/entities/data.rb +0 -45
  93. data/lib/convenient_service/service/plugins/has_result/entities/result/entities/message/class_methods.rb +0 -30
  94. data/lib/convenient_service/service/plugins/has_result/entities/result/entities/message.rb +0 -41
  95. data/lib/convenient_service/service/plugins/has_result/entities/result/entities/status/class_methods.rb +0 -30
  96. data/lib/convenient_service/service/plugins/has_result/entities/result/entities/status.rb +0 -69
  97. data/lib/convenient_service/service/plugins/has_result/entities/result/errors.rb +0 -25
  98. data/lib/convenient_service/service/plugins/has_result/entities/result/structs/result_params.rb +0 -17
  99. data/lib/convenient_service/service/plugins/has_result/entities/result/structs.rb +0 -3
@@ -1,81 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ConvenientService
4
- module Common
5
- module Plugins
6
- module HasInternals
7
- module Entities
8
- class Internals
9
- module Plugins
10
- module HasCache
11
- module Entities
12
- ##
13
- # TODO: Specs.
14
- #
15
- class Cache
16
- attr_reader :hash
17
-
18
- def initialize
19
- @hash = {}
20
- end
21
-
22
- ##
23
- # https://api.rubyonrails.org/classes/ActiveSupport/Cache/Store.html#method-i-exist-3F
24
- #
25
- def exist?(key)
26
- hash.has_key?(key)
27
- end
28
-
29
- ##
30
- # https://api.rubyonrails.org/classes/ActiveSupport/Cache/Store.html#method-i-read
31
- #
32
- def read(key)
33
- hash[key]
34
- end
35
-
36
- ##
37
- # NOTE: `alias_method` is NOT used in order to have an ability to use `allow(cache).to receive(:read).with(key).and_call_original` for both `cache[key]` and `cache.read(key)` in RSpec.
38
- #
39
- def [](key)
40
- read(key)
41
- end
42
-
43
- ##
44
- # https://api.rubyonrails.org/classes/ActiveSupport/Cache/Store.html#method-i-write
45
- #
46
- def write(key, value)
47
- hash[key] = value
48
- end
49
-
50
- ##
51
- # NOTE: `alias_method` is NOT used in order to have an ability to use `allow(cache).to receive(:write).with(key, value).and_call_original` for both `cache[key] = value` and `cache.write(key, value)` in RSpec.
52
- #
53
- def []=(key, value)
54
- write(key, value)
55
- end
56
-
57
- ##
58
- # https://api.rubyonrails.org/classes/ActiveSupport/Cache/Store.html#method-i-delete
59
- #
60
- def delete(key)
61
- hash.delete(key)
62
- end
63
-
64
- ##
65
- # https://api.rubyonrails.org/classes/ActiveSupport/Cache/Store.html#method-i-fetch
66
- #
67
- def fetch(key, &block)
68
- return read(key) unless block
69
-
70
- exist?(key) ? read(key) : write(key, block.call)
71
- end
72
- end
73
- end
74
- end
75
- end
76
- end
77
- end
78
- end
79
- end
80
- end
81
- end
@@ -1,3 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "entities/cache"
@@ -1,33 +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 Commands
10
- class CastResultParams < Support::Command
11
- attr_reader :params
12
-
13
- def initialize(params:)
14
- @params = params
15
- end
16
-
17
- def call
18
- Structs::ResultParams.new(
19
- service: params[:service],
20
- status: Entities::Status.cast!(params[:status]),
21
- data: Entities::Data.cast!(params[:data]),
22
- message: Entities::Message.cast!(params[:message]),
23
- code: Entities::Code.cast!(params[:code])
24
- )
25
- end
26
- end
27
- end
28
- end
29
- end
30
- end
31
- end
32
- end
33
- end
@@ -1,3 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "commands/cast_result_params"
@@ -1,64 +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 Concern
10
- ##
11
- # TODO: How to use concern outside?
12
- #
13
- module InstanceMethods
14
- include Support::Delegate
15
- include Support::Copyable
16
-
17
- delegate \
18
- :service,
19
- :status,
20
- :data,
21
- :message,
22
- :code,
23
- to: :params
24
-
25
- delegate \
26
- :success?,
27
- :failure?,
28
- :error?,
29
- :not_success?,
30
- :not_failure?,
31
- :not_error?,
32
- to: :status
33
-
34
- def initialize(**params)
35
- @params = Commands::CastResultParams.call(params: params)
36
- end
37
-
38
- def ==(other)
39
- return unless other.instance_of?(self.class)
40
-
41
- return false if service.class != other.service.class
42
- return false if status != other.status
43
- return false if data != other.data
44
- return false if message != other.message
45
- return false if code != other.code
46
-
47
- true
48
- end
49
-
50
- def to_kwargs
51
- {service: service, status: status, data: data, message: message, code: code}
52
- end
53
-
54
- private
55
-
56
- attr_reader :params
57
- end
58
- end
59
- end
60
- end
61
- end
62
- end
63
- end
64
- end
@@ -1,30 +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 Entities
10
- class Code
11
- module ClassMethods
12
- def cast(other)
13
- case other
14
- when ::String
15
- new(value: other.to_sym)
16
- when ::Symbol
17
- new(value: other)
18
- when Code
19
- new(value: other.value)
20
- end
21
- end
22
- end
23
- end
24
- end
25
- end
26
- end
27
- end
28
- end
29
- end
30
- end
@@ -1,45 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "code/class_methods"
4
-
5
- module ConvenientService
6
- module Service
7
- module Plugins
8
- module HasResult
9
- module Entities
10
- class Result
11
- module Entities
12
- class Code
13
- include Support::Castable
14
-
15
- extend ClassMethods
16
-
17
- attr_reader :value
18
-
19
- def initialize(value:)
20
- @value = value
21
- end
22
-
23
- def ==(other)
24
- casted = cast(other)
25
-
26
- return unless casted
27
-
28
- value == casted.value
29
- end
30
-
31
- def to_s
32
- @to_s ||= value.to_s
33
- end
34
-
35
- def to_sym
36
- @to_sym ||= value.to_sym
37
- end
38
- end
39
- end
40
- end
41
- end
42
- end
43
- end
44
- end
45
- end
@@ -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 Entities
10
- class Data
11
- module ClassMethods
12
- def cast(other)
13
- case other
14
- when ::Hash
15
- new(value: other.transform_keys(&:to_sym))
16
- when Data
17
- new(value: other.value)
18
- end
19
- end
20
- end
21
- end
22
- end
23
- end
24
- end
25
- end
26
- end
27
- end
28
- end
@@ -1,45 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "data/class_methods"
4
-
5
- module ConvenientService
6
- module Service
7
- module Plugins
8
- module HasResult
9
- module Entities
10
- class Result
11
- module Entities
12
- class Data
13
- include Support::Castable
14
-
15
- extend ClassMethods
16
-
17
- attr_reader :value
18
-
19
- def initialize(value:)
20
- @value = value
21
- end
22
-
23
- def ==(other)
24
- casted = cast(other)
25
-
26
- return unless casted
27
-
28
- value == casted.value
29
- end
30
-
31
- def [](key)
32
- value.fetch(key.to_sym) { raise Errors::NotExistingAttribute.new(attribute: key) }
33
- end
34
-
35
- def to_h
36
- @to_h ||= value.to_h
37
- end
38
- end
39
- end
40
- end
41
- end
42
- end
43
- end
44
- end
45
- end
@@ -1,30 +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 Entities
10
- class Message
11
- module ClassMethods
12
- def cast(other)
13
- case other
14
- when ::String
15
- new(value: other)
16
- when ::Symbol
17
- new(value: other.to_s)
18
- when Message
19
- new(value: other.value)
20
- end
21
- end
22
- end
23
- end
24
- end
25
- end
26
- end
27
- end
28
- end
29
- end
30
- end
@@ -1,41 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "message/class_methods"
4
-
5
- module ConvenientService
6
- module Service
7
- module Plugins
8
- module HasResult
9
- module Entities
10
- class Result
11
- module Entities
12
- class Message
13
- include Support::Castable
14
-
15
- extend ClassMethods
16
-
17
- attr_reader :value
18
-
19
- def initialize(value:)
20
- @value = value
21
- end
22
-
23
- def ==(other)
24
- casted = cast(other)
25
-
26
- return unless casted
27
-
28
- value == casted.value
29
- end
30
-
31
- def to_s
32
- @to_s ||= value.to_s
33
- end
34
- end
35
- end
36
- end
37
- end
38
- end
39
- end
40
- end
41
- end
@@ -1,30 +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 Entities
10
- class Status
11
- module ClassMethods
12
- def cast(other)
13
- case other
14
- when ::String
15
- new(value: other.to_sym)
16
- when ::Symbol
17
- new(value: other)
18
- when Status
19
- new(value: other.value)
20
- end
21
- end
22
- end
23
- end
24
- end
25
- end
26
- end
27
- end
28
- end
29
- end
30
- end
@@ -1,69 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "status/class_methods"
4
-
5
- module ConvenientService
6
- module Service
7
- module Plugins
8
- module HasResult
9
- module Entities
10
- class Result
11
- module Entities
12
- class Status
13
- include Support::Castable
14
-
15
- extend ClassMethods
16
-
17
- attr_reader :value
18
-
19
- def initialize(value:)
20
- @value = value
21
- end
22
-
23
- def ==(other)
24
- casted = cast(other)
25
-
26
- return unless casted
27
-
28
- value == casted.value
29
- end
30
-
31
- def success?
32
- value == :success
33
- end
34
-
35
- def failure?
36
- value == :failure
37
- end
38
-
39
- def error?
40
- value == :error
41
- end
42
-
43
- def not_success?
44
- !success?
45
- end
46
-
47
- def not_failure?
48
- !failure?
49
- end
50
-
51
- def not_error?
52
- !error?
53
- end
54
-
55
- def to_s
56
- @to_s ||= value.to_s
57
- end
58
-
59
- def to_sym
60
- @to_sym ||= value.to_sym
61
- end
62
- end
63
- end
64
- end
65
- end
66
- end
67
- end
68
- end
69
- end
@@ -1,25 +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 Errors
10
- class NotExistingAttribute < ConvenientService::Error
11
- def initialize(attribute:)
12
- message = <<~TEXT
13
- Data attribute `#{attribute}` does NOT exist. Make sure the corresponding result returns it.
14
- TEXT
15
-
16
- super(message)
17
- end
18
- end
19
- end
20
- end
21
- end
22
- end
23
- end
24
- end
25
- end
@@ -1,17 +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 Structs
10
- ResultParams = ::Struct.new(:service, :status, :data, :message, :code, keyword_init: true)
11
- end
12
- end
13
- end
14
- end
15
- end
16
- end
17
- end
@@ -1,3 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "structs/result_params"