servactory 1.9.7 → 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 +15 -11
- 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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7138f6d9bc8c21740306eabe282daf762cefd3e0504c1a40761f7db5c2e904ab
|
4
|
+
data.tar.gz: '09dbc3c8168b68e0db456ba7f0e71242412d05c19fb78d45b25f2161b7b06202'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91f6501df9724f4f116dc03ee57863c7e732f77f8c97b9eae7e9ecf64e85fdb7e5f5c976dcf4c92337711566ea122283013ddc4e3d34b60dd970dc380cc3dd0f
|
7
|
+
data.tar.gz: bf86943b60422743c0b829cce81fc3f753315a5c129edb228a54a42170f352816c8a306cefd53a2c5199dedfd4801a3df10f7d34043d12f924f22db290fd9450
|
data/config/locales/en.yml
CHANGED
@@ -13,11 +13,13 @@ en:
|
|
13
13
|
required:
|
14
14
|
default_error:
|
15
15
|
default: "[%{service_class_name}] Required input `%{input_name}` is missing"
|
16
|
-
|
16
|
+
for_collection: "[%{service_class_name}] Required element in input collection `%{input_name}` is missing"
|
17
17
|
type:
|
18
18
|
default_error:
|
19
19
|
default: "[%{service_class_name}] Wrong type of input `%{input_name}`, expected `%{expected_type}`, got `%{given_type}`"
|
20
|
-
|
20
|
+
for_collection: "[%{service_class_name}] Wrong type in input collection `%{input_name}`, expected `%{expected_type}`"
|
21
|
+
for_hash:
|
22
|
+
wrong_element_type: "[%{service_class_name}] Wrong type in input hash `%{input_name}`, expected `%{expected_type}` for `%{key_name}`, got `%{given_type}`"
|
21
23
|
tools:
|
22
24
|
find_unnecessary:
|
23
25
|
error: "[%{service_class_name}] Unexpected attributes: `%{unnecessary_attributes}`"
|
@@ -29,14 +31,26 @@ en:
|
|
29
31
|
setter: "[%{service_class_name}] Undefined internal attribute `%{internal_name}`"
|
30
32
|
checks:
|
31
33
|
type:
|
32
|
-
default_error:
|
34
|
+
default_error:
|
35
|
+
default: "[%{service_class_name}] Wrong type of internal attribute `%{internal_name}`, expected `%{expected_type}`, got `%{given_type}`"
|
36
|
+
for_collection:
|
37
|
+
wrong_type: "[%{service_class_name}] Wrong internal attribute collection type `%{internal_name}`, expected `%{expected_type}`, got `%{given_type}`"
|
38
|
+
wrong_element_type: "[%{service_class_name}] Wrong element type in internal attribute collection `%{internal_name}`, expected `%{expected_type}`"
|
39
|
+
for_hash:
|
40
|
+
wrong_element_type: "[%{service_class_name}] Wrong type in internal attribute hash `%{internal_name}`, expected `%{expected_type}` for `%{key_name}`, got `%{given_type}`"
|
33
41
|
outputs:
|
34
42
|
undefined:
|
35
43
|
getter: "[%{service_class_name}] Undefined output attribute `%{output_name}`"
|
36
44
|
setter: "[%{service_class_name}] Undefined output attribute `%{output_name}`"
|
37
45
|
checks:
|
38
46
|
type:
|
39
|
-
default_error:
|
47
|
+
default_error:
|
48
|
+
default: "[%{service_class_name}] Wrong type of output attribute `%{output_name}`, expected `%{expected_type}`, got `%{given_type}`"
|
49
|
+
for_collection:
|
50
|
+
wrong_type: "[%{service_class_name}] Wrong output attribute collection type `%{output_name}`, expected `%{expected_type}`, got `%{given_type}`"
|
51
|
+
wrong_element_type: "[%{service_class_name}] Wrong element type in output attribute collection `%{output_name}`, expected `%{expected_type}`"
|
52
|
+
for_hash:
|
53
|
+
wrong_element_type: "[%{service_class_name}] Wrong type in output attribute hash `%{output_name}`, expected `%{expected_type}` for `%{key_name}`, got `%{given_type}`"
|
40
54
|
methods:
|
41
55
|
call:
|
42
56
|
not_used: Nothing to perform. Use `make` or create a `call` method.
|
data/config/locales/ru.yml
CHANGED
@@ -6,18 +6,21 @@ ru:
|
|
6
6
|
setter: "[%{service_class_name}] Неизвестный входящий атрибут `%{input_name}`"
|
7
7
|
checks:
|
8
8
|
inclusion:
|
9
|
-
default_error: "[%{service_class_name}]
|
9
|
+
default_error: "[%{service_class_name}] Неправильное значение в `%{input_name}`, должно быть одним из `%{input_inclusion}`"
|
10
10
|
must:
|
11
11
|
default_error: "[%{service_class_name}] Инпут `%{input_name}` должен \"%{code}\""
|
12
12
|
syntax_error: "[%{service_class_name}] Синтаксическая ошибка внутри `%{code}` инпута `%{input_name}`"
|
13
13
|
required:
|
14
14
|
default_error:
|
15
15
|
default: "[%{service_class_name}] Обязательный инпут `%{input_name}` отсутствует"
|
16
|
-
|
16
|
+
for_collection: "[%{service_class_name}] Обязательный элемент в коллекции инпута `%{input_name}` отсутствует"
|
17
17
|
type:
|
18
18
|
default_error:
|
19
|
-
default: "[%{service_class_name}]
|
20
|
-
|
19
|
+
default: "[%{service_class_name}] Неправильный тип инпута `%{input_name}`, ожидалось `%{expected_type}`, получено `%{given_type}`"
|
20
|
+
for_collection: "[%{service_class_name}] Неправильный тип в коллекции инпута `%{input_name}`, ожидалось `%{expected_type}`"
|
21
|
+
for_hash:
|
22
|
+
wrong_element_type: "[%{service_class_name}] Неправильный тип в хеше инпута `%{input_name}`, для `%{key_name}` ожидалось `%{expected_type}`, получено `%{given_type}`"
|
23
|
+
|
21
24
|
tools:
|
22
25
|
find_unnecessary:
|
23
26
|
error: "[%{service_class_name}] Неожиданные атрибуты: `%{unnecessary_attributes}`"
|
@@ -29,14 +32,25 @@ ru:
|
|
29
32
|
setter: "[%{service_class_name}] Неизвестный внутренний атрибут `%{internal_name}`"
|
30
33
|
checks:
|
31
34
|
type:
|
32
|
-
default_error:
|
35
|
+
default_error:
|
36
|
+
default: "[%{service_class_name}] Неправильный тип внутреннего атрибута `%{internal_name}`, ожидалось `%{expected_type}`, получено `%{given_type}`"
|
37
|
+
for_collection:
|
38
|
+
wrong_type: "[%{service_class_name}] Неправильный тип коллекции внутреннего атрибута `%{internal_name}`, ожидалось `%{expected_type}`, получено `%{given_type}`"
|
39
|
+
wrong_element_type: "[%{service_class_name}] Неправильный тип элемента в коллекции внутреннего атрибута `%{internal_name}`, ожидалось `%{expected_type}`"
|
40
|
+
for_hash:
|
41
|
+
wrong_element_type: "[%{service_class_name}] Неправильный тип в хеше внутреннего атрибута `%{internal_name}`, для `%{key_name}` ожидалось `%{expected_type}`, получено `%{given_type}`"
|
33
42
|
outputs:
|
34
43
|
undefined:
|
35
44
|
getter: "[%{service_class_name}] Неизвестный выходящий атрибут `%{output_name}`"
|
36
45
|
setter: "[%{service_class_name}] Неизвестный выходящий атрибут `%{output_name}`"
|
37
46
|
checks:
|
38
47
|
type:
|
39
|
-
|
48
|
+
default: "[%{service_class_name}] Неправильный тип выходящего атрибута `%{output_name}`, ожидалось `%{expected_type}`, получено `%{given_type}`"
|
49
|
+
for_collection:
|
50
|
+
wrong_type: "[%{service_class_name}] Неправильный тип коллекции выходящего атрибута `%{output_name}`, ожидалось `%{expected_type}`, получено `%{given_type}`"
|
51
|
+
wrong_element_type: "[%{service_class_name}] Неправильный тип элемента в коллекции выходящего атрибута `%{output_name}`, ожидалось `%{expected_type}`"
|
52
|
+
for_hash:
|
53
|
+
wrong_element_type: "[%{service_class_name}] Неправильный тип в хеше выходящего атрибута `%{output_name}`, для `%{key_name}` ожидалось `%{expected_type}`, получено `%{given_type}`"
|
40
54
|
methods:
|
41
55
|
call:
|
42
56
|
not_used: Нечего исполнять. Используйте `make` или создайте метод `call`.
|
@@ -17,6 +17,8 @@ module Servactory
|
|
17
17
|
|
18
18
|
child.config.failure_class = config.failure_class
|
19
19
|
|
20
|
+
child.config.collection_mode_class_names = config.collection_mode_class_names
|
21
|
+
|
20
22
|
child.config.input_option_helpers = config.input_option_helpers
|
21
23
|
|
22
24
|
child.config.aliases_for_make = config.aliases_for_make
|
@@ -23,6 +23,14 @@ module Servactory
|
|
23
23
|
@config.failure_class = failure_class
|
24
24
|
end
|
25
25
|
|
26
|
+
def collection_mode_class_names(collection_mode_class_names)
|
27
|
+
@config.collection_mode_class_names.merge(collection_mode_class_names)
|
28
|
+
end
|
29
|
+
|
30
|
+
def hash_mode_class_names(hash_mode_class_names)
|
31
|
+
@config.collection_mode_class_names.merge(hash_mode_class_names)
|
32
|
+
end
|
33
|
+
|
26
34
|
def input_option_helpers(input_option_helpers)
|
27
35
|
@config.input_option_helpers.merge(input_option_helpers)
|
28
36
|
end
|
@@ -7,18 +7,27 @@ module Servactory
|
|
7
7
|
:internal_error_class,
|
8
8
|
:output_error_class,
|
9
9
|
:failure_class,
|
10
|
+
:collection_mode_class_names,
|
11
|
+
:hash_mode_class_names,
|
10
12
|
:input_option_helpers,
|
11
13
|
:aliases_for_make,
|
12
14
|
:shortcuts_for_make
|
13
15
|
|
14
|
-
def initialize
|
16
|
+
def initialize # rubocop:disable Metrics/MethodLength
|
15
17
|
@input_error_class = Servactory::Errors::InputError
|
16
18
|
@internal_error_class = Servactory::Errors::InternalError
|
17
19
|
@output_error_class = Servactory::Errors::OutputError
|
18
20
|
|
19
21
|
@failure_class = Servactory::Errors::Failure
|
20
22
|
|
21
|
-
@
|
23
|
+
@collection_mode_class_names =
|
24
|
+
Servactory::Maintenance::CollectionMode::ClassNamesCollection.new(default_collection_mode_class_names)
|
25
|
+
|
26
|
+
@hash_mode_class_names =
|
27
|
+
Servactory::Maintenance::HashMode::ClassNamesCollection.new(default_hash_mode_class_names)
|
28
|
+
|
29
|
+
@input_option_helpers =
|
30
|
+
Servactory::Maintenance::Attributes::OptionHelpersCollection.new(default_input_option_helpers)
|
22
31
|
|
23
32
|
@aliases_for_make = Servactory::Methods::AliasesForMake::Collection.new
|
24
33
|
@shortcuts_for_make = Servactory::Methods::ShortcutsForMake::Collection.new
|
@@ -26,10 +35,17 @@ module Servactory
|
|
26
35
|
|
27
36
|
private
|
28
37
|
|
38
|
+
def default_collection_mode_class_names
|
39
|
+
Set[Array, Set]
|
40
|
+
end
|
41
|
+
|
42
|
+
def default_hash_mode_class_names
|
43
|
+
Set[Hash]
|
44
|
+
end
|
45
|
+
|
29
46
|
def default_input_option_helpers
|
30
47
|
Set[
|
31
|
-
Servactory::
|
32
|
-
Servactory::Inputs::OptionHelper.new(name: :as_array, equivalent: { array: true })
|
48
|
+
Servactory::Maintenance::Attributes::OptionHelper.new(name: :optional, equivalent: { required: false }),
|
33
49
|
]
|
34
50
|
end
|
35
51
|
end
|
@@ -4,9 +4,11 @@ module Servactory
|
|
4
4
|
module Context
|
5
5
|
module Workspace
|
6
6
|
class Inputs
|
7
|
-
|
7
|
+
RESERVED_ATTRIBUTES = %i[type required default].freeze
|
8
|
+
private_constant :RESERVED_ATTRIBUTES
|
9
|
+
|
10
|
+
def initialize(context:, collection_of_inputs:)
|
8
11
|
@context = context
|
9
|
-
@incoming_arguments = incoming_arguments
|
10
12
|
@collection_of_inputs = collection_of_inputs
|
11
13
|
end
|
12
14
|
|
@@ -44,19 +46,51 @@ module Servactory
|
|
44
46
|
|
45
47
|
return yield if input.nil?
|
46
48
|
|
47
|
-
|
48
|
-
|
49
|
+
input.value = input.default if input.optional? && input.value.blank?
|
50
|
+
|
51
|
+
input.value = prepare_object_values_inside(object: input.value, schema: input.schema) if input.hash_mode?
|
49
52
|
|
50
53
|
input_prepare = input.prepare.fetch(:in, nil)
|
51
|
-
|
54
|
+
input.value = input_prepare.call(value: input.value) if input_prepare.present?
|
52
55
|
|
53
56
|
if name.to_s.end_with?("?")
|
54
|
-
Servactory::Utils.query_attribute(
|
57
|
+
Servactory::Utils.query_attribute(input.value)
|
55
58
|
else
|
56
|
-
|
59
|
+
input.value
|
57
60
|
end
|
58
61
|
end
|
59
62
|
|
63
|
+
def prepare_object_values_inside(object:, schema:) # rubocop:disable Metrics/MethodLength
|
64
|
+
return object unless object.respond_to?(:fetch)
|
65
|
+
|
66
|
+
schema.to_h do |schema_key, schema_value|
|
67
|
+
attribute_type = schema_value.fetch(:type, String)
|
68
|
+
|
69
|
+
result =
|
70
|
+
if attribute_type == Hash
|
71
|
+
prepare_object_values_inside(
|
72
|
+
object: object.fetch(schema_key, {}),
|
73
|
+
schema: schema_value.except(*RESERVED_ATTRIBUTES)
|
74
|
+
)
|
75
|
+
else
|
76
|
+
fetch_object_values_from(
|
77
|
+
value: object.fetch(schema_key, {}),
|
78
|
+
schema_value: schema_value,
|
79
|
+
attribute_required: schema_value.fetch(:required, true)
|
80
|
+
)
|
81
|
+
end
|
82
|
+
|
83
|
+
[schema_key, result]
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def fetch_object_values_from(value:, schema_value:, attribute_required:)
|
88
|
+
return value if attribute_required
|
89
|
+
return value if value.present?
|
90
|
+
|
91
|
+
schema_value.fetch(:default, nil)
|
92
|
+
end
|
93
|
+
|
60
94
|
def raise_error_for(type, name)
|
61
95
|
message_text = I18n.t(
|
62
96
|
"servactory.inputs.undefined.#{type}",
|
@@ -40,7 +40,7 @@ module Servactory
|
|
40
40
|
def setter_with(prepared_name:, value:, &block) # rubocop:disable Lint/UnusedMethodArgument
|
41
41
|
return yield unless @collection_of_outputs.names.include?(prepared_name)
|
42
42
|
|
43
|
-
output = @collection_of_outputs.find_by(name: prepared_name)
|
43
|
+
output = @collection_of_outputs.find_by(name: prepared_name)
|
44
44
|
|
45
45
|
return yield if output.nil?
|
46
46
|
|
data/lib/servactory/dsl.rb
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
module Servactory
|
4
4
|
module DSL
|
5
|
+
@extensions = []
|
6
|
+
|
5
7
|
def self.included(base)
|
6
8
|
base.include(Configuration::DSL)
|
7
9
|
base.include(Info::DSL)
|
@@ -9,7 +11,22 @@ module Servactory
|
|
9
11
|
base.include(Inputs::DSL)
|
10
12
|
base.include(Internals::DSL)
|
11
13
|
base.include(Outputs::DSL)
|
14
|
+
|
15
|
+
extensions.each { |extension| base.include(extension) }
|
16
|
+
|
12
17
|
base.include(Methods::DSL)
|
13
18
|
end
|
19
|
+
|
20
|
+
def self.with_extensions(*extensions)
|
21
|
+
@extensions = extensions
|
22
|
+
|
23
|
+
self
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.extensions
|
27
|
+
@extensions
|
28
|
+
end
|
29
|
+
|
30
|
+
private_class_method :extensions
|
14
31
|
end
|
15
32
|
end
|
@@ -4,7 +4,7 @@ module Servactory
|
|
4
4
|
module Inputs
|
5
5
|
class Collection
|
6
6
|
extend Forwardable
|
7
|
-
def_delegators :@collection, :<<, :filter, :each, :map, :to_h, :merge, :find
|
7
|
+
def_delegators :@collection, :<<, :filter, :each, :map, :flat_map, :to_h, :merge, :find
|
8
8
|
|
9
9
|
def initialize(collection = Set.new)
|
10
10
|
@collection = collection
|
@@ -21,6 +21,8 @@ module Servactory
|
|
21
21
|
collection_of_inputs << Input.new(
|
22
22
|
name,
|
23
23
|
*helpers,
|
24
|
+
collection_mode_class_names: config.collection_mode_class_names,
|
25
|
+
hash_mode_class_names: config.hash_mode_class_names,
|
24
26
|
option_helpers: config.input_option_helpers,
|
25
27
|
**options
|
26
28
|
)
|
@@ -3,12 +3,12 @@
|
|
3
3
|
module Servactory
|
4
4
|
module Inputs
|
5
5
|
class Input # rubocop:disable Metrics/ClassLength
|
6
|
-
|
7
|
-
|
8
|
-
private_constant :ARRAY_DEFAULT_VALUE
|
6
|
+
attr_accessor :value
|
9
7
|
|
10
8
|
attr_reader :name,
|
11
9
|
:internal_name,
|
10
|
+
:collection_mode_class_names,
|
11
|
+
:hash_mode_class_names,
|
12
12
|
:option_helpers
|
13
13
|
|
14
14
|
# rubocop:disable Style/KeywordParametersOrder
|
@@ -17,11 +17,15 @@ module Servactory
|
|
17
17
|
*helpers,
|
18
18
|
as: nil,
|
19
19
|
type:,
|
20
|
+
collection_mode_class_names:,
|
21
|
+
hash_mode_class_names:,
|
20
22
|
option_helpers:,
|
21
23
|
**options
|
22
24
|
)
|
23
25
|
@name = name
|
24
26
|
@internal_name = as.present? ? as : name
|
27
|
+
@collection_mode_class_names = collection_mode_class_names
|
28
|
+
@hash_mode_class_names = hash_mode_class_names
|
25
29
|
@option_helpers = option_helpers
|
26
30
|
|
27
31
|
options = apply_helpers_for_options(helpers: helpers, options: options) if helpers.present?
|
@@ -35,7 +39,7 @@ module Servactory
|
|
35
39
|
|
36
40
|
return super if option.nil?
|
37
41
|
|
38
|
-
option.
|
42
|
+
option.body
|
39
43
|
end
|
40
44
|
|
41
45
|
def respond_to_missing?(name, *)
|
@@ -63,7 +67,8 @@ module Servactory
|
|
63
67
|
# Check Class: Servactory::Inputs::Validations::Type
|
64
68
|
add_types_option_with(type)
|
65
69
|
add_default_option_with(options)
|
66
|
-
|
70
|
+
add_collection_option_with(type, options)
|
71
|
+
add_object_option_with(type, options)
|
67
72
|
|
68
73
|
# Check Class: Servactory::Inputs::Validations::Inclusion
|
69
74
|
add_inclusion_option_with(options)
|
@@ -73,166 +78,180 @@ module Servactory
|
|
73
78
|
|
74
79
|
# Check Class: nil
|
75
80
|
add_prepare_option_with(options)
|
76
|
-
add_internal_option_with(options)
|
77
81
|
end
|
78
82
|
|
79
83
|
def add_required_option_with(options) # rubocop:disable Metrics/MethodLength
|
80
|
-
collection_of_options << Option.new(
|
84
|
+
collection_of_options << Servactory::Maintenance::Attributes::Option.new(
|
81
85
|
name: :required,
|
82
|
-
|
86
|
+
attribute: self,
|
83
87
|
validation_class: Servactory::Inputs::Validations::Required,
|
84
|
-
|
85
|
-
|
88
|
+
define_methods: [
|
89
|
+
Servactory::Maintenance::Attributes::DefineMethod.new(
|
86
90
|
name: :required?,
|
87
|
-
content: ->(
|
91
|
+
content: ->(option:) { Servactory::Utils.true?(option[:is]) }
|
88
92
|
),
|
89
|
-
|
93
|
+
Servactory::Maintenance::Attributes::DefineMethod.new(
|
90
94
|
name: :optional?,
|
91
|
-
content: ->(
|
95
|
+
content: ->(option:) { !Servactory::Utils.true?(option[:is]) }
|
92
96
|
)
|
93
97
|
],
|
94
|
-
|
95
|
-
|
98
|
+
define_conflicts: [
|
99
|
+
Servactory::Maintenance::Attributes::DefineConflict.new(
|
100
|
+
content: -> { :required_vs_default if required? && default_value_present? }
|
101
|
+
)
|
96
102
|
],
|
97
103
|
need_for_checks: true,
|
98
|
-
|
99
|
-
|
104
|
+
body_key: :is,
|
105
|
+
body_fallback: true,
|
100
106
|
**options
|
101
107
|
)
|
102
108
|
end
|
103
109
|
|
104
110
|
def add_types_option_with(type)
|
105
|
-
collection_of_options << Option.new(
|
111
|
+
collection_of_options << Servactory::Maintenance::Attributes::Option.new(
|
106
112
|
name: :types,
|
107
|
-
|
113
|
+
attribute: self,
|
108
114
|
validation_class: Servactory::Inputs::Validations::Type,
|
109
115
|
original_value: Array(type),
|
110
116
|
need_for_checks: true,
|
111
|
-
|
117
|
+
body_fallback: nil,
|
112
118
|
with_advanced_mode: false
|
113
119
|
)
|
114
120
|
end
|
115
121
|
|
116
122
|
def add_default_option_with(options) # rubocop:disable Metrics/MethodLength
|
117
|
-
collection_of_options << Option.new(
|
123
|
+
collection_of_options << Servactory::Maintenance::Attributes::Option.new(
|
118
124
|
name: :default,
|
119
|
-
|
125
|
+
attribute: self,
|
120
126
|
validation_class: Servactory::Inputs::Validations::Type,
|
121
|
-
|
122
|
-
|
127
|
+
define_methods: [
|
128
|
+
Servactory::Maintenance::Attributes::DefineMethod.new(
|
123
129
|
name: :default_value_present?,
|
124
|
-
content: ->(
|
130
|
+
content: ->(option:) { !option.nil? }
|
125
131
|
)
|
126
132
|
],
|
127
133
|
need_for_checks: true,
|
128
|
-
|
134
|
+
body_fallback: nil,
|
129
135
|
with_advanced_mode: false,
|
130
136
|
**options
|
131
137
|
)
|
132
138
|
end
|
133
139
|
|
134
|
-
def
|
135
|
-
collection_of_options << Option.new(
|
136
|
-
name: :
|
137
|
-
|
140
|
+
def add_collection_option_with(type, options) # rubocop:disable Metrics/MethodLength
|
141
|
+
collection_of_options << Servactory::Maintenance::Attributes::Option.new(
|
142
|
+
name: :consists_of,
|
143
|
+
attribute: self,
|
138
144
|
validation_class: Servactory::Inputs::Validations::Type,
|
139
|
-
|
140
|
-
|
141
|
-
name: :
|
142
|
-
content: ->(
|
145
|
+
define_methods: [
|
146
|
+
Servactory::Maintenance::Attributes::DefineMethod.new(
|
147
|
+
name: :collection_mode?,
|
148
|
+
content: ->(**) { collection_mode_class_names.include?(type) }
|
143
149
|
)
|
144
150
|
],
|
145
|
-
|
146
|
-
|
147
|
-
|
151
|
+
define_conflicts: [
|
152
|
+
Servactory::Maintenance::Attributes::DefineConflict.new(
|
153
|
+
content: -> { :collection_vs_inclusion if collection_mode? && inclusion_present? }
|
154
|
+
)
|
148
155
|
],
|
149
156
|
need_for_checks: false,
|
150
|
-
|
151
|
-
|
157
|
+
body_key: :type,
|
158
|
+
body_value: String,
|
159
|
+
body_fallback: String,
|
160
|
+
**options
|
161
|
+
)
|
162
|
+
end
|
163
|
+
|
164
|
+
def add_object_option_with(type, options) # rubocop:disable Metrics/MethodLength
|
165
|
+
collection_of_options << Servactory::Maintenance::Attributes::Option.new(
|
166
|
+
name: :schema,
|
167
|
+
attribute: self,
|
168
|
+
validation_class: Servactory::Inputs::Validations::Type,
|
169
|
+
define_methods: [
|
170
|
+
Servactory::Maintenance::Attributes::DefineMethod.new(
|
171
|
+
name: :hash_mode?,
|
172
|
+
content: ->(**) { hash_mode_class_names.include?(type) }
|
173
|
+
)
|
174
|
+
],
|
175
|
+
define_conflicts: [
|
176
|
+
Servactory::Maintenance::Attributes::DefineConflict.new(
|
177
|
+
content: -> { :object_vs_inclusion if hash_mode? && inclusion_present? }
|
178
|
+
)
|
179
|
+
],
|
180
|
+
need_for_checks: false,
|
181
|
+
body_fallback: {},
|
182
|
+
with_advanced_mode: false,
|
152
183
|
**options
|
153
184
|
)
|
154
185
|
end
|
155
186
|
|
156
187
|
def add_inclusion_option_with(options) # rubocop:disable Metrics/MethodLength
|
157
|
-
collection_of_options << Option.new(
|
188
|
+
collection_of_options << Servactory::Maintenance::Attributes::Option.new(
|
158
189
|
name: :inclusion,
|
159
|
-
|
190
|
+
attribute: self,
|
160
191
|
validation_class: Servactory::Inputs::Validations::Inclusion,
|
161
|
-
|
162
|
-
|
192
|
+
define_methods: [
|
193
|
+
Servactory::Maintenance::Attributes::DefineMethod.new(
|
163
194
|
name: :inclusion_present?,
|
164
|
-
content: ->(
|
195
|
+
content: ->(option:) { option[:in].is_a?(Array) && option[:in].present? }
|
165
196
|
)
|
166
197
|
],
|
167
198
|
need_for_checks: true,
|
168
|
-
|
169
|
-
|
199
|
+
body_key: :in,
|
200
|
+
body_fallback: nil,
|
170
201
|
**options
|
171
202
|
)
|
172
203
|
end
|
173
204
|
|
174
205
|
def add_must_option_with(options) # rubocop:disable Metrics/MethodLength
|
175
|
-
collection_of_options << Option.new(
|
206
|
+
collection_of_options << Servactory::Maintenance::Attributes::Option.new(
|
176
207
|
name: :must,
|
177
|
-
|
208
|
+
attribute: self,
|
178
209
|
validation_class: Servactory::Inputs::Validations::Must,
|
179
|
-
|
180
|
-
|
210
|
+
define_methods: [
|
211
|
+
Servactory::Maintenance::Attributes::DefineMethod.new(
|
181
212
|
name: :must_present?,
|
182
|
-
content: ->(
|
213
|
+
content: ->(option:) { option.present? }
|
183
214
|
)
|
184
215
|
],
|
185
216
|
need_for_checks: true,
|
186
|
-
|
187
|
-
|
217
|
+
body_key: :is,
|
218
|
+
body_fallback: nil,
|
188
219
|
with_advanced_mode: false,
|
189
220
|
**options
|
190
221
|
)
|
191
222
|
end
|
192
223
|
|
193
224
|
def add_prepare_option_with(options) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
194
|
-
collection_of_options << Option.new(
|
225
|
+
collection_of_options << Servactory::Maintenance::Attributes::Option.new(
|
195
226
|
name: :prepare,
|
196
|
-
|
227
|
+
attribute: self,
|
197
228
|
validation_class: nil,
|
198
|
-
|
199
|
-
|
229
|
+
define_methods: [
|
230
|
+
Servactory::Maintenance::Attributes::DefineMethod.new(
|
200
231
|
name: :prepare_present?,
|
201
|
-
content: ->(
|
232
|
+
content: ->(option:) { option[:in].present? }
|
202
233
|
)
|
203
234
|
],
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
)
|
214
|
-
end
|
215
|
-
|
216
|
-
def add_internal_option_with(options) # rubocop:disable Metrics/MethodLength
|
217
|
-
collection_of_options << Option.new(
|
218
|
-
name: :internal,
|
219
|
-
input: self,
|
220
|
-
validation_class: nil,
|
221
|
-
define_input_methods: [
|
222
|
-
DefineInputMethod.new(
|
223
|
-
name: :internal?,
|
224
|
-
content: ->(value:) { Servactory::Utils.true?(value[:is]) }
|
235
|
+
define_conflicts: [
|
236
|
+
Servactory::Maintenance::Attributes::DefineConflict.new(
|
237
|
+
content: -> { :prepare_vs_collection if prepare_present? && collection_mode? }
|
238
|
+
),
|
239
|
+
Servactory::Maintenance::Attributes::DefineConflict.new(
|
240
|
+
content: -> { :prepare_vs_inclusion if prepare_present? && inclusion_present? }
|
241
|
+
),
|
242
|
+
Servactory::Maintenance::Attributes::DefineConflict.new(
|
243
|
+
content: -> { :prepare_vs_must if prepare_present? && must_present? }
|
225
244
|
)
|
226
245
|
],
|
227
246
|
need_for_checks: false,
|
228
|
-
|
229
|
-
|
247
|
+
body_key: :in,
|
248
|
+
body_fallback: false,
|
230
249
|
**options
|
231
250
|
)
|
232
251
|
end
|
233
252
|
|
234
253
|
def collection_of_options
|
235
|
-
@collection_of_options ||= OptionsCollection.new
|
254
|
+
@collection_of_options ||= Servactory::Maintenance::Attributes::OptionsCollection.new
|
236
255
|
end
|
237
256
|
|
238
257
|
def options_for_checks
|