convenient_service 0.1.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) 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/.github/workflows/ci.yml +6 -6
  7. data/CHANGELOG.md +27 -0
  8. data/README.md +12 -3
  9. data/ROADMAP.md +22 -8
  10. data/Taskfile.yml +5 -13
  11. data/env.rb +4 -0
  12. data/lib/convenient_service/common/plugins/caches_return_value/middleware.rb +17 -2
  13. data/lib/convenient_service/common/plugins/caches_return_value.rb +0 -1
  14. data/lib/convenient_service/common/plugins/has_constructor/concern.rb +13 -0
  15. data/lib/convenient_service/common/plugins/has_constructor_without_initialize/concern.rb +27 -0
  16. data/lib/convenient_service/common/plugins/has_constructor_without_initialize.rb +3 -0
  17. data/lib/convenient_service/common/plugins/has_internals/entities/internals/plugins/has_cache/concern.rb +8 -4
  18. data/lib/convenient_service/common/plugins/has_internals/entities/internals/plugins/has_cache.rb +0 -1
  19. data/lib/convenient_service/common/plugins.rb +1 -0
  20. data/lib/convenient_service/configs/standard.rb +16 -0
  21. data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/container/commands/cast_container.rb +0 -2
  22. data/lib/convenient_service/dependencies.rb +1 -0
  23. data/lib/convenient_service/examples/dry/gemfile/dry_service/config.rb +3 -1
  24. data/lib/convenient_service/examples/dry/gemfile/services/assert_file_exists.rb +1 -1
  25. data/lib/convenient_service/examples/dry/gemfile/services/assert_file_not_empty.rb +1 -1
  26. data/lib/convenient_service/examples/dry/gemfile/services/assert_npm_package_available.rb +1 -1
  27. data/lib/convenient_service/examples/dry/gemfile/services/parse_content.rb +1 -1
  28. data/lib/convenient_service/examples/dry/gemfile/services/print_shell_command.rb +1 -1
  29. data/lib/convenient_service/examples/dry/gemfile/services/read_file_content.rb +1 -1
  30. data/lib/convenient_service/examples/dry/gemfile/services/run_shell.rb +1 -1
  31. data/lib/convenient_service/examples/dry/gemfile/services/strip_comments.rb +1 -1
  32. data/lib/convenient_service/examples/dry/gemfile.rb +5 -4
  33. data/lib/convenient_service/examples/rails/gemfile/rails_service/config.rb +3 -1
  34. data/lib/convenient_service/examples/rails/gemfile.rb +5 -4
  35. data/lib/convenient_service/examples/standard/cowsay/services/build_cloud.rb +42 -0
  36. data/lib/convenient_service/examples/standard/cowsay/services/build_cow.rb +38 -0
  37. data/lib/convenient_service/examples/standard/cowsay/services/print.rb +32 -0
  38. data/lib/convenient_service/examples/standard/cowsay/services.rb +5 -0
  39. data/lib/convenient_service/examples/standard/cowsay.rb +24 -0
  40. data/lib/convenient_service/examples/standard/gemfile/services/format.rb +2 -0
  41. data/lib/convenient_service/examples/standard/gemfile.rb +5 -4
  42. data/lib/convenient_service/rspec/helpers/custom/stub_service/entities/result_spec.rb +96 -7
  43. data/lib/convenient_service/rspec/helpers/custom/wrap_method/entities/wrapped_method.rb +44 -8
  44. data/lib/convenient_service/rspec/helpers/custom/wrap_method/errors.rb +11 -9
  45. data/lib/convenient_service/rspec/matchers/custom/cache_its_value.rb +7 -7
  46. data/lib/convenient_service/rspec/matchers/custom/call_chain_next.rb +2 -0
  47. data/lib/convenient_service/rspec/matchers/custom/delegate_to.rb +50 -12
  48. data/lib/convenient_service/rspec/matchers/custom/results/be_success.rb +6 -0
  49. data/lib/convenient_service/service/plugins/aliases.rb +1 -0
  50. data/lib/convenient_service/service/plugins/has_inspect/concern.rb +23 -0
  51. data/lib/convenient_service/service/plugins/has_inspect.rb +3 -0
  52. data/lib/convenient_service/service/plugins/has_result/commands/create_result_class.rb +10 -0
  53. data/lib/convenient_service/service/plugins/has_result/concern/class_methods.rb +23 -14
  54. data/lib/convenient_service/service/plugins/has_result/concern/instance_methods.rb +17 -1
  55. data/lib/convenient_service/service/plugins/has_result/entities/result/concern.rb +4 -3
  56. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_inspect/concern.rb +31 -0
  57. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_inspect.rb +3 -0
  58. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/commands/cast_jsend_attributes.rb +37 -0
  59. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/commands.rb +3 -0
  60. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/concern/instance_methods.rb +127 -0
  61. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/concern.rb +27 -0
  62. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/code/class_methods.rb +34 -0
  63. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/code.rb +49 -0
  64. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/data/class_methods.rb +32 -0
  65. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/data.rb +49 -0
  66. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/message/class_methods.rb +34 -0
  67. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/message.rb +45 -0
  68. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/status/class_methods.rb +34 -0
  69. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/status.rb +73 -0
  70. data/lib/convenient_service/service/plugins/has_result/entities/result/{entities.rb → plugins/has_jsend_status_and_attributes/entities.rb} +0 -0
  71. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/errors.rb +29 -0
  72. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/middleware.rb +31 -0
  73. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/structs/jsend_attributes.rb +21 -0
  74. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/structs.rb +3 -0
  75. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes.rb +8 -0
  76. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins.rb +2 -0
  77. data/lib/convenient_service/service/plugins/has_result/entities/result.rb +0 -4
  78. data/lib/convenient_service/service/plugins/has_result_method_steps/middleware.rb +1 -1
  79. data/lib/convenient_service/service/plugins/has_result_method_steps/services/method_step_config.rb +30 -4
  80. data/lib/convenient_service/service/plugins/has_result_params_validations/using_dry_validation/middleware.rb +19 -9
  81. data/lib/convenient_service/service/plugins/has_result_status_check_short_syntax/concern.rb +63 -0
  82. data/lib/convenient_service/service/plugins/has_result_status_check_short_syntax.rb +3 -0
  83. data/lib/convenient_service/service/plugins/has_result_steps/concern.rb +2 -1
  84. data/lib/convenient_service/service/plugins/has_result_steps/entities/step/plugins/has_inspect/concern.rb +31 -0
  85. data/lib/convenient_service/service/plugins/has_result_steps/entities/step/plugins/has_inspect.rb +3 -0
  86. data/lib/convenient_service/service/plugins/has_result_steps/entities/step/plugins.rb +3 -0
  87. data/lib/convenient_service/service/plugins/has_result_steps/entities/step.rb +1 -0
  88. data/lib/convenient_service/service/plugins/has_result_steps/middleware.rb +1 -1
  89. data/lib/convenient_service/service/plugins.rb +2 -0
  90. data/lib/convenient_service/support/cache/key.rb +100 -0
  91. data/lib/convenient_service/support/cache.rb +131 -0
  92. data/lib/convenient_service/support/copyable.rb +3 -2
  93. data/lib/convenient_service/support/delegate.rb +3 -2
  94. data/lib/convenient_service/support.rb +1 -0
  95. data/lib/convenient_service/version.rb +1 -1
  96. data/logo.png +0 -0
  97. metadata +40 -21
  98. data/lib/convenient_service/common/plugins/caches_return_value/entities/key.rb +0 -79
  99. data/lib/convenient_service/common/plugins/caches_return_value/entities.rb +0 -3
  100. data/lib/convenient_service/common/plugins/has_internals/entities/internals/plugins/has_cache/entities/cache.rb +0 -81
  101. data/lib/convenient_service/common/plugins/has_internals/entities/internals/plugins/has_cache/entities.rb +0 -3
  102. data/lib/convenient_service/service/plugins/has_result/entities/result/commands/cast_result_params.rb +0 -33
  103. data/lib/convenient_service/service/plugins/has_result/entities/result/commands.rb +0 -3
  104. data/lib/convenient_service/service/plugins/has_result/entities/result/concern/instance_methods.rb +0 -64
  105. data/lib/convenient_service/service/plugins/has_result/entities/result/entities/code/class_methods.rb +0 -30
  106. data/lib/convenient_service/service/plugins/has_result/entities/result/entities/code.rb +0 -45
  107. data/lib/convenient_service/service/plugins/has_result/entities/result/entities/data/class_methods.rb +0 -28
  108. data/lib/convenient_service/service/plugins/has_result/entities/result/entities/data.rb +0 -45
  109. data/lib/convenient_service/service/plugins/has_result/entities/result/entities/message/class_methods.rb +0 -30
  110. data/lib/convenient_service/service/plugins/has_result/entities/result/entities/message.rb +0 -41
  111. data/lib/convenient_service/service/plugins/has_result/entities/result/entities/status/class_methods.rb +0 -30
  112. data/lib/convenient_service/service/plugins/has_result/entities/result/entities/status.rb +0 -69
  113. data/lib/convenient_service/service/plugins/has_result/entities/result/errors.rb +0 -25
  114. data/lib/convenient_service/service/plugins/has_result/entities/result/structs/result_params.rb +0 -17
  115. data/lib/convenient_service/service/plugins/has_result/entities/result/structs.rb +0 -3
