servactory 2.1.1 → 2.2.0.rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +5 -5
- data/config/locales/en.yml +19 -5
- data/config/locales/ru.yml +19 -5
- data/lib/servactory/actions/tools/runner.rb +40 -1
- data/lib/servactory/configuration/dsl.rb +1 -0
- data/lib/servactory/configuration/setup.rb +10 -0
- data/lib/servactory/context/callable.rb +3 -1
- data/lib/servactory/context/workspace.rb +22 -3
- data/lib/servactory/errors/failure.rb +5 -3
- data/lib/servactory/errors/input_error.rb +1 -1
- data/lib/servactory/errors/internal_error.rb +5 -3
- data/lib/servactory/errors/output_error.rb +5 -3
- data/lib/servactory/{errors → exceptions}/base.rb +1 -1
- data/lib/servactory/exceptions/success.rb +15 -0
- data/lib/servactory/inputs/translator/required.rb +24 -0
- data/lib/servactory/inputs/validations/required.rb +10 -15
- data/lib/servactory/internals/dsl.rb +3 -1
- data/lib/servactory/internals/internal.rb +24 -3
- data/lib/servactory/maintenance/attributes/option_helpers_collection.rb +1 -1
- data/lib/servactory/maintenance/attributes/translator/inclusion.rb +27 -0
- data/lib/servactory/maintenance/attributes/translator/must.rb +42 -0
- data/lib/servactory/maintenance/attributes/translator/type.rb +94 -0
- data/lib/servactory/maintenance/attributes/validations/inclusion.rb +1 -13
- data/lib/servactory/maintenance/attributes/validations/must.rb +6 -25
- data/lib/servactory/maintenance/validations/collection.rb +18 -14
- data/lib/servactory/maintenance/validations/object_schema.rb +3 -3
- data/lib/servactory/maintenance/validations/types.rb +6 -77
- data/lib/servactory/outputs/dsl.rb +3 -1
- data/lib/servactory/outputs/output.rb +24 -3
- data/lib/servactory/result.rb +70 -8
- data/lib/servactory/utils.rb +8 -0
- data/lib/servactory/version.rb +3 -3
- metadata +11 -6
@@ -0,0 +1,94 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Servactory
|
4
|
+
module Maintenance
|
5
|
+
module Attributes
|
6
|
+
module Translator
|
7
|
+
module Type
|
8
|
+
extend self
|
9
|
+
|
10
|
+
def default_message # rubocop:disable Metrics/MethodLength
|
11
|
+
lambda do |service_class_name:, attribute:, value:, key_name:, expected_type:, given_type:|
|
12
|
+
if attribute.collection_mode?
|
13
|
+
for_collection_mode_with(service_class_name: service_class_name, attribute: attribute, value: value,
|
14
|
+
expected_type: expected_type, given_type: given_type)
|
15
|
+
elsif attribute.hash_mode? && key_name.present?
|
16
|
+
for_hash_mode_with(service_class_name: service_class_name, attribute: attribute, key_name: key_name,
|
17
|
+
expected_type: expected_type, given_type: given_type)
|
18
|
+
else
|
19
|
+
for_others_with(service_class_name: service_class_name, attribute: attribute,
|
20
|
+
expected_type: expected_type, given_type: given_type)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def for_collection_mode_with(service_class_name:, attribute:, value:, expected_type:, given_type:) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
28
|
+
collection_message = attribute.consists_of.fetch(:message)
|
29
|
+
|
30
|
+
if collection_message.is_a?(Proc)
|
31
|
+
collection_message.call(
|
32
|
+
"#{attribute.system_name}_name": attribute.name,
|
33
|
+
expected_type: expected_type,
|
34
|
+
given_type: given_type
|
35
|
+
)
|
36
|
+
elsif collection_message.is_a?(String) && collection_message.present?
|
37
|
+
collection_message
|
38
|
+
elsif value.is_a?(attribute.types.fetch(0, Array))
|
39
|
+
I18n.t(
|
40
|
+
"servactory.#{attribute.i18n_name}.validations.type.default_error.for_collection.wrong_element_type",
|
41
|
+
service_class_name: service_class_name,
|
42
|
+
"#{attribute.system_name}_name": attribute.name,
|
43
|
+
expected_type: expected_type,
|
44
|
+
given_type: given_type
|
45
|
+
)
|
46
|
+
else
|
47
|
+
I18n.t(
|
48
|
+
"servactory.#{attribute.i18n_name}.validations.type.default_error.for_collection.wrong_type",
|
49
|
+
service_class_name: service_class_name,
|
50
|
+
"#{attribute.system_name}_name": attribute.name,
|
51
|
+
expected_type: attribute.types.fetch(0, Array),
|
52
|
+
given_type: value.class.name
|
53
|
+
)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def for_hash_mode_with(service_class_name:, attribute:, key_name:, expected_type:, given_type:) # rubocop:disable Metrics/MethodLength
|
58
|
+
hash_message = attribute.schema.fetch(:message)
|
59
|
+
|
60
|
+
if hash_message.is_a?(Proc)
|
61
|
+
hash_message.call(
|
62
|
+
"#{attribute.system_name}_name": attribute.name,
|
63
|
+
key_name: key_name,
|
64
|
+
expected_type: expected_type,
|
65
|
+
given_type: given_type
|
66
|
+
)
|
67
|
+
elsif hash_message.is_a?(String) && hash_message.present?
|
68
|
+
hash_message
|
69
|
+
else
|
70
|
+
I18n.t(
|
71
|
+
"servactory.#{attribute.i18n_name}.validations.type.default_error.for_hash.wrong_element_type",
|
72
|
+
service_class_name: service_class_name,
|
73
|
+
"#{attribute.system_name}_name": attribute.name,
|
74
|
+
key_name: key_name,
|
75
|
+
expected_type: expected_type,
|
76
|
+
given_type: given_type
|
77
|
+
)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def for_others_with(service_class_name:, attribute:, expected_type:, given_type:)
|
82
|
+
I18n.t(
|
83
|
+
"servactory.#{attribute.i18n_name}.validations.type.default_error.default",
|
84
|
+
service_class_name: service_class_name,
|
85
|
+
"#{attribute.system_name}_name": attribute.name,
|
86
|
+
expected_type: expected_type,
|
87
|
+
given_type: given_type
|
88
|
+
)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -5,18 +5,6 @@ module Servactory
|
|
5
5
|
module Attributes
|
6
6
|
module Validations
|
7
7
|
class Inclusion < Base
|
8
|
-
DEFAULT_MESSAGE = lambda do |service_class_name:, input:, value:|
|
9
|
-
I18n.t(
|
10
|
-
"servactory.#{input.i18n_name}.validations.inclusion.default_error",
|
11
|
-
service_class_name: service_class_name,
|
12
|
-
"#{input.system_name}_name": input.name,
|
13
|
-
input_inclusion: input.inclusion[:in],
|
14
|
-
value: value
|
15
|
-
)
|
16
|
-
end
|
17
|
-
|
18
|
-
private_constant :DEFAULT_MESSAGE
|
19
|
-
|
20
8
|
def self.check(context:, attribute:, value:, check_key:, **)
|
21
9
|
return unless should_be_checked_for?(attribute, value, check_key)
|
22
10
|
|
@@ -62,7 +50,7 @@ module Servactory
|
|
62
50
|
|
63
51
|
def add_error_with(message)
|
64
52
|
add_error(
|
65
|
-
message: message.presence ||
|
53
|
+
message: message.presence || Servactory::Maintenance::Attributes::Translator::Inclusion.default_message,
|
66
54
|
service_class_name: @context.class.name,
|
67
55
|
"#{@attribute.system_name}": @attribute,
|
68
56
|
value: @value
|
@@ -5,29 +5,6 @@ module Servactory
|
|
5
5
|
module Attributes
|
6
6
|
module Validations
|
7
7
|
class Must < Base
|
8
|
-
DEFAULT_MESSAGE = lambda do |service_class_name:, input:, value:, code:|
|
9
|
-
I18n.t(
|
10
|
-
"servactory.#{input.i18n_name}.validations.must.default_error",
|
11
|
-
service_class_name: service_class_name,
|
12
|
-
"#{input.system_name}_name": input.name,
|
13
|
-
value: value,
|
14
|
-
code: code
|
15
|
-
)
|
16
|
-
end
|
17
|
-
|
18
|
-
SYNTAX_ERROR_MESSAGE = lambda do |service_class_name:, input:, value:, code:, exception_message:|
|
19
|
-
I18n.t(
|
20
|
-
"servactory.#{input.i18n_name}.validations.must.syntax_error",
|
21
|
-
service_class_name: service_class_name,
|
22
|
-
"#{input.system_name}_name": input.name,
|
23
|
-
value: value,
|
24
|
-
code: code,
|
25
|
-
exception_message: exception_message
|
26
|
-
)
|
27
|
-
end
|
28
|
-
|
29
|
-
private_constant :DEFAULT_MESSAGE, :SYNTAX_ERROR_MESSAGE
|
30
|
-
|
31
8
|
def self.check(context:, attribute:, value:, check_key:, check_options:)
|
32
9
|
return unless should_be_checked_for?(attribute, check_key)
|
33
10
|
|
@@ -68,9 +45,13 @@ module Servactory
|
|
68
45
|
|
69
46
|
return if check.call(value: @value)
|
70
47
|
|
71
|
-
message.presence ||
|
48
|
+
message.presence || Servactory::Maintenance::Attributes::Translator::Must.default_message
|
72
49
|
rescue StandardError => e
|
73
|
-
add_syntax_error_with(
|
50
|
+
add_syntax_error_with(
|
51
|
+
Servactory::Maintenance::Attributes::Translator::Must.syntax_error_message,
|
52
|
+
code,
|
53
|
+
e.message
|
54
|
+
)
|
74
55
|
end
|
75
56
|
|
76
57
|
########################################################################
|
@@ -10,10 +10,10 @@ module Servactory
|
|
10
10
|
new(...).validate
|
11
11
|
end
|
12
12
|
|
13
|
-
def initialize(
|
14
|
-
@attribute = attribute
|
13
|
+
def initialize(types:, value:, consists_of:)
|
15
14
|
@types = types
|
16
15
|
@value = value
|
16
|
+
@consists_of = consists_of
|
17
17
|
|
18
18
|
@errors = []
|
19
19
|
end
|
@@ -28,7 +28,7 @@ module Servactory
|
|
28
28
|
return self
|
29
29
|
end
|
30
30
|
|
31
|
-
|
31
|
+
validate_for!(values: @value)
|
32
32
|
|
33
33
|
self
|
34
34
|
end
|
@@ -39,13 +39,21 @@ module Servactory
|
|
39
39
|
|
40
40
|
private
|
41
41
|
|
42
|
-
def
|
43
|
-
|
42
|
+
def validate_for!(values:) # rubocop:disable Metrics/MethodLength
|
43
|
+
values.each do |value|
|
44
|
+
value_type = value.class
|
44
45
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
46
|
+
if value_type == Array
|
47
|
+
validate_for!(values: value)
|
48
|
+
else
|
49
|
+
next if attribute_consists_of_types.include?(value_type)
|
50
|
+
|
51
|
+
add_error(
|
52
|
+
expected_type: attribute_consists_of_types.join(", "),
|
53
|
+
given_type: value_type.name
|
54
|
+
)
|
55
|
+
end
|
56
|
+
end
|
49
57
|
end
|
50
58
|
|
51
59
|
########################################################################
|
@@ -55,11 +63,7 @@ module Servactory
|
|
55
63
|
end
|
56
64
|
|
57
65
|
def attribute_consists_of_types
|
58
|
-
@attribute_consists_of_types ||= prepared_types_from(Array(@
|
59
|
-
end
|
60
|
-
|
61
|
-
def unnecessary_types
|
62
|
-
@unnecessary_types ||= @value&.map(&:class)&.difference(attribute_consists_of_types).presence || []
|
66
|
+
@attribute_consists_of_types ||= prepared_types_from(Array(@consists_of.fetch(:type, [])))
|
63
67
|
end
|
64
68
|
|
65
69
|
def prepared_types_from(types)
|
@@ -21,7 +21,7 @@ module Servactory
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def validate
|
24
|
-
validate_for(object: @object, schema: @schema)
|
24
|
+
validate_for!(object: @object, schema: @schema)
|
25
25
|
|
26
26
|
self
|
27
27
|
end
|
@@ -32,7 +32,7 @@ module Servactory
|
|
32
32
|
|
33
33
|
private
|
34
34
|
|
35
|
-
def validate_for(object:, schema:, root_schema_key: nil) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
35
|
+
def validate_for!(object:, schema:, root_schema_key: nil) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
36
36
|
unless object.respond_to?(:fetch)
|
37
37
|
add_error(key_name: root_schema_key, expected_type: Hash.name, given_type: object.class.name)
|
38
38
|
return
|
@@ -42,7 +42,7 @@ module Servactory
|
|
42
42
|
attribute_type = schema_value.fetch(:type, String)
|
43
43
|
|
44
44
|
if attribute_type == Hash
|
45
|
-
validate_for(
|
45
|
+
validate_for!(
|
46
46
|
object: object.fetch(schema_key, {}),
|
47
47
|
schema: schema_value.except(*RESERVED_ATTRIBUTES),
|
48
48
|
root_schema_key: schema_key
|
@@ -3,78 +3,7 @@
|
|
3
3
|
module Servactory
|
4
4
|
module Maintenance
|
5
5
|
module Validations
|
6
|
-
class Types
|
7
|
-
DEFAULT_MESSAGE = lambda do | # rubocop:disable Metrics/BlockLength
|
8
|
-
service_class_name:,
|
9
|
-
attribute:,
|
10
|
-
value:,
|
11
|
-
key_name:,
|
12
|
-
expected_type:,
|
13
|
-
given_type:
|
14
|
-
| # do
|
15
|
-
if attribute.collection_mode?
|
16
|
-
collection_message = attribute.consists_of.fetch(:message)
|
17
|
-
|
18
|
-
if collection_message.is_a?(Proc)
|
19
|
-
collection_message.call(
|
20
|
-
"#{attribute.system_name}_name": attribute.name,
|
21
|
-
expected_type: expected_type,
|
22
|
-
given_type: given_type
|
23
|
-
)
|
24
|
-
elsif collection_message.is_a?(String) && collection_message.present?
|
25
|
-
collection_message
|
26
|
-
elsif value.is_a?(attribute.types.fetch(0, Array))
|
27
|
-
I18n.t(
|
28
|
-
"servactory.#{attribute.i18n_name}.validations.type.default_error.for_collection.wrong_element_type",
|
29
|
-
service_class_name: service_class_name,
|
30
|
-
"#{attribute.system_name}_name": attribute.name,
|
31
|
-
expected_type: expected_type,
|
32
|
-
given_type: given_type
|
33
|
-
)
|
34
|
-
else
|
35
|
-
I18n.t(
|
36
|
-
"servactory.#{attribute.i18n_name}.validations.type.default_error.for_collection.wrong_type",
|
37
|
-
service_class_name: service_class_name,
|
38
|
-
"#{attribute.system_name}_name": attribute.name,
|
39
|
-
expected_type: attribute.types.fetch(0, Array),
|
40
|
-
given_type: value.class.name
|
41
|
-
)
|
42
|
-
end
|
43
|
-
elsif attribute.hash_mode? && key_name.present?
|
44
|
-
hash_message = attribute.schema.fetch(:message)
|
45
|
-
|
46
|
-
if hash_message.is_a?(Proc)
|
47
|
-
hash_message.call(
|
48
|
-
"#{attribute.system_name}_name": attribute.name,
|
49
|
-
key_name: key_name,
|
50
|
-
expected_type: expected_type,
|
51
|
-
given_type: given_type
|
52
|
-
)
|
53
|
-
elsif hash_message.is_a?(String) && hash_message.present?
|
54
|
-
hash_message
|
55
|
-
else
|
56
|
-
I18n.t(
|
57
|
-
"servactory.#{attribute.i18n_name}.validations.type.default_error.for_hash.wrong_element_type",
|
58
|
-
service_class_name: service_class_name,
|
59
|
-
"#{attribute.system_name}_name": attribute.name,
|
60
|
-
key_name: key_name,
|
61
|
-
expected_type: expected_type,
|
62
|
-
given_type: given_type
|
63
|
-
)
|
64
|
-
end
|
65
|
-
else
|
66
|
-
I18n.t(
|
67
|
-
"servactory.#{attribute.i18n_name}.validations.type.default_error.default",
|
68
|
-
service_class_name: service_class_name,
|
69
|
-
"#{attribute.system_name}_name": attribute.name,
|
70
|
-
expected_type: expected_type,
|
71
|
-
given_type: given_type
|
72
|
-
)
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
private_constant :DEFAULT_MESSAGE
|
77
|
-
|
6
|
+
class Types
|
78
7
|
def self.validate!(...)
|
79
8
|
new(...).validate!
|
80
9
|
end
|
@@ -93,9 +22,9 @@ module Servactory
|
|
93
22
|
|
94
23
|
if @attribute.collection_mode?
|
95
24
|
collection_validator = Servactory::Maintenance::Validations::Collection.validate(
|
96
|
-
attribute: @attribute,
|
97
25
|
types: @types,
|
98
|
-
value: @value
|
26
|
+
value: @value,
|
27
|
+
consists_of: @attribute.consists_of
|
99
28
|
)
|
100
29
|
|
101
30
|
return if collection_validator.valid?
|
@@ -114,7 +43,7 @@ module Servactory
|
|
114
43
|
|
115
44
|
if (first_error = collection_validator&.errors&.first).present?
|
116
45
|
return @error_callback.call(
|
117
|
-
message:
|
46
|
+
message: Servactory::Maintenance::Attributes::Translator::Type.default_message,
|
118
47
|
service_class_name: @context.class.name,
|
119
48
|
attribute: @attribute,
|
120
49
|
value: @value,
|
@@ -126,7 +55,7 @@ module Servactory
|
|
126
55
|
|
127
56
|
if (first_error = object_schema_validator&.errors&.first).present?
|
128
57
|
return @error_callback.call(
|
129
|
-
message:
|
58
|
+
message: Servactory::Maintenance::Attributes::Translator::Type.default_message,
|
130
59
|
service_class_name: @context.class.name,
|
131
60
|
attribute: @attribute,
|
132
61
|
value: @value,
|
@@ -137,7 +66,7 @@ module Servactory
|
|
137
66
|
end
|
138
67
|
|
139
68
|
@error_callback.call(
|
140
|
-
message:
|
69
|
+
message: Servactory::Maintenance::Attributes::Translator::Type.default_message,
|
141
70
|
service_class_name: @context.class.name,
|
142
71
|
attribute: @attribute,
|
143
72
|
value: @value,
|
@@ -16,11 +16,13 @@ module Servactory
|
|
16
16
|
|
17
17
|
private
|
18
18
|
|
19
|
-
def output(name, **options)
|
19
|
+
def output(name, *helpers, **options)
|
20
20
|
collection_of_outputs << Output.new(
|
21
21
|
name,
|
22
|
+
*helpers,
|
22
23
|
collection_mode_class_names: config.collection_mode_class_names,
|
23
24
|
hash_mode_class_names: config.hash_mode_class_names,
|
25
|
+
option_helpers: config.output_option_helpers,
|
24
26
|
**options
|
25
27
|
)
|
26
28
|
end
|
@@ -8,15 +8,18 @@ module Servactory
|
|
8
8
|
|
9
9
|
def initialize(
|
10
10
|
name,
|
11
|
+
*helpers,
|
11
12
|
collection_mode_class_names:,
|
12
13
|
hash_mode_class_names:,
|
14
|
+
option_helpers:,
|
13
15
|
**options
|
14
16
|
)
|
15
17
|
@name = name
|
16
18
|
@collection_mode_class_names = collection_mode_class_names
|
17
19
|
@hash_mode_class_names = hash_mode_class_names
|
20
|
+
@option_helpers = option_helpers
|
18
21
|
|
19
|
-
register_options(options: options)
|
22
|
+
register_options(helpers: helpers, options: options)
|
20
23
|
end
|
21
24
|
|
22
25
|
def method_missing(name, *args, &block)
|
@@ -31,7 +34,9 @@ module Servactory
|
|
31
34
|
@collection_of_options.names.include?(name) || super
|
32
35
|
end
|
33
36
|
|
34
|
-
def register_options(options:) # rubocop:disable Metrics/MethodLength
|
37
|
+
def register_options(helpers:, options:) # rubocop:disable Metrics/MethodLength
|
38
|
+
options = apply_helpers_for_options(helpers: helpers, options: options) if helpers.present?
|
39
|
+
|
35
40
|
options_registrar = Servactory::Maintenance::Attributes::Options::Registrar.register(
|
36
41
|
attribute: self,
|
37
42
|
collection_mode_class_names: @collection_mode_class_names,
|
@@ -40,13 +45,29 @@ module Servactory
|
|
40
45
|
features: {
|
41
46
|
types: true,
|
42
47
|
collection: true,
|
43
|
-
hash: true
|
48
|
+
hash: true,
|
49
|
+
inclusion: true,
|
50
|
+
must: true
|
44
51
|
}
|
45
52
|
)
|
46
53
|
|
47
54
|
@collection_of_options = options_registrar.collection
|
48
55
|
end
|
49
56
|
|
57
|
+
def apply_helpers_for_options(helpers:, options:)
|
58
|
+
prepared_options = {}
|
59
|
+
|
60
|
+
helpers.each do |helper|
|
61
|
+
found_helper = @option_helpers.find_by(name: helper)
|
62
|
+
|
63
|
+
next if found_helper.blank?
|
64
|
+
|
65
|
+
prepared_options.merge!(found_helper.equivalent)
|
66
|
+
end
|
67
|
+
|
68
|
+
options.merge(prepared_options)
|
69
|
+
end
|
70
|
+
|
50
71
|
def options_for_checks
|
51
72
|
@collection_of_options.options_for_checks
|
52
73
|
end
|
data/lib/servactory/result.rb
CHANGED
@@ -2,12 +2,25 @@
|
|
2
2
|
|
3
3
|
module Servactory
|
4
4
|
class Result
|
5
|
-
|
6
|
-
|
5
|
+
class Outputs
|
6
|
+
def initialize(outputs)
|
7
|
+
outputs.each_pair do |key, value|
|
8
|
+
define_singleton_method(:"#{key}?") { Servactory::Utils.query_attribute(value) }
|
9
|
+
define_singleton_method(key) { value }
|
10
|
+
end
|
11
|
+
end
|
7
12
|
end
|
8
13
|
|
9
|
-
|
10
|
-
|
14
|
+
private_constant :Outputs
|
15
|
+
|
16
|
+
############################################################################
|
17
|
+
|
18
|
+
def self.success_for(context:)
|
19
|
+
new(context: context).send(:as_success)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.failure_for(exception:)
|
23
|
+
new(exception: exception).send(:as_failure)
|
11
24
|
end
|
12
25
|
|
13
26
|
def initialize(context: nil, exception: nil)
|
@@ -19,15 +32,39 @@ module Servactory
|
|
19
32
|
"#<#{self.class.name} #{draw_result}>"
|
20
33
|
end
|
21
34
|
|
35
|
+
def on_success
|
36
|
+
yield(outputs: outputs) if success?
|
37
|
+
|
38
|
+
self
|
39
|
+
end
|
40
|
+
|
41
|
+
def on_failure(type = :all)
|
42
|
+
yield(exception: @exception) if failure? && [:all, @exception&.type].include?(type)
|
43
|
+
|
44
|
+
self
|
45
|
+
end
|
46
|
+
|
47
|
+
def method_missing(name, *_args)
|
48
|
+
super
|
49
|
+
rescue NoMethodError => e
|
50
|
+
rescue_no_method_error_with(exception: e)
|
51
|
+
end
|
52
|
+
|
53
|
+
def respond_to_missing?(*)
|
54
|
+
super
|
55
|
+
end
|
56
|
+
|
22
57
|
private
|
23
58
|
|
24
59
|
def as_success
|
25
60
|
define_singleton_method(:success?) { true }
|
26
61
|
define_singleton_method(:failure?) { false }
|
27
62
|
|
28
|
-
|
29
|
-
|
30
|
-
|
63
|
+
outputs.methods(false).each do |method_name|
|
64
|
+
method_value = outputs.send(method_name)
|
65
|
+
|
66
|
+
define_singleton_method(:"#{method_name}?") { Servactory::Utils.query_attribute(method_value) }
|
67
|
+
define_singleton_method(method_name) { method_value }
|
31
68
|
end
|
32
69
|
|
33
70
|
self
|
@@ -37,7 +74,12 @@ module Servactory
|
|
37
74
|
define_singleton_method(:error) { @exception }
|
38
75
|
|
39
76
|
define_singleton_method(:success?) { false }
|
40
|
-
|
77
|
+
|
78
|
+
define_singleton_method(:failure?) do |type = :all|
|
79
|
+
return true if [:all, @exception&.type].include?(type)
|
80
|
+
|
81
|
+
false
|
82
|
+
end
|
41
83
|
|
42
84
|
self
|
43
85
|
end
|
@@ -47,5 +89,25 @@ module Servactory
|
|
47
89
|
"@#{method_name}=#{send(method_name)}"
|
48
90
|
end.join(", ")
|
49
91
|
end
|
92
|
+
|
93
|
+
def outputs
|
94
|
+
@outputs ||= Outputs.new(@context.send(:servactory_service_storage).fetch(:outputs))
|
95
|
+
end
|
96
|
+
|
97
|
+
########################################################################
|
98
|
+
|
99
|
+
def rescue_no_method_error_with(exception:)
|
100
|
+
raise exception if @context.blank?
|
101
|
+
|
102
|
+
raise @context.class.config.failure_class.new(
|
103
|
+
type: :base,
|
104
|
+
message: I18n.t(
|
105
|
+
"servactory.common.undefined_method.missing_name",
|
106
|
+
service_class_name: @context.class.name,
|
107
|
+
method_name: exception.name,
|
108
|
+
missing_name: exception.missing_name.inspect
|
109
|
+
)
|
110
|
+
)
|
111
|
+
end
|
50
112
|
end
|
51
113
|
end
|
data/lib/servactory/utils.rb
CHANGED
@@ -4,6 +4,14 @@ module Servactory
|
|
4
4
|
module Utils
|
5
5
|
module_function
|
6
6
|
|
7
|
+
def define_attribute_with(input:, internal:, output:)
|
8
|
+
return input if input.present?
|
9
|
+
return internal if internal.present?
|
10
|
+
return output if output.present?
|
11
|
+
|
12
|
+
raise ArgumentError, "missing keyword: :input, :internal or :output"
|
13
|
+
end
|
14
|
+
|
7
15
|
FALSE_VALUES = [
|
8
16
|
false,
|
9
17
|
nil, "",
|
data/lib/servactory/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: servactory
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0.rc1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anton Sokolov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-02-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -16,7 +16,7 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '5.1'
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: '7.2'
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: '
|
29
|
+
version: '5.1'
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: '7.2'
|
@@ -245,11 +245,12 @@ files:
|
|
245
245
|
- lib/servactory/context/workspace/outputs.rb
|
246
246
|
- lib/servactory/dsl.rb
|
247
247
|
- lib/servactory/engine.rb
|
248
|
-
- lib/servactory/errors/base.rb
|
249
248
|
- lib/servactory/errors/failure.rb
|
250
249
|
- lib/servactory/errors/input_error.rb
|
251
250
|
- lib/servactory/errors/internal_error.rb
|
252
251
|
- lib/servactory/errors/output_error.rb
|
252
|
+
- lib/servactory/exceptions/base.rb
|
253
|
+
- lib/servactory/exceptions/success.rb
|
253
254
|
- lib/servactory/info/dsl.rb
|
254
255
|
- lib/servactory/info/result.rb
|
255
256
|
- lib/servactory/inputs/collection.rb
|
@@ -258,6 +259,7 @@ files:
|
|
258
259
|
- lib/servactory/inputs/tools/rules.rb
|
259
260
|
- lib/servactory/inputs/tools/unnecessary.rb
|
260
261
|
- lib/servactory/inputs/tools/validation.rb
|
262
|
+
- lib/servactory/inputs/translator/required.rb
|
261
263
|
- lib/servactory/inputs/validations/base.rb
|
262
264
|
- lib/servactory/inputs/validations/errors.rb
|
263
265
|
- lib/servactory/inputs/validations/required.rb
|
@@ -274,6 +276,9 @@ files:
|
|
274
276
|
- lib/servactory/maintenance/attributes/options_collection.rb
|
275
277
|
- lib/servactory/maintenance/attributes/tools/check_errors.rb
|
276
278
|
- lib/servactory/maintenance/attributes/tools/validation.rb
|
279
|
+
- lib/servactory/maintenance/attributes/translator/inclusion.rb
|
280
|
+
- lib/servactory/maintenance/attributes/translator/must.rb
|
281
|
+
- lib/servactory/maintenance/attributes/translator/type.rb
|
277
282
|
- lib/servactory/maintenance/attributes/validations/base.rb
|
278
283
|
- lib/servactory/maintenance/attributes/validations/errors.rb
|
279
284
|
- lib/servactory/maintenance/attributes/validations/inclusion.rb
|
@@ -317,7 +322,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
317
322
|
- !ruby/object:Gem::Version
|
318
323
|
version: '0'
|
319
324
|
requirements: []
|
320
|
-
rubygems_version: 3.5.
|
325
|
+
rubygems_version: 3.5.6
|
321
326
|
signing_key:
|
322
327
|
specification_version: 4
|
323
328
|
summary: A set of tools for building reliable services of any complexity
|