servactory 2.12.0.rc1 → 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 +18 -12
- data/config/locales/ru.yml +18 -12
- data/lib/servactory/configuration/option_helpers/option_helpers_collection.rb +5 -1
- data/lib/servactory/configuration/setup.rb +9 -3
- data/lib/servactory/context/workspace/inputs.rb +0 -35
- data/lib/servactory/info/builder.rb +103 -0
- data/lib/servactory/info/dsl.rb +8 -51
- data/lib/servactory/info/result.rb +4 -4
- data/lib/servactory/inputs/dsl.rb +0 -1
- data/lib/servactory/inputs/input.rb +8 -9
- data/lib/servactory/internals/dsl.rb +0 -1
- data/lib/servactory/internals/internal.rb +5 -8
- data/lib/servactory/maintenance/attributes/option.rb +7 -13
- data/lib/servactory/maintenance/attributes/option_helper.rb +8 -2
- data/lib/servactory/maintenance/attributes/options/registrar.rb +2 -57
- 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 +5 -8
- data/lib/servactory/test_kit/rspec/matchers/have_service_attribute_matchers/consists_of_matcher.rb +8 -13
- data/lib/servactory/test_kit/rspec/matchers/have_service_attribute_matchers/inclusion_matcher.rb +7 -4
- 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 +29 -7
- data/lib/servactory/test_kit/rspec/matchers/have_service_input_matchers/valid_with_matcher.rb +12 -5
- data/lib/servactory/test_kit/rspec/matchers/have_service_internal_matcher.rb +31 -7
- data/lib/servactory/tool_kit/dynamic_options/inclusion.rb +63 -0
- data/lib/servactory/tool_kit/dynamic_options/must.rb +34 -6
- data/lib/servactory/tool_kit/dynamic_options/schema.rb +193 -0
- data/lib/servactory/version.rb +1 -1
- metadata +7 -5
- data/lib/servactory/maintenance/attributes/translator/inclusion.rb +0 -26
- data/lib/servactory/maintenance/attributes/validations/inclusion.rb +0 -63
- data/lib/servactory/maintenance/validations/object_schema.rb +0 -116
@@ -1,63 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Servactory
|
4
|
-
module Maintenance
|
5
|
-
module Attributes
|
6
|
-
module Validations
|
7
|
-
class Inclusion < Base
|
8
|
-
def self.check(context:, attribute:, value:, check_key:, **)
|
9
|
-
return unless should_be_checked_for?(attribute, value, check_key)
|
10
|
-
|
11
|
-
new(context:, attribute:, value:).check
|
12
|
-
end
|
13
|
-
|
14
|
-
# rubocop:disable Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
15
|
-
def self.should_be_checked_for?(attribute, value, check_key)
|
16
|
-
check_key == :inclusion && (
|
17
|
-
(
|
18
|
-
attribute.input? && (
|
19
|
-
attribute.required? || (
|
20
|
-
attribute.optional? && !attribute.default.nil?
|
21
|
-
) || (
|
22
|
-
attribute.optional? && !value.nil?
|
23
|
-
)
|
24
|
-
)
|
25
|
-
) || attribute.internal? || attribute.output?
|
26
|
-
)
|
27
|
-
end
|
28
|
-
# rubocop:enable Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
29
|
-
|
30
|
-
##########################################################################
|
31
|
-
|
32
|
-
def initialize(context:, attribute:, value:)
|
33
|
-
super()
|
34
|
-
|
35
|
-
@context = context
|
36
|
-
@attribute = attribute
|
37
|
-
@value = value
|
38
|
-
end
|
39
|
-
|
40
|
-
def check
|
41
|
-
inclusion_in, message = @attribute.inclusion.values_at(:in, :message)
|
42
|
-
|
43
|
-
return if inclusion_in.nil?
|
44
|
-
return if inclusion_in.include?(@value)
|
45
|
-
|
46
|
-
add_error_with(message)
|
47
|
-
end
|
48
|
-
|
49
|
-
private
|
50
|
-
|
51
|
-
def add_error_with(message)
|
52
|
-
add_error(
|
53
|
-
message: message.presence || Servactory::Maintenance::Attributes::Translator::Inclusion.default_message,
|
54
|
-
service: @context.send(:servactory_service_info),
|
55
|
-
**Servactory::Utils.fetch_hash_with_desired_attribute(@attribute),
|
56
|
-
value: @value
|
57
|
-
)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
@@ -1,116 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Servactory
|
4
|
-
module Maintenance
|
5
|
-
module Validations
|
6
|
-
class ObjectSchema
|
7
|
-
RESERVED_ATTRIBUTES = %i[type required default].freeze
|
8
|
-
private_constant :RESERVED_ATTRIBUTES
|
9
|
-
|
10
|
-
attr_reader :errors
|
11
|
-
|
12
|
-
def self.validate(...)
|
13
|
-
new(...).validate
|
14
|
-
end
|
15
|
-
|
16
|
-
def initialize(object:, schema:)
|
17
|
-
@object = object
|
18
|
-
@schema = schema.fetch(:is)
|
19
|
-
|
20
|
-
@errors = []
|
21
|
-
end
|
22
|
-
|
23
|
-
def validate
|
24
|
-
validate_for!(object: @object, schema: @schema)
|
25
|
-
|
26
|
-
self
|
27
|
-
end
|
28
|
-
|
29
|
-
def valid?
|
30
|
-
@errors.empty?
|
31
|
-
end
|
32
|
-
|
33
|
-
private
|
34
|
-
|
35
|
-
def validate_for!(object:, schema:, root_schema_key: nil) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
36
|
-
unless object.respond_to?(:fetch)
|
37
|
-
add_error(key_name: root_schema_key, expected_type: Hash.name, given_type: object.class.name)
|
38
|
-
return
|
39
|
-
end
|
40
|
-
|
41
|
-
schema.each do |schema_key, schema_value|
|
42
|
-
attribute_type = schema_value.fetch(:type, String)
|
43
|
-
|
44
|
-
if attribute_type == Hash
|
45
|
-
validate_for!(
|
46
|
-
object: object.fetch(schema_key, {}),
|
47
|
-
schema: schema_value.except(*RESERVED_ATTRIBUTES),
|
48
|
-
root_schema_key: schema_key
|
49
|
-
)
|
50
|
-
else
|
51
|
-
is_success = validate_with(
|
52
|
-
object:,
|
53
|
-
schema_key:,
|
54
|
-
schema_value:,
|
55
|
-
attribute_type:,
|
56
|
-
attribute_required: schema_value.fetch(:required, true)
|
57
|
-
)
|
58
|
-
|
59
|
-
next if is_success
|
60
|
-
|
61
|
-
add_error(
|
62
|
-
key_name: schema_key,
|
63
|
-
expected_type: attribute_type,
|
64
|
-
given_type: object.fetch(schema_key, nil).class.name
|
65
|
-
)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
def validate_with(object:, schema_key:, schema_value:, attribute_type:, attribute_required:) # rubocop:disable Metrics/MethodLength
|
71
|
-
unless should_be_checked_for?(
|
72
|
-
object:,
|
73
|
-
schema_key:,
|
74
|
-
schema_value:,
|
75
|
-
required: attribute_required
|
76
|
-
) # do
|
77
|
-
return true
|
78
|
-
end
|
79
|
-
|
80
|
-
value = object.fetch(schema_key, nil)
|
81
|
-
prepared_value = prepare_value_from(schema_value:, value:, required: attribute_required)
|
82
|
-
|
83
|
-
Array(attribute_type).uniq.any? { |type| prepared_value.is_a?(type) }
|
84
|
-
end
|
85
|
-
|
86
|
-
def should_be_checked_for?(object:, schema_key:, schema_value:, required:)
|
87
|
-
required || (
|
88
|
-
!required && !fetch_default_from(schema_value).nil?
|
89
|
-
) || (
|
90
|
-
!required && !object.fetch(schema_key, nil).nil?
|
91
|
-
)
|
92
|
-
end
|
93
|
-
|
94
|
-
def prepare_value_from(schema_value:, value:, required:)
|
95
|
-
if !required && !fetch_default_from(schema_value).nil? && value.blank?
|
96
|
-
fetch_default_from(schema_value)
|
97
|
-
else
|
98
|
-
value
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
def fetch_default_from(value)
|
103
|
-
value.fetch(:default, nil)
|
104
|
-
end
|
105
|
-
|
106
|
-
def add_error(key_name:, expected_type:, given_type:)
|
107
|
-
@errors << {
|
108
|
-
key_name:,
|
109
|
-
expected_type:,
|
110
|
-
given_type:
|
111
|
-
}
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|