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.
- 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/.github/workflows/ci.yml +6 -6
- data/CHANGELOG.md +27 -0
- data/README.md +12 -3
- data/ROADMAP.md +22 -8
- data/Taskfile.yml +5 -13
- data/env.rb +4 -0
- 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/dry_service/config.rb +3 -1
- data/lib/convenient_service/examples/dry/gemfile/services/assert_file_exists.rb +1 -1
- data/lib/convenient_service/examples/dry/gemfile/services/assert_file_not_empty.rb +1 -1
- data/lib/convenient_service/examples/dry/gemfile/services/assert_npm_package_available.rb +1 -1
- data/lib/convenient_service/examples/dry/gemfile/services/parse_content.rb +1 -1
- data/lib/convenient_service/examples/dry/gemfile/services/print_shell_command.rb +1 -1
- data/lib/convenient_service/examples/dry/gemfile/services/read_file_content.rb +1 -1
- data/lib/convenient_service/examples/dry/gemfile/services/run_shell.rb +1 -1
- data/lib/convenient_service/examples/dry/gemfile/services/strip_comments.rb +1 -1
- data/lib/convenient_service/examples/dry/gemfile.rb +5 -4
- data/lib/convenient_service/examples/rails/gemfile/rails_service/config.rb +3 -1
- 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/cache_its_value.rb +7 -7
- data/lib/convenient_service/rspec/matchers/custom/call_chain_next.rb +2 -0
- data/lib/convenient_service/rspec/matchers/custom/delegate_to.rb +50 -12
- 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 +127 -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_params_validations/using_dry_validation/middleware.rb +19 -9
- 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/has_result_steps/middleware.rb +1 -1
- 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,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
|
@@ -21,15 +21,25 @@ module ConvenientService
|
|
21
21
|
# TODO: Return one or all errors?
|
22
22
|
#
|
23
23
|
def errors
|
24
|
-
@errors ||=
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
24
|
+
@errors ||= resolve_errors
|
25
|
+
end
|
26
|
+
|
27
|
+
def constructor_kwargs
|
28
|
+
@constructor_kwargs ||= entity.constructor_params.kwargs
|
29
|
+
end
|
30
|
+
|
31
|
+
def contract
|
32
|
+
@contract ||= entity.class.contract
|
33
|
+
end
|
34
|
+
|
35
|
+
def resolve_errors
|
36
|
+
return {} unless contract.schema
|
37
|
+
|
38
|
+
contract.new
|
39
|
+
.call(constructor_kwargs)
|
40
|
+
.errors
|
41
|
+
.to_h
|
42
|
+
.transform_values(&:first)
|
33
43
|
end
|
34
44
|
end
|
35
45
|
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ConvenientService
|
4
|
+
module Service
|
5
|
+
module Plugins
|
6
|
+
module HasResultStatusCheckShortSyntax
|
7
|
+
module Concern
|
8
|
+
include Support::Concern
|
9
|
+
|
10
|
+
class_methods do
|
11
|
+
##
|
12
|
+
# @return [Boolean]
|
13
|
+
# @since 0.2.0
|
14
|
+
#
|
15
|
+
def success?(...)
|
16
|
+
result(...).success?
|
17
|
+
end
|
18
|
+
|
19
|
+
##
|
20
|
+
# @return [Boolean]
|
21
|
+
# @since 0.2.0
|
22
|
+
#
|
23
|
+
def error?(...)
|
24
|
+
result(...).error?
|
25
|
+
end
|
26
|
+
|
27
|
+
##
|
28
|
+
# @return [Boolean]
|
29
|
+
# @since 0.2.0
|
30
|
+
#
|
31
|
+
def failure?(...)
|
32
|
+
result(...).failure?
|
33
|
+
end
|
34
|
+
|
35
|
+
##
|
36
|
+
# @return [Boolean]
|
37
|
+
# @since 0.2.0
|
38
|
+
#
|
39
|
+
def not_success?(...)
|
40
|
+
result(...).not_success?
|
41
|
+
end
|
42
|
+
|
43
|
+
##
|
44
|
+
# @return [Boolean]
|
45
|
+
# @since 0.2.0
|
46
|
+
#
|
47
|
+
def not_error?(...)
|
48
|
+
result(...).not_error?
|
49
|
+
end
|
50
|
+
|
51
|
+
##
|
52
|
+
# @return [Boolean]
|
53
|
+
# @since 0.2.0
|
54
|
+
#
|
55
|
+
def not_failure?(...)
|
56
|
+
result(...).not_failure?
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -9,11 +9,12 @@ module ConvenientService
|
|
9
9
|
|
10
10
|
instance_methods do
|
11
11
|
def steps
|
12
|
-
|
12
|
+
internals.cache.fetch(:steps) do
|
13
13
|
self.class
|
14
14
|
.steps
|
15
15
|
.tap(&:commit!)
|
16
16
|
.map { |step| step.copy(overrides: {kwargs: {organizer: self}}) }
|
17
|
+
end
|
17
18
|
end
|
18
19
|
|
19
20
|
##
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ConvenientService
|
4
|
+
module Service
|
5
|
+
module Plugins
|
6
|
+
module HasResultSteps
|
7
|
+
module Entities
|
8
|
+
class Step
|
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
|
+
"<#{container.klass.name}::Step service: #{service.klass.name}>"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -4,11 +4,13 @@
|
|
4
4
|
# NOTE: Order matters.
|
5
5
|
#
|
6
6
|
require_relative "plugins/can_recalculate_result"
|
7
|
+
require_relative "plugins/has_inspect"
|
7
8
|
require_relative "plugins/has_result"
|
8
9
|
require_relative "plugins/has_result_method_steps"
|
9
10
|
require_relative "plugins/has_result_short_syntax"
|
10
11
|
require_relative "plugins/has_result_steps"
|
11
12
|
require_relative "plugins/raises_on_double_result"
|
12
13
|
require_relative "plugins/wraps_result_in_db_transaction"
|
14
|
+
require_relative "plugins/has_result_status_check_short_syntax"
|
13
15
|
|
14
16
|
require_relative "plugins/aliases"
|
@@ -0,0 +1,100 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ConvenientService
|
4
|
+
module Support
|
5
|
+
class Cache
|
6
|
+
class Key
|
7
|
+
##
|
8
|
+
# @param args [Array]
|
9
|
+
# @param kwargs [Hash]
|
10
|
+
# @param block [Proc]
|
11
|
+
# @return [void]
|
12
|
+
#
|
13
|
+
def initialize(*args, **kwargs, &block)
|
14
|
+
@args = args
|
15
|
+
@kwargs = kwargs
|
16
|
+
@block = block
|
17
|
+
end
|
18
|
+
|
19
|
+
##
|
20
|
+
# @param other [Object] Can be any type.
|
21
|
+
# @return [Boolean]
|
22
|
+
#
|
23
|
+
def ==(other)
|
24
|
+
return unless other.instance_of?(self.class)
|
25
|
+
|
26
|
+
return false if args != other.args
|
27
|
+
return false if kwargs != other.kwargs
|
28
|
+
return false if block&.source_location != other.block&.source_location
|
29
|
+
|
30
|
+
true
|
31
|
+
end
|
32
|
+
|
33
|
+
##
|
34
|
+
# @param other [Object] Can be any type.
|
35
|
+
# @return [Boolean]
|
36
|
+
#
|
37
|
+
# @internal
|
38
|
+
# IMPORTANT: `Key` instances are used as Ruby hash keys.
|
39
|
+
#
|
40
|
+
# This method is overridden in order to avoid the following case:
|
41
|
+
#
|
42
|
+
# hash = {}
|
43
|
+
#
|
44
|
+
# ##
|
45
|
+
# # Two equal keys in terms of `==`.
|
46
|
+
# #
|
47
|
+
# first_key = ConvenientService::Common::Plugins::CachesReturnValue::Entities::Key.new(method: :result, args: [], kwargs: {}, block: nil)
|
48
|
+
# second_key = ConvenientService::Common::Plugins::CachesReturnValue::Entities::Key.new(method: :result, args: [], kwargs: {}, block: nil)
|
49
|
+
#
|
50
|
+
# first_key == second_key
|
51
|
+
# # => true
|
52
|
+
#
|
53
|
+
# hash[first_key] = "value"
|
54
|
+
#
|
55
|
+
# hash[second_key]
|
56
|
+
# # => nil # This happens since keys are not equal in terms of `eql?`.
|
57
|
+
#
|
58
|
+
# NOTE: Ruby hash and Object#hash are not the same things.
|
59
|
+
# - https://ruby-doc.org/core-3.1.2/Object.html#method-i-hash
|
60
|
+
# - https://belighted.com/blog/overriding-equals-equals/
|
61
|
+
#
|
62
|
+
def eql?(other)
|
63
|
+
return unless other.instance_of?(self.class)
|
64
|
+
|
65
|
+
hash == other.hash
|
66
|
+
end
|
67
|
+
|
68
|
+
##
|
69
|
+
# @internal
|
70
|
+
# NOTE: hash is overridden to treat blocks that were defined at the same location as equal.
|
71
|
+
# - https://ruby-doc.org/core-3.1.2/Proc.html#method-i-source_location
|
72
|
+
# - https://ruby-doc.org/core-3.1.2/Object.html#method-i-hash
|
73
|
+
#
|
74
|
+
def hash
|
75
|
+
[args, kwargs, block&.source_location].hash
|
76
|
+
end
|
77
|
+
|
78
|
+
protected
|
79
|
+
|
80
|
+
##
|
81
|
+
# @!attribute [r] args
|
82
|
+
# @return [Array]
|
83
|
+
#
|
84
|
+
attr_reader :args
|
85
|
+
|
86
|
+
##
|
87
|
+
# @!attribute [r] kwargs
|
88
|
+
# @return [Hash]
|
89
|
+
#
|
90
|
+
attr_reader :kwargs
|
91
|
+
|
92
|
+
##
|
93
|
+
# @!attribute [r] block
|
94
|
+
# @return [Proc]
|
95
|
+
#
|
96
|
+
attr_reader :block
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|