@@ -27,6 +27,12 @@ module ConvenientService
27
27
  self
28
28
  end
29
29
 
30
+ def without_data
31
+ chain[:data] = {}
32
+
33
+ self
34
+ end
35
+
30
36
  def of(service_class)
31
37
  chain[:service_class] = service_class
32
38
 
@@ -4,5 +4,6 @@ module ConvenientService
4
4
  module Plugins
5
5
  Result = ::ConvenientService::Service::Plugins::HasResult::Entities::Result::Plugins
6
6
  Service = ::ConvenientService::Service::Plugins
7
+ Step = ::ConvenientService::Service::Plugins::HasResultSteps::Entities::Step::Plugins
7
8
  end
8
9
  end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ConvenientService
4
+ module Service
5
+ module Plugins
6
+ module HasInspect
7
+ module Concern
8
+ include Support::Concern
9
+
10
+ instance_methods do
11
+ ##
12
+ # @return [String]
13
+ # @since 0.2.0
14
+ #
15
+ def inspect
16
+ "<#{self.class.name}>"
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "has_inspect/concern"
@@ -8,10 +8,17 @@ module ConvenientService
8
8
  class CreateResultClass < Support::Command
9
9
  attr_reader :service_class
10
10
 
11
+ ##
12
+ # @param service_class [Class]
13
+ # @return [void]
14
+ #
11
15
  def initialize(service_class:)
