convenient_service 0.8.0 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +34 -0
- data/lib/convenient_service/common/plugins/can_have_user_provided_entity/commands/find_or_create_entity.rb +117 -0
- data/lib/convenient_service/common/plugins/can_have_user_provided_entity/commands.rb +3 -0
- data/lib/convenient_service/common/plugins/can_have_user_provided_entity/container.rb +17 -0
- data/lib/convenient_service/common/plugins/can_have_user_provided_entity/errors.rb +42 -0
- data/lib/convenient_service/common/plugins/can_have_user_provided_entity.rb +5 -0
- data/lib/convenient_service/common/plugins/has_internals/commands/create_internals_class.rb +21 -36
- data/lib/convenient_service/common/plugins/has_internals/concern.rb +1 -4
- data/lib/convenient_service/common/plugins.rb +1 -0
- data/lib/convenient_service/rspec/matchers/custom/results/base.rb +5 -0
- data/lib/convenient_service/service/plugins/has_result/commands/create_result_class.rb +13 -38
- data/lib/convenient_service/service/plugins/has_result/concern/class_methods.rb +4 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/{has_result_short_syntax/concern/instance_methods.rb → has_jsend_status_and_attributes/concern/class_methods.rb} +2 -8
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/concern.rb +3 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/code/concern/class_methods.rb +40 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/code/concern/instance_methods.rb +65 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/code/{class_methods.rb → concern.rb} +12 -10
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/code.rb +2 -26
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_result_short_syntax/concern.rb +33 -1
- data/lib/convenient_service/service/plugins/has_result_steps/commands/create_step_class.rb +19 -38
- data/lib/convenient_service/service/plugins/has_result_steps/entities/step_collection.rb +4 -1
- data/lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions/commands/format_cause.rb +16 -2
- data/lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions/commands/format_class.rb +40 -0
- data/lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions/commands/format_exception.rb +31 -6
- data/lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions/commands/format_message.rb +48 -0
- data/lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions/commands.rb +2 -0
- data/lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions/constants.rb +8 -0
- data/lib/convenient_service/support/dependency_container/errors.rb +14 -0
- data/lib/convenient_service/support/dependency_container/export.rb +8 -0
- data/lib/convenient_service/utils/object/memoize_including_falsy_values.rb +61 -0
- data/lib/convenient_service/utils/object.rb +11 -0
- data/lib/convenient_service/utils/string/camelize.rb +6 -2
- data/lib/convenient_service/utils/string/demodulize.rb +50 -0
- data/lib/convenient_service/utils/string/split.rb +4 -4
- data/lib/convenient_service/utils/string.rb +5 -0
- data/lib/convenient_service/version.rb +1 -1
- metadata +15 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ae92003a48bd04299fc7d8d6036c3d1c94e1a0e2a436c645969350bc3653a6a
|
4
|
+
data.tar.gz: 177c46a70660b06e1985c4653cfc2ade49c07e9353880847c19b41e5017d3a05
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 80e69d94ebbd681b3d9aaabd78367b3a104e3e452b596c5cfbf3b32ee6a2855b1352712ee0645c095eed9e66fdd6337be27ff2b9eb14bebf61166314db3d7d40
|
7
|
+
data.tar.gz: 28bea96a05480a11360d261b853039fbc7fd364a2a495280cc457e083d62271b66ed861f089a9ad0172910976cfa1326c53a599fb2bf91ebbca68bba5e688e14
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,39 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## [0.10.0](https://github.com/marian13/convenient_service/compare/v0.9.0...v0.10.0) (2023-03-01)
|
4
|
+
|
5
|
+
|
6
|
+
### Features
|
7
|
+
|
8
|
+
* **utils:** introduce Utils::String.demodulize ([87a145a](https://github.com/marian13/convenient_service/commit/87a145a7742e1fce04fa40917dae6ee61e811c71))
|
9
|
+
|
10
|
+
|
11
|
+
### Bug Fixes
|
12
|
+
|
13
|
+
* **be_result:** commit config manually ([658e314](https://github.com/marian13/convenient_service/commit/658e3147cad50cb7226c8530227e704bb4c30945))
|
14
|
+
* **can_have_user_provided_entity:** use demodulized proto entity name ([f25e63c](https://github.com/marian13/convenient_service/commit/f25e63c23a9407ec8cc513311de506781e3cb5ca))
|
15
|
+
* **has_result_steps:** no validate ([6c14a57](https://github.com/marian13/convenient_service/commit/6c14a572b8fa2dfcb3afef26e64859bb67ac9729))
|
16
|
+
* **rescues_result_unhandled_exceptions:** add indentation for all message lines ([6458103](https://github.com/marian13/convenient_service/commit/6458103c362c66da42587b1a0bec4935b42606ac))
|
17
|
+
* **rescues_result_unhandled_exceptions:** use formatted message and class for cause ([c75c389](https://github.com/marian13/convenient_service/commit/c75c3891158ea58d28d8de3718a6296565a1cd84))
|
18
|
+
|
19
|
+
## [0.9.0](https://github.com/marian13/convenient_service/compare/v0.8.0...v0.9.0) (2023-02-22)
|
20
|
+
|
21
|
+
|
22
|
+
### ⚠ BREAKING CHANGES
|
23
|
+
|
24
|
+
* **export:** add a logic that forbids to use export in classes ([ca81536a](https://github.com/marian13/convenient_service/commit/ca81536a3080661cb762d549f4ef3ce1456bc566))
|
25
|
+
|
26
|
+
|
27
|
+
### Features
|
28
|
+
|
29
|
+
* **has_result_short_syntax:** introduce Result#ud, Result#um, Result#uc ([95856c9](https://github.com/marian13/convenient_service/commit/95856c921c14888a3253f1c3d12453dbfd97a14b))
|
30
|
+
* **utils:** introduce Object#memoize_including_falsy_values ([22b2430](https://github.com/marian13/convenient_service/commit/22b2430f2a57dbded706754261defc53ec140e4f))
|
31
|
+
|
32
|
+
|
33
|
+
### Bug Fixes
|
34
|
+
|
35
|
+
* **export:** add a logic that forbids to use export in classes ([ca81536a](https://github.com/marian13/convenient_service/commit/ca81536a3080661cb762d549f4ef3ce1456bc566))
|
36
|
+
|
3
37
|
## [0.8.0](https://github.com/marian13/convenient_service/compare/v0.7.0...v0.8.0) (2023-02-20)
|
4
38
|
|
5
39
|
|
@@ -0,0 +1,117 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ConvenientService
|
4
|
+
module Common
|
5
|
+
module Plugins
|
6
|
+
module CanHaveUserProvidedEntity
|
7
|
+
module Commands
|
8
|
+
class FindOrCreateEntity < Support::Command
|
9
|
+
##
|
10
|
+
# @!attribute [r] namespace
|
11
|
+
# @return [Class]
|
12
|
+
#
|
13
|
+
attr_reader :namespace
|
14
|
+
|
15
|
+
##
|
16
|
+
# @!attribute [r] proto_entity
|
17
|
+
# @return [Class]
|
18
|
+
#
|
19
|
+
attr_reader :proto_entity
|
20
|
+
|
21
|
+
##
|
22
|
+
# @param namespace [Class]
|
23
|
+
# @param proto_entity [Class]
|
24
|
+
# @return [void]
|
25
|
+
#
|
26
|
+
def initialize(namespace:, proto_entity:)
|
27
|
+
@namespace = namespace
|
28
|
+
@proto_entity = proto_entity
|
29
|
+
end
|
30
|
+
|
31
|
+
##
|
32
|
+
# @return [void]
|
33
|
+
#
|
34
|
+
def call
|
35
|
+
raise Errors::ProtoEntityHasNoName.new(proto_entity: proto_entity) unless proto_entity_name
|
36
|
+
raise Errors::ProtoEntityHasNoConcern.new(proto_entity: proto_entity) unless proto_entity_concern
|
37
|
+
|
38
|
+
entity.include proto_entity_concern
|
39
|
+
|
40
|
+
##
|
41
|
+
# @example Result for service.
|
42
|
+
#
|
43
|
+
# klass = ConvenientService::Common::Plugins::CanHaveUserProvidedEntity::Commands::FindOrCreateEntity.call(
|
44
|
+
# namespace: SomeService,
|
45
|
+
# proto_entity: ConvenientService::Service::Plugins::HasResult::Entities::Result
|
46
|
+
# )
|
47
|
+
#
|
48
|
+
# ##
|
49
|
+
# # `klass` is something like:
|
50
|
+
# #
|
51
|
+
# # class Result < ConvenientService::Service::Plugins::HasResult::Entities::Result # or just `class Result` if service (namespace) class defines its own.
|
52
|
+
# # include ConvenientService::Service::Plugins::HasResult::Entities::Result::Concern # (concern)
|
53
|
+
# #
|
54
|
+
# # class << self
|
55
|
+
# # def proto_entity
|
56
|
+
# # ##
|
57
|
+
# # # NOTE: Returns `proto_entity` passed to `FindOrCreateEntity`.
|
58
|
+
# # #
|
59
|
+
# # proto_entity
|
60
|
+
# # end
|
61
|
+
# #
|
62
|
+
# # def ==(other)
|
63
|
+
# # return unless other.respond_to?(:proto_entity)
|
64
|
+
# #
|
65
|
+
# # self.proto_entity == other.proto_entity
|
66
|
+
# # end
|
67
|
+
# # end
|
68
|
+
# # end
|
69
|
+
#
|
70
|
+
entity.class_exec(proto_entity) do |proto_entity|
|
71
|
+
define_singleton_method(:proto_entity) { proto_entity }
|
72
|
+
define_singleton_method(:==) { |other| self.proto_entity == other.proto_entity if other.respond_to?(:proto_entity) }
|
73
|
+
|
74
|
+
##
|
75
|
+
# TODO: `inspect`.
|
76
|
+
#
|
77
|
+
# define_singleton_method(:inspect) { "#{entity}(Prototyped by #{proto_entity})" }
|
78
|
+
end
|
79
|
+
|
80
|
+
entity
|
81
|
+
end
|
82
|
+
|
83
|
+
private
|
84
|
+
|
85
|
+
##
|
86
|
+
# @return [Class]
|
87
|
+
#
|
88
|
+
def entity
|
89
|
+
@entity ||= Utils::Module.get_own_const(namespace, proto_entity_demodulized_name) || ::Class.new(proto_entity)
|
90
|
+
end
|
91
|
+
|
92
|
+
##
|
93
|
+
# @return [String, nil]
|
94
|
+
#
|
95
|
+
def proto_entity_name
|
96
|
+
Utils::Object.memoize_including_falsy_values(self, :@proto_entity_name) { proto_entity.name }
|
97
|
+
end
|
98
|
+
|
99
|
+
##
|
100
|
+
# @return [String]
|
101
|
+
#
|
102
|
+
def proto_entity_demodulized_name
|
103
|
+
@proto_entity_demodulized_name ||= Utils::String.demodulize(proto_entity_name)
|
104
|
+
end
|
105
|
+
|
106
|
+
##
|
107
|
+
# @return [Module]
|
108
|
+
#
|
109
|
+
def proto_entity_concern
|
110
|
+
Utils::Object.memoize_including_falsy_values(self, :@proto_entity_concern) { Utils::Module.get_own_const(proto_entity, :Concern) }
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ConvenientService
|
4
|
+
module Common
|
5
|
+
module Plugins
|
6
|
+
module CanHaveUserProvidedEntity
|
7
|
+
module Container
|
8
|
+
include Support::DependencyContainer::Export
|
9
|
+
|
10
|
+
export :"commands.FindOrCreateEntity" do
|
11
|
+
Commands::FindOrCreateEntity
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ConvenientService
|
4
|
+
module Common
|
5
|
+
module Plugins
|
6
|
+
module CanHaveUserProvidedEntity
|
7
|
+
module Errors
|
8
|
+
class ProtoEntityHasNoName < ConvenientService::Error
|
9
|
+
def initialize(proto_entity:)
|
10
|
+
message = <<~TEXT
|
11
|
+
Proto entity `#{proto_entity}` has no name.
|
12
|
+
|
13
|
+
In other words:
|
14
|
+
|
15
|
+
proto_entity.name
|
16
|
+
# => nil
|
17
|
+
|
18
|
+
NOTE: Anonymous classes do NOT have names. Are you passing an anonymous class?
|
19
|
+
TEXT
|
20
|
+
|
21
|
+
super(message)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class ProtoEntityHasNoConcern < ConvenientService::Error
|
26
|
+
def initialize(proto_entity:)
|
27
|
+
message = <<~TEXT
|
28
|
+
Proto entity `#{proto_entity}` has no concern.
|
29
|
+
|
30
|
+
Have a look at `ConvenientService::Service::Plugins::HasResult::Entities::Result`.
|
31
|
+
|
32
|
+
It is an example of a valid proto entity.
|
33
|
+
TEXT
|
34
|
+
|
35
|
+
super(message)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -6,47 +6,32 @@ module ConvenientService
|
|
6
6
|
module HasInternals
|
7
7
|
module Commands
|
8
8
|
class CreateInternalsClass < Support::Command
|
9
|
-
|
9
|
+
include Support::DependencyContainer::Import
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
internals_class.include Entities::Internals::Concern
|
11
|
+
##
|
12
|
+
# @!attribute [r] entity_class
|
13
|
+
# @return Class
|
14
|
+
#
|
15
|
+
attr_reader :entity_class
|
17
16
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
# class << self
|
23
|
-
# def service_class
|
24
|
-
# ##
|
25
|
-
# # NOTE: Returns `service_class` passed to `CreateInternalsClass`.
|
26
|
-
# #
|
27
|
-
# service_class
|
28
|
-
# end
|
29
|
-
#
|
30
|
-
# def ==(other)
|
31
|
-
# return unless other.instance_of?(self.class)
|
32
|
-
#
|
33
|
-
# self.service_class == other.service_class
|
34
|
-
# end
|
35
|
-
# end
|
36
|
-
# end
|
37
|
-
#
|
38
|
-
internals_class.class_exec(service_class) do |service_class|
|
39
|
-
define_singleton_method(:service_class) { service_class }
|
40
|
-
define_singleton_method(:==) { |other| self.service_class == other.service_class if other.instance_of?(self.class) }
|
41
|
-
end
|
17
|
+
##
|
18
|
+
# @return Class
|
19
|
+
#
|
20
|
+
import :"commands.FindOrCreateEntity", from: Common::Plugins::CanHaveUserProvidedEntity::Container
|
42
21
|
|
43
|
-
|
22
|
+
##
|
23
|
+
# @param entity_class [Class]
|
24
|
+
# @return [void]
|
25
|
+
#
|
26
|
+
def initialize(entity_class:)
|
27
|
+
@entity_class = entity_class
|
44
28
|
end
|
45
29
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
30
|
+
##
|
31
|
+
# @return [Class]
|
32
|
+
#
|
33
|
+
def call
|
34
|
+
commands.FindOrCreateEntity.call(namespace: entity_class, proto_entity: Entities::Internals)
|
50
35
|
end
|
51
36
|
end
|
52
37
|
end
|
@@ -15,10 +15,7 @@ module ConvenientService
|
|
15
15
|
|
16
16
|
class_methods do
|
17
17
|
def internals_class
|
18
|
-
|
19
|
-
# TODO: Generic `CreateInternalsClass`.
|
20
|
-
#
|
21
|
-
@internals_class ||= Commands::CreateInternalsClass.call(service_class: self)
|
18
|
+
@internals_class ||= Commands::CreateInternalsClass.call(entity_class: self)
|
22
19
|
end
|
23
20
|
end
|
24
21
|
end
|
@@ -8,6 +8,7 @@ require_relative "plugins/normalizes_env"
|
|
8
8
|
require_relative "plugins/caches_constructor_params"
|
9
9
|
require_relative "plugins/caches_return_value"
|
10
10
|
require_relative "plugins/can_be_copied"
|
11
|
+
require_relative "plugins/can_have_user_provided_entity"
|
11
12
|
require_relative "plugins/has_callbacks"
|
12
13
|
require_relative "plugins/has_around_callbacks"
|
13
14
|
require_relative "plugins/has_constructor"
|
@@ -25,6 +25,11 @@ module ConvenientService
|
|
25
25
|
|
26
26
|
rules = []
|
27
27
|
|
28
|
+
##
|
29
|
+
# IMPORTANT: Makes `result.class.include?` from the following line idempotent.
|
30
|
+
#
|
31
|
+
result.commit_config! if result.respond_to?(:commit_config!)
|
32
|
+
|
28
33
|
rules << ->(result) { result.class.include?(Service::Plugins::HasResult::Entities::Result::Concern) }
|
29
34
|
|
30
35
|
##
|
@@ -6,57 +6,32 @@ module ConvenientService
|
|
6
6
|
module HasResult
|
7
7
|
module Commands
|
8
8
|
class CreateResultClass < Support::Command
|
9
|
+
include Support::DependencyContainer::Import
|
10
|
+
|
11
|
+
##
|
12
|
+
# @!attribute [r] service_class
|
13
|
+
# @return Class
|
14
|
+
#
|
9
15
|
attr_reader :service_class
|
10
16
|
|
11
17
|
##
|
12
|
-
# @
|
13
|
-
# @return [void]
|
18
|
+
# @return Class
|
14
19
|
#
|
15
|
-
|
16
|
-
@service_class = service_class
|
17
|
-
end
|
20
|
+
import :"commands.FindOrCreateEntity", from: Common::Plugins::CanHaveUserProvidedEntity::Container
|
18
21
|
|
19
22
|
##
|
23
|
+
# @param service_class [Class]
|
20
24
|
# @return [void]
|
21
25
|
#
|
22
|
-
def
|
23
|
-
|
24
|
-
|
25
|
-
##
|
26
|
-
# class Result < ConvenientService::Service::Plugins::HasResult::Entities::Result # or just `class Result` if service class defines its own.
|
27
|
-
# include ConvenientService::Service::Plugins::HasResult::Entities::Result::Concern
|
28
|
-
#
|
29
|
-
# class << self
|
30
|
-
# def service_class
|
31
|
-
# ##
|
32
|
-
# # NOTE: Returns `service_class` passed to `CreateResultClass`.
|
33
|
-
# #
|
34
|
-
# service_class
|
35
|
-
# end
|
36
|
-
#
|
37
|
-
# def ==(other)
|
38
|
-
# return unless other.instance_of?(self.class)
|
39
|
-
#
|
40
|
-
# self.service_class == other.service_class
|
41
|
-
# end
|
42
|
-
# end
|
43
|
-
# end
|
44
|
-
#
|
45
|
-
result_class.class_exec(service_class) do |service_class|
|
46
|
-
define_singleton_method(:service_class) { service_class }
|
47
|
-
define_singleton_method(:==) { |other| self.service_class == other.service_class if other.instance_of?(self.class) }
|
48
|
-
end
|
49
|
-
|
50
|
-
result_class
|
26
|
+
def initialize(service_class:)
|
27
|
+
@service_class = service_class
|
51
28
|
end
|
52
29
|
|
53
|
-
private
|
54
|
-
|
55
30
|
##
|
56
31
|
# @return [Class]
|
57
32
|
#
|
58
|
-
def
|
59
|
-
|
33
|
+
def call
|
34
|
+
commands.FindOrCreateEntity.call(namespace: service_class, proto_entity: Entities::Result)
|
60
35
|
end
|
61
36
|
end
|
62
37
|
end
|
@@ -80,6 +80,10 @@ module ConvenientService
|
|
80
80
|
# @api private
|
81
81
|
# @return [Class]
|
82
82
|
#
|
83
|
+
# @internal
|
84
|
+
# NOTE: A command instead of `import` is used in order to NOT pollute the public interface.
|
85
|
+
# TODO: Specs that prevent public interface accidental pollution.
|
86
|
+
#
|
83
87
|
def result_class
|
84
88
|
@result_class ||= Commands::CreateResultClass.call(service_class: self)
|
85
89
|
end
|
@@ -7,15 +7,9 @@ module ConvenientService
|
|
7
7
|
module Entities
|
8
8
|
class Result
|
9
9
|
module Plugins
|
10
|
-
module
|
10
|
+
module HasJsendStatusAndAttributes
|
11
11
|
module Concern
|
12
|
-
module
|
13
|
-
##
|
14
|
-
# NOTE: `Support::Delegate` is NOT used intentionally in order to NOT pollute the public interface.
|
15
|
-
#
|
16
|
-
def [](key)
|
17
|
-
data[key]
|
18
|
-
end
|
12
|
+
module ClassMethods
|
19
13
|
end
|
20
14
|
end
|
21
15
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative "concern/class_methods"
|
3
4
|
require_relative "concern/instance_methods"
|
4
5
|
|
5
6
|
module ConvenientService
|
@@ -15,6 +16,8 @@ module ConvenientService
|
|
15
16
|
|
16
17
|
included do |result_class|
|
17
18
|
result_class.include InstanceMethods
|
19
|
+
|
20
|
+
result_class.extend ClassMethods
|
18
21
|
end
|
19
22
|
end
|
20
23
|
end
|
@@ -0,0 +1,40 @@
|
|
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 Concern
|
14
|
+
module ClassMethods
|
15
|
+
##
|
16
|
+
# @param other [Object] Can be any type.
|
17
|
+
# @return [ConvenientService::Service::Plugins::HasResult::Entities::Result::Plugins::HasJsendStatusAndAttributes::Entities::Code, nil]
|
18
|
+
#
|
19
|
+
def cast(other)
|
20
|
+
case other
|
21
|
+
when ::String
|
22
|
+
new(value: other.to_sym)
|
23
|
+
when ::Symbol
|
24
|
+
new(value: other)
|
25
|
+
when Code
|
26
|
+
new(value: other.value)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,65 @@
|
|
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 Concern
|
14
|
+
module InstanceMethods
|
15
|
+
##
|
16
|
+
# @!attribute value [r]
|
17
|
+
# @return [Symbol]
|
18
|
+
#
|
19
|
+
attr_reader :value
|
20
|
+
|
21
|
+
##
|
22
|
+
# @param value [Symbol]
|
23
|
+
# @return [void]
|
24
|
+
#
|
25
|
+
def initialize(value:)
|
26
|
+
@value = value
|
27
|
+
end
|
28
|
+
|
29
|
+
##
|
30
|
+
# @param other [Object] Can be any type.
|
31
|
+
# @return [Boolean]
|
32
|
+
#
|
33
|
+
def ==(other)
|
34
|
+
casted = cast(other)
|
35
|
+
|
36
|
+
return unless casted
|
37
|
+
|
38
|
+
value == casted.value
|
39
|
+
end
|
40
|
+
|
41
|
+
##
|
42
|
+
# @return [String]
|
43
|
+
#
|
44
|
+
def to_s
|
45
|
+
@to_s ||= value.to_s
|
46
|
+
end
|
47
|
+
|
48
|
+
##
|
49
|
+
# @return [Symbol]
|
50
|
+
#
|
51
|
+
def to_sym
|
52
|
+
@to_sym ||= value.to_sym
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -1,5 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative "concern/class_methods"
|
4
|
+
require_relative "concern/instance_methods"
|
5
|
+
|
3
6
|
module ConvenientService
|
4
7
|
module Service
|
5
8
|
module Plugins
|
@@ -10,16 +13,15 @@ module ConvenientService
|
|
10
13
|
module HasJsendStatusAndAttributes
|
11
14
|
module Entities
|
12
15
|
class Code
|
13
|
-
module
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
end
|
16
|
+
module Concern
|
17
|
+
include Support::Concern
|
18
|
+
|
19
|
+
included do |code_class|
|
20
|
+
code_class.include Support::Castable
|
21
|
+
|
22
|
+
code_class.include InstanceMethods
|
23
|
+
|
24
|
+
code_class.extend ClassMethods
|
23
25
|
end
|
24
26
|
end
|
25
27
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "code/
|
3
|
+
require_relative "code/concern"
|
4
4
|
|
5
5
|
module ConvenientService
|
6
6
|
module Service
|
@@ -12,31 +12,7 @@ module ConvenientService
|
|
12
12
|
module HasJsendStatusAndAttributes
|
13
13
|
module Entities
|
14
14
|
class Code
|
15
|
-
include
|
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
|
15
|
+
include Concern
|
40
16
|
end
|
41
17
|
end
|
42
18
|
end
|