servactory 2.12.0.rc2 → 2.12.0.rc3
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/config/locales/en.yml +12 -6
- data/config/locales/ru.yml +12 -6
- data/lib/servactory/configuration/setup.rb +3 -0
- data/lib/servactory/context/workspace/inputs.rb +0 -35
- data/lib/servactory/inputs/dsl.rb +0 -1
- data/lib/servactory/inputs/input.rb +0 -4
- data/lib/servactory/internals/dsl.rb +0 -1
- data/lib/servactory/internals/internal.rb +0 -4
- data/lib/servactory/maintenance/attributes/option.rb +7 -13
- data/lib/servactory/maintenance/attributes/options/registrar.rb +1 -23
- data/lib/servactory/maintenance/attributes/translator/must.rb +1 -1
- data/lib/servactory/maintenance/attributes/translator/type.rb +3 -38
- data/lib/servactory/maintenance/attributes/validations/must.rb +8 -6
- data/lib/servactory/maintenance/validations/types.rb +3 -26
- data/lib/servactory/outputs/dsl.rb +0 -1
- data/lib/servactory/outputs/output.rb +0 -4
- data/lib/servactory/test_kit/rspec/matchers/have_service_attribute_matchers/consists_of_matcher.rb +9 -26
- data/lib/servactory/test_kit/rspec/matchers/have_service_attribute_matchers/inclusion_matcher.rb +11 -27
- data/lib/servactory/test_kit/rspec/matchers/have_service_attribute_matchers/message_matcher.rb +91 -0
- data/lib/servactory/test_kit/rspec/matchers/have_service_attribute_matchers/must_matcher.rb +6 -0
- data/lib/servactory/test_kit/rspec/matchers/have_service_attribute_matchers/schema_matcher.rb +83 -0
- data/lib/servactory/test_kit/rspec/matchers/have_service_input_matcher.rb +30 -11
- data/lib/servactory/test_kit/rspec/matchers/have_service_input_matchers/valid_with_matcher.rb +7 -1
- data/lib/servactory/test_kit/rspec/matchers/have_service_internal_matcher.rb +32 -11
- data/lib/servactory/tool_kit/dynamic_options/must.rb +29 -5
- data/lib/servactory/tool_kit/dynamic_options/schema.rb +193 -0
- data/lib/servactory/version.rb +1 -1
- metadata +5 -3
- data/lib/servactory/maintenance/validations/object_schema.rb +0 -116
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db0f437672047c90c0b10f79f55c49670ec6c18ea977f3cf0ac2ab5e0b1b5cee
|
4
|
+
data.tar.gz: 5a51217c27c4d0d21d1d2d466450295dc4c6b8fcc7254bf7b82634ffa968b03d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 62a421c1ee2f2135f5d14fdc11378e05f3dda3ddf5a613af2e0809c40defacad98c3ed7ad06d6cb1c91c1333890cb31687dd8423ac2e2c5658acfc53a62a2885
|
7
|
+
data.tar.gz: 900ab23ae47cd912238476d6945ecc31f9fc43e26378bde0ff3d4e0367c1e8f703006a2d44b5704335ee7b1549ecde596be732c5a12acbabbc94d1ca717dfea0
|
data/config/locales/en.yml
CHANGED
@@ -34,14 +34,16 @@ en:
|
|
34
34
|
default: "[%{service_class_name}] Input `%{input_name}` has the value `%{value}`, which is not a multiple of `%{option_value}`"
|
35
35
|
blank: "[%{service_class_name}] Input `%{input_name}` has an invalid value `%{option_value}` in option `%{option_name}`"
|
36
36
|
divided_by_0: "[%{service_class_name}] Input `%{input_name}` has an invalid value `%{option_value}` in option `%{option_name}`"
|
37
|
+
schema:
|
38
|
+
wrong_type: "[%{service_class_name}] Wrong type of input `%{input_name}`, expected `%{expected_type}`, got `%{given_type}`"
|
39
|
+
wrong_element_type: "[%{service_class_name}] Wrong type in input hash `%{input_name}`, expected `%{expected_type}` for `%{key_name}`, got `%{given_type}`"
|
40
|
+
wrong_element_value: "[%{service_class_name}] Wrong value in input hash `%{input_name}`, expected value of type `%{expected_type}` for `%{key_name}`, got `%{given_type}`"
|
37
41
|
required:
|
38
42
|
default_error:
|
39
43
|
default: "[%{service_class_name}] Required input `%{input_name}` is missing"
|
40
44
|
type:
|
41
45
|
default_error:
|
42
46
|
default: "[%{service_class_name}] Wrong type of input `%{input_name}`, expected `%{expected_type}`, got `%{given_type}`"
|
43
|
-
for_hash:
|
44
|
-
wrong_element_type: "[%{service_class_name}] Wrong type in input hash `%{input_name}`, expected `%{expected_type}` for `%{key_name}`, got `%{given_type}`"
|
45
47
|
tools:
|
46
48
|
find_unnecessary:
|
47
49
|
error: "[%{service_class_name}] Unexpected attributes: `%{unnecessary_attributes}`"
|
@@ -74,11 +76,13 @@ en:
|
|
74
76
|
default: "[%{service_class_name}] Internal attribute `%{internal_name}` has the value `%{value}`, which is not a multiple of `%{option_value}`"
|
75
77
|
blank: "[%{service_class_name}] Internal attribute `%{internal_name}` has an invalid value `%{option_value}` in option `%{option_name}`"
|
76
78
|
divided_by_0: "[%{service_class_name}] Internal attribute `%{internal_name}` has an invalid value `%{option_value}` in option `%{option_name}`"
|
79
|
+
schema:
|
80
|
+
wrong_type: "[%{service_class_name}] Wrong type of internal attribute `%{internal_name}`, expected `%{expected_type}`, got `%{given_type}`"
|
81
|
+
wrong_element_type: "[%{service_class_name}] Wrong type in internal attribute hash `%{internal_name}`, expected `%{expected_type}` for `%{key_name}`, got `%{given_type}`"
|
82
|
+
wrong_element_value: "[%{service_class_name}] Wrong value in internal attribute hash `%{internal_name}`, expected value of type `%{expected_type}` for `%{key_name}`, got `%{given_type}`"
|
77
83
|
type:
|
78
84
|
default_error:
|
79
85
|
default: "[%{service_class_name}] Wrong type of internal attribute `%{internal_name}`, expected `%{expected_type}`, got `%{given_type}`"
|
80
|
-
for_hash:
|
81
|
-
wrong_element_type: "[%{service_class_name}] Wrong type in internal attribute hash `%{internal_name}`, expected `%{expected_type}` for `%{key_name}`, got `%{given_type}`"
|
82
86
|
outputs:
|
83
87
|
undefined:
|
84
88
|
for_fetch: "[%{service_class_name}] Undefined output attribute `%{output_name}`"
|
@@ -106,8 +110,10 @@ en:
|
|
106
110
|
default: "[%{service_class_name}] Output attribute `%{output_name}` has the value `%{value}`, which is not a multiple of `%{option_value}`"
|
107
111
|
blank: "[%{service_class_name}] Output attribute `%{output_name}` has an invalid value `%{option_value}` in option `%{option_name}`"
|
108
112
|
divided_by_0: "[%{service_class_name}] Output attribute `%{output_name}` has an invalid value `%{option_value}` in option `%{option_name}`"
|
113
|
+
schema:
|
114
|
+
wrong_type: "[%{service_class_name}] Wrong type of output attribute `%{output_name}`, expected `%{expected_type}`, got `%{given_type}`"
|
115
|
+
wrong_element_type: "[%{service_class_name}] Wrong type in output attribute hash `%{output_name}`, expected `%{expected_type}` for `%{key_name}`, got `%{given_type}`"
|
116
|
+
wrong_element_value: "[%{service_class_name}] Wrong value in output attribute hash `%{output_name}`, expected value of type `%{expected_type}` for `%{key_name}`, got `%{given_type}`"
|
109
117
|
type:
|
110
118
|
default_error:
|
111
119
|
default: "[%{service_class_name}] Wrong type of output attribute `%{output_name}`, expected `%{expected_type}`, got `%{given_type}`"
|
112
|
-
for_hash:
|
113
|
-
wrong_element_type: "[%{service_class_name}] Wrong type in output attribute hash `%{output_name}`, expected `%{expected_type}` for `%{key_name}`, got `%{given_type}`"
|
data/config/locales/ru.yml
CHANGED
@@ -34,14 +34,16 @@ ru:
|
|
34
34
|
default: "[%{service_class_name}] Инпут `%{input_name}` имеет значение `%{value}`, которое не кратно `%{option_value}`"
|
35
35
|
blank: "[%{service_class_name}] Инпут `%{input_name}` имеет недопустимое значение `%{option_value}` в опции `%{option_name}`"
|
36
36
|
divided_by_0: "[%{service_class_name}] Инпут `%{input_name}` имеет недопустимое значение `%{option_value}` в опции `%{option_name}`"
|
37
|
+
schema:
|
38
|
+
wrong_type: "[%{service_class_name}] Неправильный тип инпута `%{input_name}`, ожидалось `%{expected_type}`, получено `%{given_type}`"
|
39
|
+
wrong_element_type: "[%{service_class_name}] Неправильный тип в хеше инпута `%{input_name}`, для `%{key_name}` ожидалось `%{expected_type}`, получено `%{given_type}`"
|
40
|
+
wrong_element_value: "[%{service_class_name}] Неправильное значение в хеше инпута `%{input_name}`, для `%{key_name}` ожидалось значение с типом `%{expected_type}`, получено `%{given_type}`"
|
37
41
|
required:
|
38
42
|
default_error:
|
39
43
|
default: "[%{service_class_name}] Обязательный инпут `%{input_name}` отсутствует"
|
40
44
|
type:
|
41
45
|
default_error:
|
42
46
|
default: "[%{service_class_name}] Неправильный тип инпута `%{input_name}`, ожидалось `%{expected_type}`, получено `%{given_type}`"
|
43
|
-
for_hash:
|
44
|
-
wrong_element_type: "[%{service_class_name}] Неправильный тип в хеше инпута `%{input_name}`, для `%{key_name}` ожидалось `%{expected_type}`, получено `%{given_type}`"
|
45
47
|
tools:
|
46
48
|
find_unnecessary:
|
47
49
|
error: "[%{service_class_name}] Неожиданные атрибуты: `%{unnecessary_attributes}`"
|
@@ -74,11 +76,13 @@ ru:
|
|
74
76
|
default: "[%{service_class_name}] Внутренний атрибут `%{internal_name}` имеет значение `%{value}`, которое не кратно `%{option_value}`"
|
75
77
|
blank: "[%{service_class_name}] Внутренний атрибут `%{internal_name}` имеет недопустимое значение `%{option_value}` в опции `%{option_name}`"
|
76
78
|
divided_by_0: "[%{service_class_name}] Внутренний атрибут `%{internal_name}` имеет недопустимое значение `%{option_value}` в опции `%{option_name}`"
|
79
|
+
schema:
|
80
|
+
wrong_type: "[%{service_class_name}] Неправильный тип внутреннего атрибута `%{internal_name}`, ожидалось `%{expected_type}`, получено `%{given_type}`"
|
81
|
+
wrong_element_type: "[%{service_class_name}] Неправильный тип в хеше внутреннего атрибута `%{internal_name}`, для `%{key_name}` ожидалось `%{expected_type}`, получено `%{given_type}`"
|
82
|
+
wrong_element_value: "[%{service_class_name}] Неправильное значение в хеше внутреннего атрибута `%{internal_name}`, для `%{key_name}` ожидалось значение с типом `%{expected_type}`, получено `%{given_type}`"
|
77
83
|
type:
|
78
84
|
default_error:
|
79
85
|
default: "[%{service_class_name}] Неправильный тип внутреннего атрибута `%{internal_name}`, ожидалось `%{expected_type}`, получено `%{given_type}`"
|
80
|
-
for_hash:
|
81
|
-
wrong_element_type: "[%{service_class_name}] Неправильный тип в хеше внутреннего атрибута `%{internal_name}`, для `%{key_name}` ожидалось `%{expected_type}`, получено `%{given_type}`"
|
82
86
|
outputs:
|
83
87
|
undefined:
|
84
88
|
for_fetch: "[%{service_class_name}] Неизвестный выходящий атрибут `%{output_name}`"
|
@@ -106,8 +110,10 @@ ru:
|
|
106
110
|
default: "[%{service_class_name}] Выходящий атрибут `%{output_name}` имеет значение `%{value}`, которое не кратно `%{option_value}`"
|
107
111
|
blank: "[%{service_class_name}] Выходящий атрибут `%{output_name}` имеет недопустимое значение `%{option_value}` в опции `%{option_name}`"
|
108
112
|
divided_by_0: "[%{service_class_name}] Выходящий атрибут `%{output_name}` имеет недопустимое значение `%{option_value}` в опции `%{option_name}`"
|
113
|
+
schema:
|
114
|
+
wrong_type: "[%{service_class_name}] Неправильный тип выходящего атрибута `%{output_name}`, ожидалось `%{expected_type}`, получено `%{given_type}`"
|
115
|
+
wrong_element_type: "[%{service_class_name}] Неправильный тип в хеше выходящего атрибута `%{output_name}`, для `%{key_name}` ожидалось `%{expected_type}`, получено `%{given_type}`"
|
116
|
+
wrong_element_value: "[%{service_class_name}] Неправильное значение в хеше выходящего атрибута `%{output_name}`, для `%{key_name}` ожидалось значение с типом `%{expected_type}`, получено `%{given_type}`"
|
109
117
|
type:
|
110
118
|
default_error:
|
111
119
|
default: "[%{service_class_name}] Неправильный тип выходящего атрибута `%{output_name}`, ожидалось `%{expected_type}`, получено `%{given_type}`"
|
112
|
-
for_hash:
|
113
|
-
wrong_element_type: "[%{service_class_name}] Неправильный тип в хеше выходящего атрибута `%{output_name}`, для `%{key_name}` ожидалось `%{expected_type}`, получено `%{given_type}`"
|
@@ -72,6 +72,7 @@ module Servactory
|
|
72
72
|
Set[
|
73
73
|
Servactory::Maintenance::Attributes::OptionHelper.new(name: :optional, equivalent: { required: false }),
|
74
74
|
Servactory::ToolKit::DynamicOptions::ConsistsOf.use(collection_mode_class_names:),
|
75
|
+
Servactory::ToolKit::DynamicOptions::Schema.use(default_hash_mode_class_names:),
|
75
76
|
Servactory::ToolKit::DynamicOptions::Inclusion.use
|
76
77
|
]
|
77
78
|
end
|
@@ -79,6 +80,7 @@ module Servactory
|
|
79
80
|
def default_internal_option_helpers
|
80
81
|
Set[
|
81
82
|
Servactory::ToolKit::DynamicOptions::ConsistsOf.use(collection_mode_class_names:),
|
83
|
+
Servactory::ToolKit::DynamicOptions::Schema.use(default_hash_mode_class_names:),
|
82
84
|
Servactory::ToolKit::DynamicOptions::Inclusion.use
|
83
85
|
]
|
84
86
|
end
|
@@ -86,6 +88,7 @@ module Servactory
|
|
86
88
|
def default_output_option_helpers
|
87
89
|
Set[
|
88
90
|
Servactory::ToolKit::DynamicOptions::ConsistsOf.use(collection_mode_class_names:),
|
91
|
+
Servactory::ToolKit::DynamicOptions::Schema.use(default_hash_mode_class_names:),
|
89
92
|
Servactory::ToolKit::DynamicOptions::Inclusion.use
|
90
93
|
]
|
91
94
|
end
|
@@ -51,10 +51,6 @@ module Servactory
|
|
51
51
|
input_value = @context.send(:servactory_service_warehouse).fetch_input(input.name)
|
52
52
|
input_value = input.default if input.optional? && input_value.blank?
|
53
53
|
|
54
|
-
if input.hash_mode? && (tmp_schema = input.schema.fetch(:is)).present?
|
55
|
-
input_value = prepare_hash_values_inside(object: input_value, schema: tmp_schema)
|
56
|
-
end
|
57
|
-
|
58
54
|
input_prepare = input.prepare.fetch(:in, nil)
|
59
55
|
input_value = input_prepare.call(value: input_value) if input_prepare.present?
|
60
56
|
|
@@ -66,37 +62,6 @@ module Servactory
|
|
66
62
|
end
|
67
63
|
# rubocop:enable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Lint/UnusedMethodArgument
|
68
64
|
|
69
|
-
def prepare_hash_values_inside(object:, schema:) # rubocop:disable Metrics/MethodLength
|
70
|
-
return object unless object.respond_to?(:fetch)
|
71
|
-
|
72
|
-
schema.to_h do |schema_key, schema_value|
|
73
|
-
attribute_type = schema_value.fetch(:type, String)
|
74
|
-
|
75
|
-
result =
|
76
|
-
if attribute_type == Hash
|
77
|
-
prepare_hash_values_inside(
|
78
|
-
object: object.fetch(schema_key, {}),
|
79
|
-
schema: schema_value.except(*RESERVED_ATTRIBUTES)
|
80
|
-
)
|
81
|
-
else
|
82
|
-
fetch_hash_values_from(
|
83
|
-
value: object.fetch(schema_key, {}),
|
84
|
-
schema_value:,
|
85
|
-
attribute_required: schema_value.fetch(:required, true)
|
86
|
-
)
|
87
|
-
end
|
88
|
-
|
89
|
-
[schema_key, result]
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
def fetch_hash_values_from(value:, schema_value:, attribute_required:)
|
94
|
-
return value if attribute_required
|
95
|
-
return value if value.present?
|
96
|
-
|
97
|
-
schema_value.fetch(:default, nil)
|
98
|
-
end
|
99
|
-
|
100
65
|
def raise_error_for(type, name)
|
101
66
|
message_text = @context.send(:servactory_service_info).translate(
|
102
67
|
"inputs.undefined.for_#{type}",
|
@@ -38,13 +38,11 @@ module Servactory
|
|
38
38
|
name,
|
39
39
|
*helpers,
|
40
40
|
as: nil,
|
41
|
-
hash_mode_class_names:,
|
42
41
|
option_helpers:,
|
43
42
|
**options
|
44
43
|
)
|
45
44
|
@name = name
|
46
45
|
@internal_name = as.presence || name
|
47
|
-
@hash_mode_class_names = hash_mode_class_names
|
48
46
|
@option_helpers = option_helpers
|
49
47
|
|
50
48
|
register_options(helpers:, options:)
|
@@ -71,13 +69,11 @@ module Servactory
|
|
71
69
|
|
72
70
|
options_registrar = Servactory::Maintenance::Attributes::Options::Registrar.register(
|
73
71
|
attribute: self,
|
74
|
-
hash_mode_class_names: @hash_mode_class_names,
|
75
72
|
options:,
|
76
73
|
features: {
|
77
74
|
required: true,
|
78
75
|
types: true,
|
79
76
|
default: true,
|
80
|
-
hash: true,
|
81
77
|
must: true,
|
82
78
|
prepare: true
|
83
79
|
}
|
@@ -29,12 +29,10 @@ module Servactory
|
|
29
29
|
def initialize(
|
30
30
|
name,
|
31
31
|
*helpers,
|
32
|
-
hash_mode_class_names:,
|
33
32
|
option_helpers:,
|
34
33
|
**options
|
35
34
|
)
|
36
35
|
@name = name
|
37
|
-
@hash_mode_class_names = hash_mode_class_names
|
38
36
|
@option_helpers = option_helpers
|
39
37
|
|
40
38
|
register_options(helpers:, options:)
|
@@ -60,11 +58,9 @@ module Servactory
|
|
60
58
|
|
61
59
|
options_registrar = Servactory::Maintenance::Attributes::Options::Registrar.register(
|
62
60
|
attribute: self,
|
63
|
-
hash_mode_class_names: @hash_mode_class_names,
|
64
61
|
options:,
|
65
62
|
features: {
|
66
63
|
types: true,
|
67
|
-
hash: true,
|
68
64
|
must: true
|
69
65
|
}
|
70
66
|
)
|
@@ -75,7 +75,6 @@ module Servactory
|
|
75
75
|
)
|
76
76
|
end
|
77
77
|
|
78
|
-
# rubocop:disable Metrics/MethodLength
|
79
78
|
def prepare_advanced_for(
|
80
79
|
body:,
|
81
80
|
body_key:,
|
@@ -83,22 +82,17 @@ module Servactory
|
|
83
82
|
body_fallback:
|
84
83
|
)
|
85
84
|
if body.is_a?(Hash)
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
body: body.fetch(body_key, message.present? ? body_value : body_fallback),
|
94
|
-
message:
|
95
|
-
)
|
96
|
-
end
|
85
|
+
message = body.fetch(:message, nil)
|
86
|
+
|
87
|
+
DEFAULT_BODY.call(
|
88
|
+
key: body_key,
|
89
|
+
body: body.fetch(body_key, message.present? ? body_value : body_fallback),
|
90
|
+
message:
|
91
|
+
)
|
97
92
|
else
|
98
93
|
DEFAULT_BODY.call(key: body_key, body:)
|
99
94
|
end
|
100
95
|
end
|
101
|
-
# rubocop:enable Metrics/MethodLength
|
102
96
|
|
103
97
|
def prepare_methods_for(attribute)
|
104
98
|
attribute.instance_eval(define_methods_template) if define_methods_template.present?
|
@@ -10,7 +10,6 @@ module Servactory
|
|
10
10
|
required
|
11
11
|
default
|
12
12
|
collection
|
13
|
-
hash
|
14
13
|
must
|
15
14
|
prepare
|
16
15
|
].freeze
|
@@ -19,7 +18,6 @@ module Servactory
|
|
19
18
|
required: false,
|
20
19
|
types: false,
|
21
20
|
default: false,
|
22
|
-
hash: false,
|
23
21
|
must: false,
|
24
22
|
prepare: false
|
25
23
|
}.freeze
|
@@ -30,9 +28,8 @@ module Servactory
|
|
30
28
|
new(...).register
|
31
29
|
end
|
32
30
|
|
33
|
-
def initialize(attribute:,
|
31
|
+
def initialize(attribute:, options:, features:)
|
34
32
|
@attribute = attribute
|
35
|
-
@hash_mode_class_names = hash_mode_class_names
|
36
33
|
@options = options
|
37
34
|
@features = DEFAULT_FEATURES.merge(features)
|
38
35
|
end
|
@@ -46,7 +43,6 @@ module Servactory
|
|
46
43
|
# Validation Class: Servactory::Maintenance::Attributes::Validations::Type
|
47
44
|
register_types_option if @features.fetch(:types)
|
48
45
|
register_default_option if @features.fetch(:default)
|
49
|
-
register_hash_option if @features.fetch(:hash)
|
50
46
|
|
51
47
|
# Validation Class: Servactory::Maintenance::Attributes::Validations::Must
|
52
48
|
register_must_option if @features.fetch(:must)
|
@@ -116,24 +112,6 @@ module Servactory
|
|
116
112
|
)
|
117
113
|
end
|
118
114
|
|
119
|
-
def register_hash_option # rubocop:disable Metrics/MethodLength
|
120
|
-
collection << Servactory::Maintenance::Attributes::Option.new(
|
121
|
-
name: :schema,
|
122
|
-
attribute: @attribute,
|
123
|
-
validation_class: Servactory::Maintenance::Attributes::Validations::Type,
|
124
|
-
define_methods: [
|
125
|
-
Servactory::Maintenance::Attributes::DefineMethod.new(
|
126
|
-
name: :hash_mode?,
|
127
|
-
content: ->(**) { @hash_mode_class_names.include?(@options.fetch(:type)) }
|
128
|
-
)
|
129
|
-
],
|
130
|
-
need_for_checks: false,
|
131
|
-
body_key: :is,
|
132
|
-
body_fallback: {},
|
133
|
-
**@options
|
134
|
-
)
|
135
|
-
end
|
136
|
-
|
137
115
|
def register_must_option # rubocop:disable Metrics/MethodLength
|
138
116
|
collection << Servactory::Maintenance::Attributes::Option.new(
|
139
117
|
name: :must,
|
@@ -8,7 +8,7 @@ module Servactory
|
|
8
8
|
module_function
|
9
9
|
|
10
10
|
def default_message
|
11
|
-
lambda do |service:, value:, code:, input: nil, internal: nil, output: nil, reason: nil
|
11
|
+
lambda do |service:, value:, code:, input: nil, internal: nil, output: nil, reason: nil, **|
|
12
12
|
attribute = Servactory::Utils.define_attribute_with(input:, internal:, output:)
|
13
13
|
|
14
14
|
service.translate(
|
@@ -5,53 +5,18 @@ module Servactory
|
|
5
5
|
module Attributes
|
6
6
|
module Translator
|
7
7
|
module Type
|
8
|
-
|
8
|
+
module_function
|
9
9
|
|
10
10
|
def default_message
|
11
|
-
lambda do |service:, attribute:,
|
12
|
-
if attribute.hash_mode? && key_name.present?
|
13
|
-
for_hash_mode_with(service:, attribute:, key_name:,
|
14
|
-
expected_type:, given_type:)
|
15
|
-
else
|
16
|
-
for_others_with(service:, attribute:,
|
17
|
-
expected_type:, given_type:)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
private
|
23
|
-
|
24
|
-
def for_hash_mode_with(service:, attribute:, key_name:, expected_type:, given_type:) # rubocop:disable Metrics/MethodLength
|
25
|
-
hash_message = attribute.schema.fetch(:message)
|
26
|
-
|
27
|
-
if hash_message.is_a?(Proc)
|
28
|
-
hash_message.call(
|
29
|
-
**Servactory::Utils.fetch_hash_with_desired_attribute(attribute),
|
30
|
-
key_name:,
|
31
|
-
expected_type:,
|
32
|
-
given_type:
|
33
|
-
)
|
34
|
-
elsif hash_message.is_a?(String) && hash_message.present?
|
35
|
-
hash_message
|
36
|
-
else
|
11
|
+
lambda do |service:, attribute:, expected_type:, given_type:, **|
|
37
12
|
service.translate(
|
38
|
-
"#{attribute.i18n_name}.validations.type.default_error.
|
13
|
+
"#{attribute.i18n_name}.validations.type.default_error.default",
|
39
14
|
"#{attribute.system_name}_name": attribute.name,
|
40
|
-
key_name:,
|
41
15
|
expected_type:,
|
42
16
|
given_type:
|
43
17
|
)
|
44
18
|
end
|
45
19
|
end
|
46
|
-
|
47
|
-
def for_others_with(service:, attribute:, expected_type:, given_type:)
|
48
|
-
service.translate(
|
49
|
-
"#{attribute.i18n_name}.validations.type.default_error.default",
|
50
|
-
"#{attribute.system_name}_name": attribute.name,
|
51
|
-
expected_type:,
|
52
|
-
given_type:
|
53
|
-
)
|
54
|
-
end
|
55
20
|
end
|
56
21
|
end
|
57
22
|
end
|
@@ -28,11 +28,11 @@ module Servactory
|
|
28
28
|
|
29
29
|
def check
|
30
30
|
@check_options.each do |code, options|
|
31
|
-
message, reason = call_or_fetch_message_from(code, options)
|
31
|
+
message, reason, meta = call_or_fetch_message_from(code, options)
|
32
32
|
|
33
33
|
next if message.blank?
|
34
34
|
|
35
|
-
add_error_with(message, code, reason)
|
35
|
+
add_error_with(message, code, reason, meta)
|
36
36
|
end
|
37
37
|
|
38
38
|
errors
|
@@ -43,14 +43,15 @@ module Servactory
|
|
43
43
|
def call_or_fetch_message_from(code, options) # rubocop:disable Metrics/MethodLength
|
44
44
|
check, message = options.values_at(:is, :message)
|
45
45
|
|
46
|
-
check_result, check_result_code =
|
46
|
+
check_result, check_result_code, meta =
|
47
47
|
check.call(value: @value, **Servactory::Utils.fetch_hash_with_desired_attribute(@attribute))
|
48
48
|
|
49
49
|
return if check_result
|
50
50
|
|
51
51
|
[
|
52
52
|
message.presence || Servactory::Maintenance::Attributes::Translator::Must.default_message,
|
53
|
-
check_result_code
|
53
|
+
check_result_code,
|
54
|
+
meta
|
54
55
|
]
|
55
56
|
rescue StandardError => e
|
56
57
|
add_syntax_error_with(
|
@@ -62,14 +63,15 @@ module Servactory
|
|
62
63
|
|
63
64
|
########################################################################
|
64
65
|
|
65
|
-
def add_error_with(message, code, reason)
|
66
|
+
def add_error_with(message, code, reason, meta = {})
|
66
67
|
add_error(
|
67
68
|
message:,
|
68
69
|
service: @context.send(:servactory_service_info),
|
69
70
|
**Servactory::Utils.fetch_hash_with_desired_attribute(@attribute),
|
70
71
|
value: @value,
|
71
72
|
code:,
|
72
|
-
reason
|
73
|
+
reason:,
|
74
|
+
meta:
|
73
75
|
)
|
74
76
|
end
|
75
77
|
|
@@ -16,32 +16,9 @@ module Servactory
|
|
16
16
|
@error_callback = error_callback
|
17
17
|
end
|
18
18
|
|
19
|
-
def validate! # rubocop:disable Metrics/MethodLength
|
20
|
-
|
21
|
-
|
22
|
-
if @attribute.hash_mode?
|
23
|
-
object_schema_validator = Servactory::Maintenance::Validations::ObjectSchema.validate(
|
24
|
-
object: @value,
|
25
|
-
schema: @attribute.schema
|
26
|
-
)
|
27
|
-
|
28
|
-
return if object_schema_validator.valid?
|
29
|
-
else
|
30
|
-
return if prepared_types.any? do |type| # rubocop:disable Style/IfInsideElse
|
31
|
-
@value.is_a?(type)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
if (first_error = object_schema_validator&.errors&.first).present?
|
36
|
-
return @error_callback.call(
|
37
|
-
message: Servactory::Maintenance::Attributes::Translator::Type.default_message,
|
38
|
-
service: @context.send(:servactory_service_info),
|
39
|
-
attribute: @attribute,
|
40
|
-
value: @value,
|
41
|
-
key_name: first_error.fetch(:key_name),
|
42
|
-
expected_type: first_error.fetch(:expected_type),
|
43
|
-
given_type: first_error.fetch(:given_type)
|
44
|
-
)
|
19
|
+
def validate! # rubocop:disable Metrics/MethodLength
|
20
|
+
return if prepared_types.any? do |type|
|
21
|
+
@value.is_a?(type)
|
45
22
|
end
|
46
23
|
|
47
24
|
@error_callback.call(
|
@@ -29,12 +29,10 @@ module Servactory
|
|
29
29
|
def initialize(
|
30
30
|
name,
|
31
31
|
*helpers,
|
32
|
-
hash_mode_class_names:,
|
33
32
|
option_helpers:,
|
34
33
|
**options
|
35
34
|
)
|
36
35
|
@name = name
|
37
|
-
@hash_mode_class_names = hash_mode_class_names
|
38
36
|
@option_helpers = option_helpers
|
39
37
|
|
40
38
|
register_options(helpers:, options:)
|
@@ -60,11 +58,9 @@ module Servactory
|
|
60
58
|
|
61
59
|
options_registrar = Servactory::Maintenance::Attributes::Options::Registrar.register(
|
62
60
|
attribute: self,
|
63
|
-
hash_mode_class_names: @hash_mode_class_names,
|
64
61
|
options:,
|
65
62
|
features: {
|
66
63
|
types: true,
|
67
|
-
hash: true,
|
68
64
|
must: true
|
69
65
|
}
|
70
66
|
)
|
data/lib/servactory/test_kit/rspec/matchers/have_service_attribute_matchers/consists_of_matcher.rb
CHANGED
@@ -6,17 +6,18 @@ module Servactory
|
|
6
6
|
module Matchers
|
7
7
|
module HaveServiceAttributeMatchers
|
8
8
|
class ConsistsOfMatcher
|
9
|
+
OPTION_NAME = :consists_of
|
10
|
+
OPTION_BODY_KEY = :type
|
11
|
+
|
9
12
|
attr_reader :missing_option
|
10
13
|
|
11
|
-
def initialize(described_class, attribute_type, attribute_name, option_types, consists_of_types
|
12
|
-
custom_message)
|
14
|
+
def initialize(described_class, attribute_type, attribute_name, option_types, consists_of_types)
|
13
15
|
@described_class = described_class
|
14
16
|
@attribute_type = attribute_type
|
15
17
|
@attribute_type_plural = attribute_type.to_s.pluralize.to_sym
|
16
18
|
@attribute_name = attribute_name
|
17
19
|
@option_types = option_types
|
18
20
|
@consists_of_types = consists_of_types
|
19
|
-
@custom_message = custom_message
|
20
21
|
|
21
22
|
@attribute_data = described_class.info.public_send(attribute_type_plural).fetch(attribute_name)
|
22
23
|
|
@@ -46,32 +47,14 @@ module Servactory
|
|
46
47
|
:attribute_name,
|
47
48
|
:option_types,
|
48
49
|
:consists_of_types,
|
49
|
-
:custom_message,
|
50
50
|
:attribute_data
|
51
51
|
|
52
|
-
def submatcher_passes?(_subject)
|
53
|
-
attribute_consists_of = attribute_data.fetch(
|
54
|
-
attribute_consists_of_types = Array(attribute_consists_of.fetch(
|
55
|
-
attribute_consists_of_message = attribute_consists_of.fetch(:message)
|
56
|
-
|
57
|
-
matched = attribute_consists_of_types.difference(consists_of_types).empty? &&
|
58
|
-
consists_of_types.difference(attribute_consists_of_types).empty?
|
59
|
-
|
60
|
-
if custom_message.present? && !attribute_consists_of_message.nil?
|
61
|
-
if custom_message.is_a?(RSpec::Matchers::BuiltIn::BaseMatcher)
|
62
|
-
RSpec::Expectations::ValueExpectationTarget
|
63
|
-
.new(attribute_consists_of_message)
|
64
|
-
.to(custom_message)
|
65
|
-
else
|
66
|
-
matched &&= if attribute_consists_of_message.is_a?(Proc)
|
67
|
-
attribute_consists_of_message.call.casecmp(custom_message).zero?
|
68
|
-
else
|
69
|
-
attribute_consists_of_message.casecmp(custom_message).zero?
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
52
|
+
def submatcher_passes?(_subject)
|
53
|
+
attribute_consists_of = attribute_data.fetch(OPTION_NAME)
|
54
|
+
attribute_consists_of_types = Array(attribute_consists_of.fetch(OPTION_BODY_KEY))
|
73
55
|
|
74
|
-
|
56
|
+
attribute_consists_of_types.difference(consists_of_types).empty? &&
|
57
|
+
consists_of_types.difference(attribute_consists_of_types).empty?
|
75
58
|
end
|
76
59
|
|
77
60
|
def build_missing_option
|