12
16
  @service_class = service_class
13
17
  end
14
18
 
19
+ ##
20
+ # @return [void]
21
+ #
15
22
  def call
16
23
  result_class.include Entities::Result::Concern
17
24
 
@@ -45,6 +52,9 @@ module ConvenientService
45
52
 
46
53
  private
47
54
 
55
+ ##
56
+ # @return [Class]
57
+ #
48
58
  def result_class
49
59
  @result_class ||= Utils::Module.get_own_const(service_class, :Result) || ::Class.new(Entities::Result)
50
60
  end
@@ -7,28 +7,25 @@ module ConvenientService
7
7
  module Concern
8
8
  module ClassMethods
9
9
  ##
10
- #
10
+ # @api public
11
+ # @return [ConvenientService::Service::Plugins::HasResult::Entities::Result]
11
12
  #
12
13
  def result(...)
13
14
  new(...).result
14
15
  end
15
16
 
16
17
  ##
17
- # https://ruby-doc.org/core-2.5.0/Class.html#method-i-allocate
18
- # https://frontdeveloper.pl/2018/11/ruby-allocate-method/
18
+ # @api private
19
+ # @return [ConvenientService::Service::Plugins::HasResult::Entities::Result]
19
20
  #
20
- def new_without_initialize
21
- allocate
22
- end
23
-
24
- ##
25
- # NOTE: This method is internally used by custom RSpec helper `stub_service`. It should NOT be used in the client code.
21
+ # @internal
22
+ # NOTE: This method is internally used by custom RSpec helper `stub_service`. It should NOT be used in the client code.
26
23
  #
