servactory 1.9.5 → 2.0.0.rc2
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 -4
- data/config/locales/ru.yml +20 -6
- data/lib/servactory/configuration/dsl.rb +2 -0
- data/lib/servactory/configuration/factory.rb +8 -0
- data/lib/servactory/configuration/setup.rb +20 -4
- data/lib/servactory/context/workspace/inputs.rb +41 -7
- data/lib/servactory/context/workspace/outputs.rb +1 -1
- data/lib/servactory/context/workspace.rb +0 -1
- data/lib/servactory/dsl.rb +17 -0
- data/lib/servactory/inputs/collection.rb +1 -1
- data/lib/servactory/inputs/dsl.rb +2 -0
- data/lib/servactory/inputs/input.rb +101 -82
- data/lib/servactory/inputs/tools/distributor.rb +24 -0
- data/lib/servactory/inputs/tools/rules.rb +3 -3
- data/lib/servactory/inputs/tools/{find_unnecessary.rb → unnecessary.rb} +4 -4
- data/lib/servactory/inputs/tools/validation.rb +5 -7
- data/lib/servactory/inputs/validations/inclusion.rb +14 -9
- data/lib/servactory/inputs/validations/must.rb +26 -17
- data/lib/servactory/inputs/validations/required.rb +15 -10
- data/lib/servactory/inputs/validations/type.rb +85 -34
- data/lib/servactory/inputs/workspace.rb +6 -3
- data/lib/servactory/internals/dsl.rb +6 -1
- data/lib/servactory/internals/internal.rb +82 -14
- data/lib/servactory/internals/validations/type.rb +110 -29
- data/lib/servactory/maintenance/attributes/define_conflict.rb +15 -0
- data/lib/servactory/maintenance/attributes/define_method.rb +17 -0
- data/lib/servactory/maintenance/attributes/option.rb +115 -0
- data/lib/servactory/maintenance/attributes/option_helper.rb +17 -0
- data/lib/servactory/maintenance/attributes/option_helpers_collection.rb +20 -0
- data/lib/servactory/maintenance/attributes/options_collection.rb +48 -0
- data/lib/servactory/maintenance/collection_mode/class_names_collection.rb +16 -0
- data/lib/servactory/maintenance/hash_mode/class_names_collection.rb +16 -0
- data/lib/servactory/maintenance/validations/object_schema.rb +119 -0
- data/lib/servactory/methods/workspace.rb +2 -0
- data/lib/servactory/outputs/dsl.rb +6 -1
- data/lib/servactory/outputs/output.rb +80 -19
- data/lib/servactory/outputs/validations/type.rb +110 -31
- data/lib/servactory/version.rb +5 -4
- metadata +33 -15
- data/lib/servactory/inputs/define_input_conflict.rb +0 -13
- data/lib/servactory/inputs/define_input_method.rb +0 -15
- data/lib/servactory/inputs/option.rb +0 -98
- data/lib/servactory/inputs/option_helper.rb +0 -15
- data/lib/servactory/inputs/option_helpers_collection.rb +0 -18
- data/lib/servactory/inputs/options_collection.rb +0 -46
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Servactory
|
4
|
+
module Inputs
|
5
|
+
module Tools
|
6
|
+
class Distributor
|
7
|
+
def self.assign!(...)
|
8
|
+
new(...).assign!
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize(incoming_arguments, collection_of_inputs)
|
12
|
+
@incoming_arguments = incoming_arguments
|
13
|
+
@collection_of_inputs = collection_of_inputs
|
14
|
+
end
|
15
|
+
|
16
|
+
def assign!
|
17
|
+
@collection_of_inputs.map do |input|
|
18
|
+
input.value = @incoming_arguments.fetch(input.name, nil)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -4,8 +4,8 @@ module Servactory
|
|
4
4
|
module Inputs
|
5
5
|
module Tools
|
6
6
|
class Rules
|
7
|
-
def self.
|
8
|
-
new(...).
|
7
|
+
def self.check!(...)
|
8
|
+
new(...).check!
|
9
9
|
end
|
10
10
|
|
11
11
|
def initialize(context, collection_of_inputs)
|
@@ -13,7 +13,7 @@ module Servactory
|
|
13
13
|
@collection_of_inputs = collection_of_inputs
|
14
14
|
end
|
15
15
|
|
16
|
-
def
|
16
|
+
def check!
|
17
17
|
@collection_of_inputs.each do |input|
|
18
18
|
check_for!(input)
|
19
19
|
end
|
@@ -3,9 +3,9 @@
|
|
3
3
|
module Servactory
|
4
4
|
module Inputs
|
5
5
|
module Tools
|
6
|
-
class
|
7
|
-
def self.
|
8
|
-
new(...).
|
6
|
+
class Unnecessary
|
7
|
+
def self.find!(...)
|
8
|
+
new(...).find!
|
9
9
|
end
|
10
10
|
|
11
11
|
def initialize(context, incoming_arguments, collection_of_inputs)
|
@@ -14,7 +14,7 @@ module Servactory
|
|
14
14
|
@collection_of_inputs = collection_of_inputs
|
15
15
|
end
|
16
16
|
|
17
|
-
def
|
17
|
+
def find!
|
18
18
|
return if unnecessary_attributes.empty?
|
19
19
|
|
20
20
|
message_text = I18n.t(
|
@@ -8,9 +8,8 @@ module Servactory
|
|
8
8
|
new(...).validate!
|
9
9
|
end
|
10
10
|
|
11
|
-
def initialize(context,
|
11
|
+
def initialize(context, collection_of_inputs)
|
12
12
|
@context = context
|
13
|
-
@incoming_arguments = incoming_arguments
|
14
13
|
@collection_of_inputs = collection_of_inputs
|
15
14
|
end
|
16
15
|
|
@@ -32,8 +31,8 @@ module Servactory
|
|
32
31
|
|
33
32
|
def process_option(check_key, check_options, input:)
|
34
33
|
validation_classes_from(input).each do |validation_class|
|
35
|
-
errors_from_checks =
|
36
|
-
validation_class,
|
34
|
+
errors_from_checks = process_validation_class(
|
35
|
+
validation_class: validation_class,
|
37
36
|
input: input,
|
38
37
|
check_key: check_key,
|
39
38
|
check_options: check_options
|
@@ -43,8 +42,8 @@ module Servactory
|
|
43
42
|
end
|
44
43
|
end
|
45
44
|
|
46
|
-
def
|
47
|
-
validation_class
|
45
|
+
def process_validation_class(
|
46
|
+
validation_class:,
|
48
47
|
input:,
|
49
48
|
check_key:,
|
50
49
|
check_options:
|
@@ -52,7 +51,6 @@ module Servactory
|
|
52
51
|
validation_class.check(
|
53
52
|
context: @context,
|
54
53
|
input: input,
|
55
|
-
value: @incoming_arguments.fetch(input.name, nil),
|
56
54
|
check_key: check_key,
|
57
55
|
check_options: check_options
|
58
56
|
)
|
@@ -16,43 +16,48 @@ module Servactory
|
|
16
16
|
|
17
17
|
private_constant :DEFAULT_MESSAGE
|
18
18
|
|
19
|
-
def self.check(context:, input:,
|
20
|
-
return unless should_be_checked_for?(input,
|
19
|
+
def self.check(context:, input:, check_key:, **)
|
20
|
+
return unless should_be_checked_for?(input, check_key)
|
21
21
|
|
22
|
-
new(context: context, input: input
|
22
|
+
new(context: context, input: input).check
|
23
23
|
end
|
24
24
|
|
25
|
-
def self.should_be_checked_for?(input,
|
25
|
+
def self.should_be_checked_for?(input, check_key)
|
26
26
|
check_key == :inclusion && (
|
27
27
|
input.required? || (
|
28
28
|
input.optional? && !input.default.nil?
|
29
29
|
) || (
|
30
|
-
input.optional? && !value.nil?
|
30
|
+
input.optional? && !input.value.nil?
|
31
31
|
)
|
32
32
|
)
|
33
33
|
end
|
34
34
|
|
35
35
|
##########################################################################
|
36
36
|
|
37
|
-
def initialize(context:, input
|
37
|
+
def initialize(context:, input:)
|
38
38
|
super()
|
39
39
|
|
40
40
|
@context = context
|
41
41
|
@input = input
|
42
|
-
@value = value
|
43
42
|
end
|
44
43
|
|
45
44
|
def check
|
46
45
|
inclusion_in, message = @input.inclusion.values_at(:in, :message)
|
47
46
|
|
48
47
|
return if inclusion_in.nil?
|
49
|
-
return if inclusion_in.include?(@value)
|
48
|
+
return if inclusion_in.include?(@input.value)
|
50
49
|
|
50
|
+
add_error_with(message)
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def add_error_with(message)
|
51
56
|
add_error(
|
52
57
|
message.presence || DEFAULT_MESSAGE,
|
53
58
|
service_class_name: @context.class.name,
|
54
59
|
input: @input,
|
55
|
-
value: @value
|
60
|
+
value: @input.value
|
56
61
|
)
|
57
62
|
end
|
58
63
|
end
|
@@ -27,10 +27,10 @@ module Servactory
|
|
27
27
|
|
28
28
|
private_constant :DEFAULT_MESSAGE, :SYNTAX_ERROR_MESSAGE
|
29
29
|
|
30
|
-
def self.check(context:, input:,
|
30
|
+
def self.check(context:, input:, check_key:, check_options:)
|
31
31
|
return unless should_be_checked_for?(input, check_key)
|
32
32
|
|
33
|
-
new(context: context, input: input,
|
33
|
+
new(context: context, input: input, check_options: check_options).check
|
34
34
|
end
|
35
35
|
|
36
36
|
def self.should_be_checked_for?(input, check_key)
|
@@ -39,28 +39,21 @@ module Servactory
|
|
39
39
|
|
40
40
|
##########################################################################
|
41
41
|
|
42
|
-
def initialize(context:, input:,
|
42
|
+
def initialize(context:, input:, check_options:)
|
43
43
|
super()
|
44
44
|
|
45
45
|
@context = context
|
46
46
|
@input = input
|
47
|
-
@value = value
|
48
47
|
@check_options = check_options
|
49
48
|
end
|
50
49
|
|
51
|
-
def check
|
50
|
+
def check
|
52
51
|
@check_options.each do |code, options|
|
53
52
|
message = call_or_fetch_message_from(code, options)
|
54
53
|
|
55
54
|
next if message.blank?
|
56
55
|
|
57
|
-
|
58
|
-
message,
|
59
|
-
service_class_name: @context.class.name,
|
60
|
-
input: @input,
|
61
|
-
value: @value,
|
62
|
-
code: code
|
63
|
-
)
|
56
|
+
add_error_with(message, code)
|
64
57
|
end
|
65
58
|
|
66
59
|
errors
|
@@ -68,20 +61,36 @@ module Servactory
|
|
68
61
|
|
69
62
|
private
|
70
63
|
|
71
|
-
def call_or_fetch_message_from(code, options)
|
64
|
+
def call_or_fetch_message_from(code, options)
|
72
65
|
check, message = options.values_at(:is, :message)
|
73
66
|
|
74
|
-
return if check.call(value: @value)
|
67
|
+
return if check.call(value: @input.value)
|
75
68
|
|
76
69
|
message.presence || DEFAULT_MESSAGE
|
77
70
|
rescue StandardError => e
|
71
|
+
add_syntax_error_with(SYNTAX_ERROR_MESSAGE, code, e.message)
|
72
|
+
end
|
73
|
+
|
74
|
+
########################################################################
|
75
|
+
|
76
|
+
def add_error_with(message, code)
|
78
77
|
add_error(
|
79
|
-
|
78
|
+
message,
|
80
79
|
service_class_name: @context.class.name,
|
81
80
|
input: @input,
|
82
|
-
value: @value,
|
81
|
+
value: @input.value,
|
82
|
+
code: code
|
83
|
+
)
|
84
|
+
end
|
85
|
+
|
86
|
+
def add_syntax_error_with(message, code, exception_message)
|
87
|
+
add_error(
|
88
|
+
message,
|
89
|
+
service_class_name: @context.class.name,
|
90
|
+
input: @input,
|
91
|
+
value: @input.value,
|
83
92
|
code: code,
|
84
|
-
exception_message:
|
93
|
+
exception_message: exception_message
|
85
94
|
)
|
86
95
|
end
|
87
96
|
end
|
@@ -6,7 +6,7 @@ module Servactory
|
|
6
6
|
class Required < Base
|
7
7
|
DEFAULT_MESSAGE = lambda do |service_class_name:, input:, value:|
|
8
8
|
i18n_key = "servactory.inputs.checks.required.default_error."
|
9
|
-
i18n_key += input.
|
9
|
+
i18n_key += input.collection_mode? && value.present? ? "for_collection" : "default"
|
10
10
|
|
11
11
|
I18n.t(
|
12
12
|
i18n_key,
|
@@ -17,10 +17,10 @@ module Servactory
|
|
17
17
|
|
18
18
|
private_constant :DEFAULT_MESSAGE
|
19
19
|
|
20
|
-
def self.check(context:, input:,
|
20
|
+
def self.check(context:, input:, check_key:, **)
|
21
21
|
return unless should_be_checked_for?(input, check_key)
|
22
22
|
|
23
|
-
new(context: context, input: input
|
23
|
+
new(context: context, input: input).check
|
24
24
|
end
|
25
25
|
|
26
26
|
def self.should_be_checked_for?(input, check_key)
|
@@ -29,28 +29,33 @@ module Servactory
|
|
29
29
|
|
30
30
|
##########################################################################
|
31
31
|
|
32
|
-
def initialize(context:, input
|
32
|
+
def initialize(context:, input:)
|
33
33
|
super()
|
34
34
|
|
35
35
|
@context = context
|
36
36
|
@input = input
|
37
|
-
@value = value
|
38
37
|
end
|
39
38
|
|
40
|
-
def check
|
41
|
-
if @input.
|
42
|
-
return if @value.respond_to?(:all?) && @value.all?(&:present?)
|
43
|
-
elsif Servactory::Utils.value_present?(@value)
|
39
|
+
def check
|
40
|
+
if @input.collection_mode? && Servactory::Utils.value_present?(@input.value)
|
41
|
+
return if @input.value.respond_to?(:all?) && @input.value.all?(&:present?)
|
42
|
+
elsif Servactory::Utils.value_present?(@input.value)
|
44
43
|
return
|
45
44
|
end
|
46
45
|
|
47
46
|
_, message = @input.required.values_at(:is, :message)
|
48
47
|
|
48
|
+
add_error_with(message)
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def add_error_with(message)
|
49
54
|
add_error(
|
50
55
|
message.presence || DEFAULT_MESSAGE,
|
51
56
|
service_class_name: @context.class.name,
|
52
57
|
input: @input,
|
53
|
-
value: @value
|
58
|
+
value: @input.value
|
54
59
|
)
|
55
60
|
end
|
56
61
|
end
|
@@ -3,24 +3,33 @@
|
|
3
3
|
module Servactory
|
4
4
|
module Inputs
|
5
5
|
module Validations
|
6
|
-
class Type < Base
|
7
|
-
DEFAULT_MESSAGE = lambda do |service_class_name:, input:, expected_type:, given_type:|
|
8
|
-
if input.
|
9
|
-
|
10
|
-
|
11
|
-
if
|
12
|
-
|
13
|
-
elsif
|
14
|
-
|
6
|
+
class Type < Base # rubocop:disable Metrics/ClassLength
|
7
|
+
DEFAULT_MESSAGE = lambda do |service_class_name:, input:, key_name:, expected_type:, given_type:| # rubocop:disable Metrics/BlockLength
|
8
|
+
if input.collection_mode?
|
9
|
+
collection_message = input.consists_of.fetch(:message)
|
10
|
+
|
11
|
+
if collection_message.is_a?(Proc)
|
12
|
+
collection_message.call(input: input, expected_type: expected_type)
|
13
|
+
elsif collection_message.is_a?(String) && collection_message.present?
|
14
|
+
collection_message
|
15
15
|
else
|
16
16
|
I18n.t(
|
17
|
-
"servactory.inputs.checks.type.default_error.
|
17
|
+
"servactory.inputs.checks.type.default_error.for_collection",
|
18
18
|
service_class_name: service_class_name,
|
19
19
|
input_name: input.name,
|
20
20
|
expected_type: expected_type,
|
21
21
|
given_type: given_type
|
22
22
|
)
|
23
23
|
end
|
24
|
+
elsif input.hash_mode? && key_name.present?
|
25
|
+
I18n.t(
|
26
|
+
"servactory.inputs.checks.type.default_error.for_hash.wrong_element_type",
|
27
|
+
service_class_name: service_class_name,
|
28
|
+
input_name: input.name,
|
29
|
+
key_name: key_name,
|
30
|
+
expected_type: expected_type,
|
31
|
+
given_type: given_type
|
32
|
+
)
|
24
33
|
else
|
25
34
|
I18n.t(
|
26
35
|
"servactory.inputs.checks.type.default_error.default",
|
@@ -34,67 +43,109 @@ module Servactory
|
|
34
43
|
|
35
44
|
private_constant :DEFAULT_MESSAGE
|
36
45
|
|
37
|
-
def self.check(context:, input:,
|
38
|
-
return unless should_be_checked_for?(input,
|
46
|
+
def self.check(context:, input:, check_key:, check_options:)
|
47
|
+
return unless should_be_checked_for?(input, check_key)
|
39
48
|
|
40
|
-
new(context: context, input: input,
|
49
|
+
new(context: context, input: input, types: check_options).check
|
41
50
|
end
|
42
51
|
|
43
|
-
def self.should_be_checked_for?(input,
|
52
|
+
def self.should_be_checked_for?(input, check_key)
|
44
53
|
check_key == :types && (
|
45
54
|
input.required? || (
|
46
55
|
input.optional? && !input.default.nil?
|
47
56
|
) || (
|
48
|
-
input.optional? && !value.nil?
|
57
|
+
input.optional? && !input.value.nil?
|
49
58
|
)
|
50
59
|
)
|
51
60
|
end
|
52
61
|
|
53
62
|
##########################################################################
|
54
63
|
|
55
|
-
def initialize(context:, input:,
|
64
|
+
def initialize(context:, input:, types:)
|
56
65
|
super()
|
57
66
|
|
58
67
|
@context = context
|
59
68
|
@input = input
|
60
|
-
@value = value
|
61
69
|
@types = types
|
62
70
|
end
|
63
71
|
|
64
|
-
def check # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
72
|
+
def check # rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
73
|
+
object_schema_validator = nil
|
74
|
+
|
65
75
|
return if prepared_types.any? do |type|
|
66
|
-
if @input.
|
67
|
-
prepared_value.is_a?(
|
76
|
+
if @input.collection_mode?
|
77
|
+
prepared_value.is_a?(@types.fetch(0, Array)) &&
|
68
78
|
prepared_value.respond_to?(:all?) && prepared_value.all?(type)
|
79
|
+
elsif @input.hash_mode?
|
80
|
+
object_schema_validator = Servactory::Maintenance::Validations::ObjectSchema.validate(
|
81
|
+
object: prepared_value,
|
82
|
+
schema: @input.schema
|
83
|
+
)
|
84
|
+
|
85
|
+
object_schema_validator.valid?
|
69
86
|
else
|
70
87
|
prepared_value.is_a?(type)
|
71
88
|
end
|
72
89
|
end
|
73
90
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
given_type: prepared_value.class.name
|
80
|
-
)
|
91
|
+
if (first_error = object_schema_validator&.errors&.first).present?
|
92
|
+
return add_default_object_error_with(first_error)
|
93
|
+
end
|
94
|
+
|
95
|
+
add_default_error
|
81
96
|
end
|
82
97
|
|
83
98
|
########################################################################
|
84
99
|
|
85
100
|
def prepared_types
|
86
101
|
@prepared_types ||=
|
87
|
-
@
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
102
|
+
if @input.collection_mode?
|
103
|
+
prepared_types_from(Array(@input.consists_of.fetch(:type, [])))
|
104
|
+
else
|
105
|
+
prepared_types_from(@types)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def prepared_types_from(types)
|
110
|
+
types.map do |type|
|
111
|
+
if type.is_a?(String)
|
112
|
+
Object.const_get(type)
|
113
|
+
else
|
114
|
+
type
|
93
115
|
end
|
116
|
+
end
|
94
117
|
end
|
95
118
|
|
96
119
|
def prepared_value
|
97
|
-
@prepared_value ||= @input.optional? && !@input.default.nil? && @value.blank?
|
120
|
+
@prepared_value ||= if @input.optional? && !@input.default.nil? && @input.value.blank?
|
121
|
+
@input.default
|
122
|
+
else
|
123
|
+
@input.value
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
private
|
128
|
+
|
129
|
+
def add_default_object_error_with(error)
|
130
|
+
add_error(
|
131
|
+
DEFAULT_MESSAGE,
|
132
|
+
service_class_name: @context.class.name,
|
133
|
+
input: @input,
|
134
|
+
key_name: error.fetch(:name),
|
135
|
+
expected_type: error.fetch(:expected_type),
|
136
|
+
given_type: error.fetch(:given_type)
|
137
|
+
)
|
138
|
+
end
|
139
|
+
|
140
|
+
def add_default_error
|
141
|
+
add_error(
|
142
|
+
DEFAULT_MESSAGE,
|
143
|
+
service_class_name: @context.class.name,
|
144
|
+
input: @input,
|
145
|
+
key_name: nil,
|
146
|
+
expected_type: prepared_types.join(", "),
|
147
|
+
given_type: prepared_value.class.name
|
148
|
+
)
|
98
149
|
end
|
99
150
|
end
|
100
151
|
end
|
@@ -3,12 +3,15 @@
|
|
3
3
|
module Servactory
|
4
4
|
module Inputs
|
5
5
|
module Workspace
|
6
|
+
private
|
7
|
+
|
6
8
|
def call!(incoming_arguments:, collection_of_inputs:, **)
|
7
9
|
super
|
8
10
|
|
9
|
-
Tools::
|
10
|
-
Tools::
|
11
|
-
|
11
|
+
Tools::Unnecessary.find!(self, incoming_arguments, collection_of_inputs)
|
12
|
+
Tools::Distributor.assign!(incoming_arguments, collection_of_inputs)
|
13
|
+
Tools::Rules.check!(self, collection_of_inputs)
|
14
|
+
Tools::Validation.validate!(self, collection_of_inputs)
|
12
15
|
end
|
13
16
|
end
|
14
17
|
end
|
@@ -17,7 +17,12 @@ module Servactory
|
|
17
17
|
private
|
18
18
|
|
19
19
|
def internal(name, **options)
|
20
|
-
collection_of_internals << Internal.new(
|
20
|
+
collection_of_internals << Internal.new(
|
21
|
+
name,
|
22
|
+
collection_mode_class_names: config.collection_mode_class_names,
|
23
|
+
hash_mode_class_names: config.hash_mode_class_names,
|
24
|
+
**options
|
25
|
+
)
|
21
26
|
end
|
22
27
|
|
23
28
|
def collection_of_internals
|
@@ -4,29 +4,97 @@ module Servactory
|
|
4
4
|
module Internals
|
5
5
|
class Internal
|
6
6
|
attr_reader :name,
|
7
|
-
:
|
8
|
-
:
|
7
|
+
:collection_mode_class_names,
|
8
|
+
:hash_mode_class_names
|
9
9
|
|
10
|
-
def initialize(
|
10
|
+
def initialize(
|
11
|
+
name,
|
12
|
+
type:,
|
13
|
+
collection_mode_class_names:,
|
14
|
+
hash_mode_class_names:,
|
15
|
+
**options
|
16
|
+
)
|
11
17
|
@name = name
|
12
|
-
@
|
18
|
+
@collection_mode_class_names = collection_mode_class_names
|
19
|
+
@hash_mode_class_names = hash_mode_class_names
|
13
20
|
|
14
|
-
|
21
|
+
add_basic_options_with(type: type, options: options)
|
15
22
|
end
|
16
23
|
|
17
|
-
def
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
24
|
+
def method_missing(name, *args, &block)
|
25
|
+
option = collection_of_options.find_by(name: name)
|
26
|
+
|
27
|
+
return super if option.nil?
|
28
|
+
|
29
|
+
option.body
|
30
|
+
end
|
31
|
+
|
32
|
+
def respond_to_missing?(name, *)
|
33
|
+
collection_of_options.names.include?(name) || super
|
34
|
+
end
|
35
|
+
|
36
|
+
def add_basic_options_with(type:, options:)
|
37
|
+
# Check Class: Servactory::Internals::Validations::Type
|
38
|
+
add_types_option_with(type)
|
39
|
+
add_collection_option_with(type, options)
|
40
|
+
add_object_option_with(type, options)
|
22
41
|
end
|
23
42
|
|
24
|
-
def
|
25
|
-
|
43
|
+
def add_types_option_with(type)
|
44
|
+
collection_of_options << Servactory::Maintenance::Attributes::Option.new(
|
45
|
+
name: :types,
|
46
|
+
attribute: self,
|
47
|
+
validation_class: Servactory::Internals::Validations::Type,
|
48
|
+
original_value: Array(type),
|
49
|
+
need_for_checks: true,
|
50
|
+
body_fallback: nil,
|
51
|
+
with_advanced_mode: false
|
52
|
+
)
|
26
53
|
end
|
27
54
|
|
28
|
-
def
|
29
|
-
|
55
|
+
def add_collection_option_with(type, options) # rubocop:disable Metrics/MethodLength
|
56
|
+
collection_of_options << Servactory::Maintenance::Attributes::Option.new(
|
57
|
+
name: :consists_of,
|
58
|
+
attribute: self,
|
59
|
+
validation_class: Servactory::Internals::Validations::Type,
|
60
|
+
define_methods: [
|
61
|
+
Servactory::Maintenance::Attributes::DefineMethod.new(
|
62
|
+
name: :collection_mode?,
|
63
|
+
content: ->(**) { collection_mode_class_names.include?(type) }
|
64
|
+
)
|
65
|
+
],
|
66
|
+
need_for_checks: false,
|
67
|
+
body_key: :type,
|
68
|
+
body_value: String,
|
69
|
+
body_fallback: String,
|
70
|
+
**options
|
71
|
+
)
|
72
|
+
end
|
73
|
+
|
74
|
+
def add_object_option_with(type, options) # rubocop:disable Metrics/MethodLength
|
75
|
+
collection_of_options << Servactory::Maintenance::Attributes::Option.new(
|
76
|
+
name: :schema,
|
77
|
+
attribute: self,
|
78
|
+
validation_class: Servactory::Inputs::Validations::Type,
|
79
|
+
define_methods: [
|
80
|
+
Servactory::Maintenance::Attributes::DefineMethod.new(
|
81
|
+
name: :hash_mode?,
|
82
|
+
content: ->(**) { hash_mode_class_names.include?(type) }
|
83
|
+
)
|
84
|
+
],
|
85
|
+
need_for_checks: false,
|
86
|
+
body_fallback: {},
|
87
|
+
with_advanced_mode: false,
|
88
|
+
**options
|
89
|
+
)
|
90
|
+
end
|
91
|
+
|
92
|
+
def collection_of_options
|
93
|
+
@collection_of_options ||= Servactory::Maintenance::Attributes::OptionsCollection.new
|
94
|
+
end
|
95
|
+
|
96
|
+
def options_for_checks
|
97
|
+
collection_of_options.options_for_checks
|
30
98
|
end
|
31
99
|
end
|
32
100
|
end
|