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.
- checksums.yaml +4 -4
- data/.gem_release.yml +0 -12
- data/.github/issue_template.md +35 -0
- data/.github/pull_request_template.md +31 -0
- data/.github/workflows/cd.yml +15 -2
- data/CHANGELOG.md +18 -0
- data/README.md +12 -3
- data/ROADMAP.md +19 -8
- data/Taskfile.yml +2 -10
- data/lib/convenient_service/common/plugins/caches_return_value/middleware.rb +17 -2
- data/lib/convenient_service/common/plugins/caches_return_value.rb +0 -1
- data/lib/convenient_service/common/plugins/has_constructor/concern.rb +13 -0
- data/lib/convenient_service/common/plugins/has_constructor_without_initialize/concern.rb +27 -0
- data/lib/convenient_service/common/plugins/has_constructor_without_initialize.rb +3 -0
- data/lib/convenient_service/common/plugins/has_internals/entities/internals/plugins/has_cache/concern.rb +8 -4
- data/lib/convenient_service/common/plugins/has_internals/entities/internals/plugins/has_cache.rb +0 -1
- data/lib/convenient_service/common/plugins.rb +1 -0
- data/lib/convenient_service/configs/standard.rb +16 -0
- data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/container/commands/cast_container.rb +0 -2
- data/lib/convenient_service/dependencies.rb +1 -0
- data/lib/convenient_service/examples/dry/gemfile.rb +5 -4
- data/lib/convenient_service/examples/rails/gemfile.rb +5 -4
- data/lib/convenient_service/examples/standard/cowsay/services/build_cloud.rb +42 -0
- data/lib/convenient_service/examples/standard/cowsay/services/build_cow.rb +38 -0
- data/lib/convenient_service/examples/standard/cowsay/services/print.rb +32 -0
- data/lib/convenient_service/examples/standard/cowsay/services.rb +5 -0
- data/lib/convenient_service/examples/standard/cowsay.rb +24 -0
- data/lib/convenient_service/examples/standard/gemfile/services/format.rb +2 -0
- data/lib/convenient_service/examples/standard/gemfile.rb +5 -4
- data/lib/convenient_service/rspec/helpers/custom/stub_service/entities/result_spec.rb +96 -7
- data/lib/convenient_service/rspec/helpers/custom/wrap_method/entities/wrapped_method.rb +44 -8
- data/lib/convenient_service/rspec/helpers/custom/wrap_method/errors.rb +11 -9
- data/lib/convenient_service/rspec/matchers/custom/call_chain_next.rb +2 -0
- data/lib/convenient_service/rspec/matchers/custom/results/be_success.rb +6 -0
- data/lib/convenient_service/service/plugins/aliases.rb +1 -0
- data/lib/convenient_service/service/plugins/has_inspect/concern.rb +23 -0
- data/lib/convenient_service/service/plugins/has_inspect.rb +3 -0
- data/lib/convenient_service/service/plugins/has_result/commands/create_result_class.rb +10 -0
- data/lib/convenient_service/service/plugins/has_result/concern/class_methods.rb +23 -14
- data/lib/convenient_service/service/plugins/has_result/concern/instance_methods.rb +17 -1
- data/lib/convenient_service/service/plugins/has_result/entities/result/concern.rb +4 -3
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_inspect/concern.rb +31 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_inspect.rb +3 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/commands/cast_jsend_attributes.rb +37 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/commands.rb +3 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/concern/instance_methods.rb +115 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/concern.rb +27 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/code/class_methods.rb +34 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/code.rb +49 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/data/class_methods.rb +32 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/data.rb +49 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/message/class_methods.rb +34 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/message.rb +45 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/status/class_methods.rb +34 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/status.rb +73 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/{entities.rb → plugins/has_jsend_status_and_attributes/entities.rb} +0 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/errors.rb +29 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/middleware.rb +31 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/structs/jsend_attributes.rb +21 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/structs.rb +3 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes.rb +8 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins.rb +2 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result.rb +0 -4
- data/lib/convenient_service/service/plugins/has_result_method_steps/middleware.rb +1 -1
- data/lib/convenient_service/service/plugins/has_result_method_steps/services/method_step_config.rb +30 -4
- data/lib/convenient_service/service/plugins/has_result_status_check_short_syntax/concern.rb +63 -0
- data/lib/convenient_service/service/plugins/has_result_status_check_short_syntax.rb +3 -0
- data/lib/convenient_service/service/plugins/has_result_steps/concern.rb +2 -1
- data/lib/convenient_service/service/plugins/has_result_steps/entities/step/plugins/has_inspect/concern.rb +31 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/step/plugins/has_inspect.rb +3 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/step/plugins.rb +3 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/step.rb +1 -0
- data/lib/convenient_service/service/plugins.rb +2 -0
- data/lib/convenient_service/support/cache/key.rb +100 -0
- data/lib/convenient_service/support/cache.rb +131 -0
- data/lib/convenient_service/support/copyable.rb +3 -2
- data/lib/convenient_service/support/delegate.rb +3 -2
- data/lib/convenient_service/support.rb +1 -0
- data/lib/convenient_service/version.rb +1 -1
- data/logo.png +0 -0
- metadata +40 -21
- data/lib/convenient_service/common/plugins/caches_return_value/entities/key.rb +0 -79
- data/lib/convenient_service/common/plugins/caches_return_value/entities.rb +0 -3
- data/lib/convenient_service/common/plugins/has_internals/entities/internals/plugins/has_cache/entities/cache.rb +0 -81
- data/lib/convenient_service/common/plugins/has_internals/entities/internals/plugins/has_cache/entities.rb +0 -3
- data/lib/convenient_service/service/plugins/has_result/entities/result/commands/cast_result_params.rb +0 -33
- data/lib/convenient_service/service/plugins/has_result/entities/result/commands.rb +0 -3
- data/lib/convenient_service/service/plugins/has_result/entities/result/concern/instance_methods.rb +0 -64
- data/lib/convenient_service/service/plugins/has_result/entities/result/entities/code/class_methods.rb +0 -30
- data/lib/convenient_service/service/plugins/has_result/entities/result/entities/code.rb +0 -45
- data/lib/convenient_service/service/plugins/has_result/entities/result/entities/data/class_methods.rb +0 -28
- data/lib/convenient_service/service/plugins/has_result/entities/result/entities/data.rb +0 -45
- data/lib/convenient_service/service/plugins/has_result/entities/result/entities/message/class_methods.rb +0 -30
- data/lib/convenient_service/service/plugins/has_result/entities/result/entities/message.rb +0 -41
- data/lib/convenient_service/service/plugins/has_result/entities/result/entities/status/class_methods.rb +0 -30
- data/lib/convenient_service/service/plugins/has_result/entities/result/entities/status.rb +0 -69
- data/lib/convenient_service/service/plugins/has_result/entities/result/errors.rb +0 -25
- data/lib/convenient_service/service/plugins/has_result/entities/result/structs/result_params.rb +0 -17
- data/lib/convenient_service/service/plugins/has_result/entities/result/structs.rb +0 -3
@@ -0,0 +1,115 @@
|
|
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
|
+
def service
|
53
|
+
internals.cache[:jsend_attributes].service
|
54
|
+
end
|
55
|
+
|
56
|
+
##
|
57
|
+
# @return [ConvenientService::Service::Plugins::HasResult::Entities::Result::Plugins::HasJsendStatusAndAttributes::Entities::Status]
|
58
|
+
#
|
59
|
+
def status
|
60
|
+
internals.cache[:jsend_attributes].status
|
61
|
+
end
|
62
|
+
|
63
|
+
##
|
64
|
+
# @return [ConvenientService::Service::Plugins::HasResult::Entities::Result::Plugins::HasJsendStatusAndAttributes::Entities::Data]
|
65
|
+
#
|
66
|
+
def data
|
67
|
+
internals.cache[:jsend_attributes].data
|
68
|
+
end
|
69
|
+
|
70
|
+
##
|
71
|
+
# @return [ConvenientService::Service::Plugins::HasResult::Entities::Result::Plugins::HasJsendStatusAndAttributes::Entities::Message]
|
72
|
+
#
|
73
|
+
def message
|
74
|
+
internals.cache[:jsend_attributes].message
|
75
|
+
end
|
76
|
+
|
77
|
+
##
|
78
|
+
# @return [ConvenientService::Service::Plugins::HasResult::Entities::Result::Plugins::HasJsendStatusAndAttributes::Entities::Code]
|
79
|
+
#
|
80
|
+
def code
|
81
|
+
internals.cache[:jsend_attributes].code
|
82
|
+
end
|
83
|
+
|
84
|
+
##
|
85
|
+
# @param other [ConvenientService::Service::Plugins::HasResult::Entities::Result]
|
86
|
+
# @return [Boolean, nil]
|
87
|
+
#
|
88
|
+
def ==(other)
|
89
|
+
return unless other.instance_of?(self.class)
|
90
|
+
|
91
|
+
return false if service.class != other.service.class
|
92
|
+
return false if status != other.status
|
93
|
+
return false if data != other.data
|
94
|
+
return false if message != other.message
|
95
|
+
return false if code != other.code
|
96
|
+
|
97
|
+
true
|
98
|
+
end
|
99
|
+
|
100
|
+
##
|
101
|
+
# @return [Hash]
|
102
|
+
#
|
103
|
+
def to_kwargs
|
104
|
+
{service: service, status: status, data: data, message: message, code: code}
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
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
|
@@ -0,0 +1,45 @@
|
|
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 Plugins
|
12
|
+
module HasJsendStatusAndAttributes
|
13
|
+
module Entities
|
14
|
+
class Message
|
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
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
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 Status
|
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 Status
|
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,73 @@
|
|
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 Plugins
|
12
|
+
module HasJsendStatusAndAttributes
|
13
|
+
module Entities
|
14
|
+
class Status
|
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 success?
|
34
|
+
value == :success
|
35
|
+
end
|
36
|
+
|
37
|
+
def failure?
|
38
|
+
value == :failure
|
39
|
+
end
|
40
|
+
|
41
|
+
def error?
|
42
|
+
value == :error
|
43
|
+
end
|
44
|
+
|
45
|
+
def not_success?
|
46
|
+
!success?
|
47
|
+
end
|
48
|
+
|
49
|
+
def not_failure?
|
50
|
+
!failure?
|
51
|
+
end
|
52
|
+
|
53
|
+
def not_error?
|
54
|
+
!error?
|
55
|
+
end
|
56
|
+
|
57
|
+
def to_s
|
58
|
+
@to_s ||= value.to_s
|
59
|
+
end
|
60
|
+
|
61
|
+
def to_sym
|
62
|
+
@to_sym ||= value.to_sym
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
File without changes
|
@@ -0,0 +1,29 @@
|
|
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 Errors
|
12
|
+
class NotExistingAttribute < ConvenientService::Error
|
13
|
+
def initialize(attribute:)
|
14
|
+
message = <<~TEXT
|
15
|
+
Data attribute `#{attribute}` does NOT exist. Make sure the corresponding result returns it.
|
16
|
+
TEXT
|
17
|
+
|
18
|
+
super(message)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
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 HasJsendStatusAndAttributes
|
11
|
+
class Middleware < Core::MethodChainMiddleware
|
12
|
+
##
|
13
|
+
# @param args [Array]
|
14
|
+
# @param kwargs [Hash]
|
15
|
+
# @param block [Proc]
|
16
|
+
# @return [void]
|
17
|
+
#
|
18
|
+
def next(*args, **kwargs, &block)
|
19
|
+
entity.internals.cache[:jsend_attributes] = Commands::CastJSendAttributes.call(attributes: kwargs)
|
20
|
+
|
21
|
+
chain.next(*args, **kwargs, &block)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,21 @@
|
|
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 Structs
|
12
|
+
JSendAttributes = ::Struct.new(:service, :status, :data, :message, :code, keyword_init: true)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "has_jsend_status_and_attributes/commands"
|
4
|
+
require_relative "has_jsend_status_and_attributes/concern"
|
5
|
+
require_relative "has_jsend_status_and_attributes/entities"
|
6
|
+
require_relative "has_jsend_status_and_attributes/errors"
|
7
|
+
require_relative "has_jsend_status_and_attributes/middleware"
|
8
|
+
require_relative "has_jsend_status_and_attributes/structs"
|
@@ -1,6 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative "plugins/can_recalculate_result"
|
4
|
+
require_relative "plugins/has_jsend_status_and_attributes"
|
5
|
+
require_relative "plugins/has_inspect"
|
4
6
|
require_relative "plugins/has_result_short_syntax"
|
5
7
|
require_relative "plugins/marks_result_status_as_checked"
|
6
8
|
require_relative "plugins/raises_on_not_checked_result_status"
|
@@ -1,11 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "result/commands"
|
4
3
|
require_relative "result/concern"
|
5
|
-
require_relative "result/entities"
|
6
|
-
require_relative "result/errors"
|
7
4
|
require_relative "result/plugins"
|
8
|
-
require_relative "result/structs"
|
9
5
|
|
10
6
|
module ConvenientService
|
11
7
|
module Service
|
@@ -17,7 +17,7 @@ module ConvenientService
|
|
17
17
|
|
18
18
|
kwargs[:in] = Utils::Array.wrap(kwargs[:in]) + [{method_name: raw(args.first)}, {organizer: :itself}]
|
19
19
|
|
20
|
-
args[0] = args.first == :result ? Services::RunOwnMethodInOrganizer : Services::RunMethodInOrganizer
|
20
|
+
args[0] = (args.first == :result) ? Services::RunOwnMethodInOrganizer : Services::RunMethodInOrganizer
|
21
21
|
|
22
22
|
chain.next(*args, **kwargs, &block)
|
23
23
|
end
|
data/lib/convenient_service/service/plugins/has_result_method_steps/services/method_step_config.rb
CHANGED
@@ -8,19 +8,45 @@ module ConvenientService
|
|
8
8
|
module MethodStepConfig
|
9
9
|
include Support::Concern
|
10
10
|
|
11
|
+
# rubocop:disable Lint/ConstantDefinitionInBlock
|
11
12
|
included do
|
12
|
-
include Core
|
13
|
+
include ConvenientService::Core
|
13
14
|
|
14
15
|
concerns do
|
15
|
-
use Service::Plugins::HasResult::Concern
|
16
|
+
use ConvenientService::Service::Plugins::HasResult::Concern
|
16
17
|
end
|
17
18
|
|
18
19
|
middlewares :result do
|
19
|
-
use Common::Plugins::NormalizesEnv::Middleware
|
20
|
+
use ConvenientService::Common::Plugins::NormalizesEnv::Middleware
|
20
21
|
|
21
|
-
use Service::Plugins::HasResult::Middleware
|
22
|
+
use ConvenientService::Service::Plugins::HasResult::Middleware
|
23
|
+
end
|
24
|
+
|
25
|
+
class self::Result
|
26
|
+
include ConvenientService::Core
|
27
|
+
|
28
|
+
concerns do
|
29
|
+
use ConvenientService::Common::Plugins::HasInternals::Concern
|
30
|
+
use ConvenientService::Common::Plugins::HasConstructor::Concern
|
31
|
+
use ConvenientService::Service::Plugins::HasResult::Entities::Result::Plugins::HasJsendStatusAndAttributes::Concern
|
32
|
+
end
|
33
|
+
|
34
|
+
middlewares :initialize do
|
35
|
+
use ConvenientService::Common::Plugins::NormalizesEnv::Middleware
|
36
|
+
|
37
|
+
use ConvenientService::Service::Plugins::HasResult::Entities::Result::Plugins::HasJsendStatusAndAttributes::Middleware
|
38
|
+
end
|
39
|
+
|
40
|
+
class self::Internals
|
41
|
+
include ConvenientService::Core
|
42
|
+
|
43
|
+
concerns do
|
44
|
+
use ConvenientService::Common::Plugins::HasInternals::Entities::Internals::Plugins::HasCache::Concern
|
45
|
+
end
|
46
|
+
end
|
22
47
|
end
|
23
48
|
end
|
49
|
+
# rubocop:enable Lint/ConstantDefinitionInBlock
|
24
50
|
end
|
25
51
|
end
|
26
52
|
end
|