27
24
  def success(
28
25
  service: Constants::DEFAULT_SERVICE_INSTANCE,
29
26
  data: Constants::DEFAULT_SUCCESS_DATA
30
27
  )
31
- result_class.new(
28
+ result_class.create(
32
29
  service: service,
33
30
  status: Constants::SUCCESS_STATUS,
34
31
  data: data,
@@ -38,14 +35,18 @@ module ConvenientService
38
35
  end
39
36
 
40
37
  ##
41
- # NOTE: This method is internally used by custom RSpec helper `stub_service`. It should NOT be used in the client code.
38
+ # @api private
39
+ # @return [ConvenientService::Service::Plugins::HasResult::Entities::Result]
40
+ #
41
+ # @internal
42
+ # NOTE: This method is internally used by custom RSpec helper `stub_service`. It should NOT be used in the client code.
42
43
  #
43
44
  def failure(
44
45
  service: Constants::DEFAULT_SERVICE_INSTANCE,
45
46
  data: Constants::DEFAULT_FAILURE_DATA,
46
47
  message: data.any? ? data.first.join(" ") : Constants::DEFAULT_FAILURE_MESSAGE
47
48
  )
48
- result_class.new(
49
+ result_class.create(
49
50
  service: service,
50
51
  status: Constants::FAILURE_STATUS,
51
52
  data: data,
@@ -55,14 +56,18 @@ module ConvenientService
55
56
  end
56
57
 
57
58
  ##
58
- # NOTE: This method is internally used by custom RSpec helper `stub_service`. It should NOT be used in the client code.
59
+ # @api private
60
+ # @return [ConvenientService::Service::Plugins::HasResult::Entities::Result]
61
+ #
62
+ # @internal
63
+ # NOTE: This method is internally used by custom RSpec helper `stub_service`. It should NOT be used in the client code.
59
64
  #
60
65
  def error(
61
66
  service: Constants::DEFAULT_SERVICE_INSTANCE,
62
67
  message: Constants::DEFAULT_ERROR_MESSAGE,
63
68
  code: Constants::DEFAULT_ERROR_CODE
64
69
  )
65
- result_class.new(
70
+ result_class.create(
66
71
  service: service,
67
72
  status: Constants::ERROR_STATUS,
68
73
  data: Constants::ERROR_DATA,
@@ -71,6 +76,10 @@ module ConvenientService
71
76
  )
72
77
  end
73
78
 
79
+ ##
80
+ # @api private
81
+ # @return [Class]
82
+ #
74
83
  def result_class
75
84
  @result_class ||= Commands::CreateResultClass.call(service_class: self)
76
85
  end
@@ -6,21 +6,37 @@ module ConvenientService
6
6
  module HasResult
7
7
  module Concern
8
8
  module InstanceMethods
9
+ ##
10
+ # @api public
11
+ # @raise [ConvenientService::Service::Plugins::HasResult::Errors::ResultIsNotOverridden]
12
+ #
9
13
  def result
10
14
  raise Errors::ResultIsNotOverridden.new(service: self)
11
15
  end
12
16
 
13
17
  ##
14
- # TODO: Specs.
18
+ # @api public
19
+ # @param kwargs [Hash]
20
+ # @return [ConvenientService::Service::Plugins::HasResult::Entities::Result]
15
21
  #
16
22
  def success(**kwargs)
17
23
  self.class.success(**kwargs.merge(service: self))
18
24
  end
19
25
 
26
+ ##
27
+ # @api public
28
+ # @param kwargs [Hash]
29
+ # @return [ConvenientService::Service::Plugins::HasResult::Entities::Result]
30
+ #
20
31
  def failure(**kwargs)
21
32
  self.class.failure(**kwargs.merge(service: self))
22
33
  end
23
34
 
35
+ ##
36
+ # @api public
37
+ # @param kwargs [Hash]
38
+ # @return [ConvenientService::Service::Plugins::HasResult::Entities::Result]
39
+ #
24
40
  def error(**kwargs)
25
41
  self.class.error(**kwargs.merge(service: self))
26
42
  end
@@ -1,15 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "concern/instance_methods"
4
-
5
3
  module ConvenientService
6
4
  module Service
7
5
  module Plugins
8
6
  module HasResult
9
7
  module Entities
10
8
  class Result
9
+ ##
10
+ # @internal
11
+ # This concern is needed for `CastResultClass` and `be_success`, `be_error`, `be_failure` matchers.
12
+ #
11
13
  module Concern
12
- include Support::Concern
13
14
  end
14
15
  end
15
16
  end
@@ -0,0 +1,31 @@
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 HasInspect
11
+ module Concern
12
+ include Support::Concern
13
+
14
+ instance_methods do
15
+ ##
16
+ # @return [String]
17
+ # @since 0.2.0
18
+ #
19
+ def inspect
20
+ "<#{service.class.name}::Result status: :#{status}>"
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "has_inspect/concern"
@@ -0,0 +1,37 @@
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 HasJsendStatusAndAttributes
11
+ module Commands
12
+ class CastJSendAttributes < Support::Command
13
+ attr_reader :attributes
14
+
15
+ def initialize(attributes:)
16
+ @attributes = attributes
17
+ end
18
+
19
+ def call
20
+ Structs::JSendAttributes.new(
21
+ service: attributes[:service],
22
+ status: Entities::Status.cast!(attributes[:status]),
23
+ data: Entities::Data.cast!(attributes[:data]),
24
+ message: Entities::Message.cast!(attributes[:message]),
25
+ code: Entities::Code.cast!(attributes[:code])
26
+ )
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "commands/cast_jsend_attributes"
@@ -0,0 +1,127 @@
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 HasJsendStatusAndAttributes
11
+ module Concern
12
+ ##
13
+ # TODO: How to use concern outside?
14
+ #
15
+ module InstanceMethods
16
+ include Support::Delegate
17
+ include Support::Copyable
18
+
19
+ ##
20
+ # @return [Boolean]
21
+ #
22
+ delegate :success?, to: :status
23
+
24
+ ##
25
+ # @return [Boolean]
26
+ #
27
+ delegate :failure?, to: :status
28
+
29
+ ##
30
+ # @return [Boolean]
31
+ #
32
+ delegate :error?, to: :status
33
+
34
+ ##
35
+ # @return [Boolean]
36
+ #
37
+ delegate :not_success?, to: :status
38
+
39
+ ##
40
+ # @return [Boolean]
41
+ #
42
+ delegate :not_failure?, to: :status
43
+
44
+ ##
45
+ # @return [Boolean]
46
+ #
47
+ delegate :not_error?, to: :status
48
+
49
+ ##
50
+ # @return [Class]
51
+ #
52
+ delegate :service, to: :jsend_attributes
53
+
54
+ ##
55
+ # @return [ConvenientService::Service::Plugins::HasResult::Entities::Result::Plugins::HasJsendStatusAndAttributes::Entities::Status]
56
+ #
57
+ delegate :status, to: :jsend_attributes
58
+
59
+ ##
60
+ # @return [ConvenientService::Service::Plugins::HasResult::Entities::Result::Plugins::HasJsendStatusAndAttributes::Entities::Data]
61
+ #
62
+ delegate :data, to: :jsend_attributes
63
+
64
+ ##
65
+ # @return [ConvenientService::Service::Plugins::HasResult::Entities::Result::Plugins::HasJsendStatusAndAttributes::Entities::Data]
66
+ #
67
+ alias_method :unsafe_data, :data
68
+
69
+ ##
70
+ # @return [ConvenientService::Service::Plugins::HasResult::Entities::Result::Plugins::HasJsendStatusAndAttributes::Entities::Message]
71
+ #
72
+ delegate :message, to: :jsend_attributes
73
+
74
+ ##
75
+ # @return [ConvenientService::Service::Plugins::HasResult::Entities::Result::Plugins::HasJsendStatusAndAttributes::Entities::Message]
76
+ #
77
+ alias_method :unsafe_message, :message
78
+
79
+ ##
80
+ # @return [ConvenientService::Service::Plugins::HasResult::Entities::Result::Plugins::HasJsendStatusAndAttributes::Entities::Code]
81
+ #
82
+ delegate :code, to: :jsend_attributes
83
+
84
+ ##
85
+ # @return [ConvenientService::Service::Plugins::HasResult::Entities::Result::Plugins::HasJsendStatusAndAttributes::Entities::Code]
86
+ #
87
+ alias_method :unsafe_code, :code
88
+
89
+ ##
90
+ # @return [ConvenientService::Service::Plugins::HasResult::Entities::Result::Plugins::HasJsendStatusAndAttributes::Structs::JSendAttributes]
91
+ #
92
+ def jsend_attributes
93
+ internals.cache[:jsend_attributes]
94
+ end
95
+
96
+ ##
97
+ # @param other [ConvenientService::Service::Plugins::HasResult::Entities::Result]
98
+ # @return [Boolean, nil]
99
+ #
100
+ def ==(other)
101
+ return unless other.instance_of?(self.class)
102
+
103
+ return false if service.class != other.service.class
104
+ return false if status != other.status
105
+ return false if unsafe_data != other.unsafe_data
106
+ return false if unsafe_message != other.unsafe_message
107
+ return false if unsafe_code != other.unsafe_code
108
+
109
+ true
110
+ end
111
+
112
+ ##
113
+ # @return [Hash]
114
+ #
115
+ def to_kwargs
116
+ {service: service, status: status, data: data, message: message, code: code}
117
+ end
118
+ end
119
+ end
120
+ end
121
+ end
122
+ end
123
+ end
124
+ end
125
+ end
126
+ end
127
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "concern/instance_methods"
4
+
5
+ module ConvenientService
6
+ module Service
7
+ module Plugins
8
+ module HasResult
9
+ module Entities
10
+ class Result
11
+ module Plugins
12
+ module HasJsendStatusAndAttributes
13
+ module Concern
14
+ include Support::Concern
15
+
16
+ included do |result_class|
17
+ result_class.include InstanceMethods
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,34 @@
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 HasJsendStatusAndAttributes
11
+ module Entities
12
+ class Code
13
+ module ClassMethods
14
+ def cast(other)
15
+ case other
16
+ when ::String
17
+ new(value: other.to_sym)
18
+ when ::Symbol
19
+ new(value: other)
20
+ when Code
21
+ new(value: other.value)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,49 @@
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 Plugins
12
+ module HasJsendStatusAndAttributes
13
+ module Entities
14
+ class Code
15
+ include Support::Castable
16
+
17
+ extend ClassMethods
18
+
19
+ attr_reader :value
20
+
21
+ def initialize(value:)
22
+ @value = value
23
+ end
24
+
25
+ def ==(other)
26
+ casted = cast(other)
27
+
28
+ return unless casted
29
+
30
+ value == casted.value
31
+ end
32
+
33
+ def to_s
34
+ @to_s ||= value.to_s
35
+ end
36
+
37
+ def to_sym
38
+ @to_sym ||= value.to_sym
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,32 @@
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 HasJsendStatusAndAttributes
11
+ module Entities
12
+ class Data
13
+ module ClassMethods
14
+ def cast(other)
15
+ case other
16
+ when ::Hash
17
+ new(value: other.transform_keys(&:to_sym))
18
+ when Data
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
31
+ end
32
+ end
@@ -0,0 +1,49 @@
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 Plugins
12
+ module HasJsendStatusAndAttributes
13
+ module Entities
14
+ class Data
15
+ include Support::Castable
16
+
17
+ extend ClassMethods
18
+
19
+ attr_reader :value
20
+
21
+ def initialize(value:)
22
+ @value = value
23
+ end
24
+
25
+ def ==(other)
26
+ casted = cast(other)
27
+
28
+ return unless casted
29
+
30
+ value == casted.value
31
+ end
32
+
33
+ def [](key)
34
+ value.fetch(key.to_sym) { raise Errors::NotExistingAttribute.new(attribute: key) }
35
+ end
36
+
37
+ def to_h
38
+ @to_h ||= value.to_h
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,34 @@
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 HasJsendStatusAndAttributes
11
+ module Entities
12
+ class Message
13
+ module ClassMethods
14
+ def cast(other)
15
+ case other
16
+ when ::String
17
+ new(value: other)
18
+ when ::Symbol
19
+ new(value: other.to_s)
20
+ when Message
21
+ new(value: other.value)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end