servactory 2.11.0 → 2.12.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 +6 -6
- data/config/locales/ru.yml +6 -6
- data/lib/servactory/configuration/option_helpers/option_helpers_collection.rb +5 -1
- data/lib/servactory/configuration/setup.rb +6 -3
- data/lib/servactory/context/warehouse/base.rb +25 -0
- data/lib/servactory/context/warehouse/inputs.rb +56 -0
- data/lib/servactory/context/warehouse/internals.rb +10 -0
- data/lib/servactory/context/warehouse/outputs.rb +12 -0
- data/lib/servactory/context/warehouse/setup.rb +73 -0
- data/lib/servactory/context/workspace/inputs.rb +3 -3
- data/lib/servactory/context/workspace/internals.rb +2 -2
- data/lib/servactory/context/workspace/outputs.rb +2 -2
- data/lib/servactory/context/workspace.rb +2 -2
- 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/input.rb +8 -5
- data/lib/servactory/inputs/tools/unnecessary.rb +1 -1
- data/lib/servactory/inputs/tools/validation.rb +1 -1
- data/lib/servactory/inputs/tools/{store.rb → warehouse.rb} +2 -2
- data/lib/servactory/inputs/workspace.rb +1 -1
- data/lib/servactory/internals/internal.rb +5 -4
- data/lib/servactory/maintenance/attributes/option_helper.rb +8 -2
- data/lib/servactory/maintenance/attributes/options/registrar.rb +1 -34
- data/lib/servactory/outputs/output.rb +5 -4
- data/lib/servactory/result.rb +1 -1
- data/lib/servactory/test_kit/result.rb +3 -3
- data/lib/servactory/test_kit/rspec/matchers/have_service_attribute_matchers/consists_of_matcher.rb +20 -8
- data/lib/servactory/test_kit/rspec/matchers/have_service_attribute_matchers/inclusion_matcher.rb +23 -4
- data/lib/servactory/test_kit/rspec/matchers/have_service_input_matcher.rb +4 -1
- data/lib/servactory/test_kit/rspec/matchers/have_service_input_matchers/valid_with_matcher.rb +5 -4
- data/lib/servactory/test_kit/rspec/matchers/have_service_internal_matcher.rb +4 -1
- data/lib/servactory/tool_kit/dynamic_options/inclusion.rb +63 -0
- data/lib/servactory/tool_kit/dynamic_options/must.rb +5 -1
- data/lib/servactory/version.rb +2 -2
- metadata +12 -8
- data/lib/servactory/context/store.rb +0 -71
- data/lib/servactory/maintenance/attributes/translator/inclusion.rb +0 -26
- data/lib/servactory/maintenance/attributes/validations/inclusion.rb +0 -63
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d25dddc86ece8552d4644707ec8ed928d743287e7b6d8cac5b6651c2f4376b4
|
4
|
+
data.tar.gz: 75954babfecf8c47e89961b6a3795b66264d34c09a9362e6ea30891d2453b156
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d5e14c6eed833a4e2181cbf68d87a69b869a7b98479402a26feb1b1ab2404cb5d74ec3e9cfa6a858a1b059980d3164bcf6c63c4faaddbf57925363a2cd3588b
|
7
|
+
data.tar.gz: cf7f8c2c6fd19d0f743e610a8de747f00fe0e885aa0c62ff392be27522a2d8d7dc88a8cbdd3916099ca4f21f8efcc5132d0ef3f995e37f8c5993bbca9dc207d6
|
data/config/locales/en.yml
CHANGED
@@ -12,8 +12,6 @@ en:
|
|
12
12
|
for_fetch: "[%{service_class_name}] Undefined input attribute `%{input_name}`"
|
13
13
|
for_assign: "[%{service_class_name}] Undefined input attribute `%{input_name}`"
|
14
14
|
validations:
|
15
|
-
inclusion:
|
16
|
-
default_error: "[%{service_class_name}] Wrong value in `%{input_name}`, must be one of `%{input_inclusion}`"
|
17
15
|
must:
|
18
16
|
default_error: "[%{service_class_name}] Input `%{input_name}` must \"%{code}\""
|
19
17
|
syntax_error: "[%{service_class_name}] Syntax error inside `%{code}` of `%{input_name}` input: %{exception_message}"
|
@@ -26,6 +24,8 @@ en:
|
|
26
24
|
default: "[%{service_class_name}] Input `%{input_name}` does not match `%{format_name}` format"
|
27
25
|
wrong_pattern: "[%{service_class_name}] Input `%{input_name}` does not match `%{format_name}` format"
|
28
26
|
unknown: "[%{service_class_name}] Unknown `%{format_name}` format specified for input `%{input_name}`"
|
27
|
+
inclusion:
|
28
|
+
default: "[%{service_class_name}] Wrong value in `%{input_name}`, must be one of `%{input_inclusion}`, got `%{value}`"
|
29
29
|
min:
|
30
30
|
default: "[%{service_class_name}] Input `%{input_name}` received value `%{value}`, which is less than `%{option_value}`"
|
31
31
|
max:
|
@@ -52,8 +52,6 @@ en:
|
|
52
52
|
for_fetch: "[%{service_class_name}] Undefined internal attribute `%{internal_name}`"
|
53
53
|
for_assign: "[%{service_class_name}] Undefined internal attribute `%{internal_name}`"
|
54
54
|
validations:
|
55
|
-
inclusion:
|
56
|
-
default_error: "[%{service_class_name}] Wrong value in `%{internal_name}`, must be one of `%{internal_inclusion}`"
|
57
55
|
must:
|
58
56
|
default_error: "[%{service_class_name}] Internal attribute `%{internal_name}` must \"%{code}\""
|
59
57
|
syntax_error: "[%{service_class_name}] Syntax error inside `%{code}` of `%{internal_name}` internal attribute: %{exception_message}"
|
@@ -66,6 +64,8 @@ en:
|
|
66
64
|
default: "[%{service_class_name}] Internal attribute `%{internal_name}` does not match `%{format_name}` format"
|
67
65
|
wrong_pattern: "[%{service_class_name}] Internal attribute `%{internal_name}` does not match `%{format_name}` format"
|
68
66
|
unknown: "[%{service_class_name}] Unknown `%{format_name}` format specified for internal attribute `%{internal_name}`"
|
67
|
+
inclusion:
|
68
|
+
default: "[%{service_class_name}] Wrong value in `%{internal_name}`, must be one of `%{internal_inclusion}`, got `%{value}`"
|
69
69
|
min:
|
70
70
|
default: "[%{service_class_name}] Internal attribute `%{internal_name}` received value `%{value}`, which is less than `%{option_value}`"
|
71
71
|
max:
|
@@ -84,8 +84,6 @@ en:
|
|
84
84
|
for_fetch: "[%{service_class_name}] Undefined output attribute `%{output_name}`"
|
85
85
|
for_assign: "[%{service_class_name}] Undefined output attribute `%{output_name}`"
|
86
86
|
validations:
|
87
|
-
inclusion:
|
88
|
-
default_error: "[%{service_class_name}] Wrong value in `%{output_name}`, must be one of `%{output_inclusion}`"
|
89
87
|
must:
|
90
88
|
default_error: "[%{service_class_name}] Output attribute `%{output_name}` must \"%{code}\""
|
91
89
|
syntax_error: "[%{service_class_name}] Syntax error inside `%{code}` of `%{output_name}` output attribute: %{exception_message}"
|
@@ -98,6 +96,8 @@ en:
|
|
98
96
|
default: "[%{service_class_name}] Output attribute `%{output_name}` does not match `%{format_name}` format"
|
99
97
|
wrong_pattern: "[%{service_class_name}] Output attribute `%{output_name}` does not match `%{format_name}` format"
|
100
98
|
unknown: "[%{service_class_name}] Unknown `%{format_name}` format specified for output attribute `%{output_name}`"
|
99
|
+
inclusion:
|
100
|
+
default: "[%{service_class_name}] Wrong value in `%{output_name}`, must be one of `%{output_inclusion}`, got `%{value}`"
|
101
101
|
min:
|
102
102
|
default: "[%{service_class_name}] Output attribute `%{output_name}` received value `%{value}`, which is less than `%{option_value}`"
|
103
103
|
max:
|
data/config/locales/ru.yml
CHANGED
@@ -12,8 +12,6 @@ ru:
|
|
12
12
|
for_fetch: "[%{service_class_name}] Неизвестный входящий атрибут `%{input_name}`"
|
13
13
|
for_assign: "[%{service_class_name}] Неизвестный входящий атрибут `%{input_name}`"
|
14
14
|
validations:
|
15
|
-
inclusion:
|
16
|
-
default_error: "[%{service_class_name}] Неправильное значение в `%{input_name}`, должно быть одним из `%{input_inclusion}`"
|
17
15
|
must:
|
18
16
|
default_error: "[%{service_class_name}] Инпут `%{input_name}` должен \"%{code}\""
|
19
17
|
syntax_error: "[%{service_class_name}] Синтаксическая ошибка внутри `%{code}` инпута `%{input_name}`: %{exception_message}"
|
@@ -26,6 +24,8 @@ ru:
|
|
26
24
|
default: "[%{service_class_name}] Инпут `%{input_name}` не соответствует формату `%{format_name}`"
|
27
25
|
wrong_pattern: "[%{service_class_name}] Инпут `%{input_name}` не соответствует формату `%{format_name}`"
|
28
26
|
unknown: "[%{service_class_name}] Указан неизвестный формат `%{format_name}` у инпута `%{input_name}`"
|
27
|
+
inclusion:
|
28
|
+
default: "[%{service_class_name}] Неправильное значение в `%{input_name}`, должно быть одним из `%{input_inclusion}`, получено `%{value}`"
|
29
29
|
min:
|
30
30
|
default: "[%{service_class_name}] Инпут `%{input_name}` получил значение `%{value}`, которое меньше `%{option_value}`"
|
31
31
|
max:
|
@@ -52,8 +52,6 @@ ru:
|
|
52
52
|
for_fetch: "[%{service_class_name}] Неизвестный внутренний атрибут `%{internal_name}`"
|
53
53
|
for_assign: "[%{service_class_name}] Неизвестный внутренний атрибут `%{internal_name}`"
|
54
54
|
validations:
|
55
|
-
inclusion:
|
56
|
-
default_error: "[%{service_class_name}] Неправильное значение в `%{internal_name}`, должно быть одним из `%{internal_inclusion}`"
|
57
55
|
must:
|
58
56
|
default_error: "[%{service_class_name}] Внутренний атрибут `%{internal_name}` должен \"%{code}\""
|
59
57
|
syntax_error: "[%{service_class_name}] Синтаксическая ошибка внутри `%{code}` внутреннего атрибута `%{internal_name}`: %{exception_message}"
|
@@ -66,6 +64,8 @@ ru:
|
|
66
64
|
default: "[%{service_class_name}] Внутренний атрибут `%{internal_name}` не соответствует формату `%{format_name}`"
|
67
65
|
wrong_pattern: "[%{service_class_name}] Внутренний атрибут `%{internal_name}` не соответствует формату `%{format_name}`"
|
68
66
|
unknown: "[%{service_class_name}] Указан неизвестный формат `%{format_name}` у внутреннего атрибута `%{internal_name}`"
|
67
|
+
inclusion:
|
68
|
+
default: "[%{service_class_name}] Неправильное значение в `%{internal_name}`, должно быть одним из `%{internal_inclusion}`, получено `%{value}`"
|
69
69
|
min:
|
70
70
|
default: "[%{service_class_name}] Внутренний атрибут `%{internal_name}` получил значение `%{value}`, которое меньше `%{option_value}`"
|
71
71
|
max:
|
@@ -84,8 +84,6 @@ ru:
|
|
84
84
|
for_fetch: "[%{service_class_name}] Неизвестный выходящий атрибут `%{output_name}`"
|
85
85
|
for_assign: "[%{service_class_name}] Неизвестный выходящий атрибут `%{output_name}`"
|
86
86
|
validations:
|
87
|
-
inclusion:
|
88
|
-
default_error: "[%{service_class_name}] Неправильное значение в `%{output_name}`, должно быть одним из `%{output_inclusion}`"
|
89
87
|
must:
|
90
88
|
default_error: "[%{service_class_name}] Выходящий атрибут `%{output_name}` должен \"%{code}\""
|
91
89
|
syntax_error: "[%{service_class_name}] Синтаксическая ошибка внутри `%{code}` выходящего атрибута `%{output_name}`: %{exception_message}"
|
@@ -98,6 +96,8 @@ ru:
|
|
98
96
|
default: "[%{service_class_name}] Выходящий атрибут `%{output_name}` не соответствует формату `%{format_name}`"
|
99
97
|
wrong_pattern: "[%{service_class_name}] Выходящий атрибут `%{output_name}` не соответствует формату `%{format_name}`"
|
100
98
|
unknown: "[%{service_class_name}] Указан неизвестный формат `%{format_name}` у выходящего атрибута `%{output_name}`"
|
99
|
+
inclusion:
|
100
|
+
default: "[%{service_class_name}] Неправильное значение в `%{output_name}`, должно быть одним из `%{output_inclusion}`, получено `%{value}`"
|
101
101
|
min:
|
102
102
|
default: "[%{service_class_name}] Выходящий атрибут `%{output_name}` получил значение `%{value}`, которое меньше `%{option_value}`"
|
103
103
|
max:
|
@@ -5,12 +5,16 @@ module Servactory
|
|
5
5
|
module OptionHelpers
|
6
6
|
class OptionHelpersCollection
|
7
7
|
extend Forwardable
|
8
|
-
def_delegators :@collection, :<<, :find, :merge
|
8
|
+
def_delegators :@collection, :<<, :filter, :map, :find, :merge
|
9
9
|
|
10
10
|
def initialize(collection = Set.new)
|
11
11
|
@collection = collection
|
12
12
|
end
|
13
13
|
|
14
|
+
def dynamic_options
|
15
|
+
OptionHelpersCollection.new(filter(&:dynamic_option?))
|
16
|
+
end
|
17
|
+
|
14
18
|
def find_by(name:)
|
15
19
|
find { |helper| helper.name == name }
|
16
20
|
end
|
@@ -71,19 +71,22 @@ module Servactory
|
|
71
71
|
def default_input_option_helpers
|
72
72
|
Set[
|
73
73
|
Servactory::Maintenance::Attributes::OptionHelper.new(name: :optional, equivalent: { required: false }),
|
74
|
-
Servactory::ToolKit::DynamicOptions::ConsistsOf.use(collection_mode_class_names:)
|
74
|
+
Servactory::ToolKit::DynamicOptions::ConsistsOf.use(collection_mode_class_names:),
|
75
|
+
Servactory::ToolKit::DynamicOptions::Inclusion.use
|
75
76
|
]
|
76
77
|
end
|
77
78
|
|
78
79
|
def default_internal_option_helpers
|
79
80
|
Set[
|
80
|
-
Servactory::ToolKit::DynamicOptions::ConsistsOf.use(collection_mode_class_names:)
|
81
|
+
Servactory::ToolKit::DynamicOptions::ConsistsOf.use(collection_mode_class_names:),
|
82
|
+
Servactory::ToolKit::DynamicOptions::Inclusion.use
|
81
83
|
]
|
82
84
|
end
|
83
85
|
|
84
86
|
def default_output_option_helpers
|
85
87
|
Set[
|
86
|
-
Servactory::ToolKit::DynamicOptions::ConsistsOf.use(collection_mode_class_names:)
|
88
|
+
Servactory::ToolKit::DynamicOptions::ConsistsOf.use(collection_mode_class_names:),
|
89
|
+
Servactory::ToolKit::DynamicOptions::Inclusion.use
|
87
90
|
]
|
88
91
|
end
|
89
92
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Servactory
|
4
|
+
module Context
|
5
|
+
module Warehouse
|
6
|
+
class Base
|
7
|
+
def initialize(arguments = {})
|
8
|
+
@arguments = arguments
|
9
|
+
end
|
10
|
+
|
11
|
+
# def fetch!(name)
|
12
|
+
# @arguments.fetch(name)
|
13
|
+
# end
|
14
|
+
|
15
|
+
def fetch(name, default_value)
|
16
|
+
@arguments.fetch(name, default_value)
|
17
|
+
end
|
18
|
+
|
19
|
+
def assign(key, value)
|
20
|
+
@arguments[key] = value
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Servactory
|
4
|
+
module Context
|
5
|
+
module Warehouse
|
6
|
+
class Inputs < Base
|
7
|
+
def initialize(context, arguments = {})
|
8
|
+
@context = context
|
9
|
+
|
10
|
+
super(arguments)
|
11
|
+
end
|
12
|
+
|
13
|
+
def names
|
14
|
+
@arguments.keys
|
15
|
+
end
|
16
|
+
|
17
|
+
def merge!(arguments)
|
18
|
+
@arguments.merge!(arguments)
|
19
|
+
end
|
20
|
+
|
21
|
+
##########################################################################
|
22
|
+
|
23
|
+
def method_missing(name, *_args)
|
24
|
+
input_name = @context.class.config.predicate_methods_enabled? ? name.to_s.chomp("?").to_sym : name
|
25
|
+
|
26
|
+
input_value = @arguments.fetch(input_name) { raise_error_for(input_name) }
|
27
|
+
|
28
|
+
if name.to_s.end_with?("?") && @context.class.config.predicate_methods_enabled?
|
29
|
+
Servactory::Utils.query_attribute(input_value)
|
30
|
+
else
|
31
|
+
input_value
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def respond_to_missing?(name, *)
|
36
|
+
@arguments.fetch(name) { raise_error_for(name) }
|
37
|
+
end
|
38
|
+
|
39
|
+
##########################################################################
|
40
|
+
|
41
|
+
def raise_error_for(input_name)
|
42
|
+
message_text = @context.send(:servactory_service_info).translate(
|
43
|
+
"inputs.undefined.for_fetch",
|
44
|
+
input_name:
|
45
|
+
)
|
46
|
+
|
47
|
+
raise @context.class.config.input_exception_class.new(
|
48
|
+
context: @context,
|
49
|
+
message: message_text,
|
50
|
+
input_name:
|
51
|
+
)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Servactory
|
4
|
+
module Context
|
5
|
+
module Warehouse
|
6
|
+
class Setup
|
7
|
+
def initialize(context)
|
8
|
+
@context = context
|
9
|
+
end
|
10
|
+
|
11
|
+
def assign_inputs(arguments)
|
12
|
+
context_data[:inputs].merge!(arguments)
|
13
|
+
end
|
14
|
+
|
15
|
+
def fetch_input(name)
|
16
|
+
inputs.fetch(name, nil)
|
17
|
+
end
|
18
|
+
|
19
|
+
def assign_internal(name, value)
|
20
|
+
assign_attribute(:internals, name, value)
|
21
|
+
end
|
22
|
+
|
23
|
+
def fetch_internal(name)
|
24
|
+
internals.fetch(name, nil)
|
25
|
+
end
|
26
|
+
|
27
|
+
def assign_output(name, value)
|
28
|
+
assign_attribute(:outputs, name, value)
|
29
|
+
end
|
30
|
+
|
31
|
+
def fetch_output(name)
|
32
|
+
outputs.fetch(name, nil)
|
33
|
+
end
|
34
|
+
|
35
|
+
def inputs
|
36
|
+
@inputs ||= context_data.fetch(:inputs)
|
37
|
+
end
|
38
|
+
|
39
|
+
def internals
|
40
|
+
@internals ||= context_data.fetch(:internals)
|
41
|
+
end
|
42
|
+
|
43
|
+
def outputs
|
44
|
+
@outputs ||= context_data.fetch(:outputs)
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def assign_attribute(section, name, value)
|
50
|
+
context_data[section].assign(name, value)
|
51
|
+
end
|
52
|
+
|
53
|
+
def context_data
|
54
|
+
@context_data ||= state.fetch(context_id)
|
55
|
+
end
|
56
|
+
|
57
|
+
def state
|
58
|
+
{
|
59
|
+
context_id => {
|
60
|
+
inputs: Servactory::Context::Warehouse::Inputs.new(@context),
|
61
|
+
internals: Servactory::Context::Warehouse::Internals.new,
|
62
|
+
outputs: Servactory::Context::Warehouse::Outputs.new
|
63
|
+
}
|
64
|
+
}
|
65
|
+
end
|
66
|
+
|
67
|
+
def context_id
|
68
|
+
@context_id ||= "context_#{@context.object_id}"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -40,7 +40,7 @@ module Servactory
|
|
40
40
|
|
41
41
|
private
|
42
42
|
|
43
|
-
# rubocop:disable Metrics/MethodLength, Metrics/AbcSize,
|
43
|
+
# rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Lint/UnusedMethodArgument
|
44
44
|
def fetch_with(name:, &block)
|
45
45
|
input_name = @context.class.config.predicate_methods_enabled? ? name.to_s.chomp("?").to_sym : name
|
46
46
|
|
@@ -48,7 +48,7 @@ module Servactory
|
|
48
48
|
|
49
49
|
return yield if input.nil?
|
50
50
|
|
51
|
-
input_value = @context.send(:
|
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
54
|
if input.hash_mode? && (tmp_schema = input.schema.fetch(:is)).present?
|
@@ -64,7 +64,7 @@ module Servactory
|
|
64
64
|
input_value
|
65
65
|
end
|
66
66
|
end
|
67
|
-
# rubocop:enable Metrics/MethodLength, Metrics/AbcSize,
|
67
|
+
# rubocop:enable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Lint/UnusedMethodArgument
|
68
68
|
|
69
69
|
def prepare_hash_values_inside(object:, schema:) # rubocop:disable Metrics/MethodLength
|
70
70
|
return object unless object.respond_to?(:fetch)
|
@@ -50,7 +50,7 @@ module Servactory
|
|
50
50
|
value:
|
51
51
|
)
|
52
52
|
|
53
|
-
@context.send(:
|
53
|
+
@context.send(:servactory_service_warehouse).assign_internal(internal.name, value)
|
54
54
|
end
|
55
55
|
|
56
56
|
def fetch_with(name:, &block) # rubocop:disable Metrics/AbcSize, Lint/UnusedMethodArgument
|
@@ -59,7 +59,7 @@ module Servactory
|
|
59
59
|
|
60
60
|
return yield if internal.nil?
|
61
61
|
|
62
|
-
internal_value = @context.send(:
|
62
|
+
internal_value = @context.send(:servactory_service_warehouse).fetch_internal(internal.name)
|
63
63
|
|
64
64
|
if name.to_s.end_with?("?") && @context.class.config.predicate_methods_enabled?
|
65
65
|
Servactory::Utils.query_attribute(internal_value)
|
@@ -50,7 +50,7 @@ module Servactory
|
|
50
50
|
value:
|
51
51
|
)
|
52
52
|
|
53
|
-
@context.send(:
|
53
|
+
@context.send(:servactory_service_warehouse).assign_output(output.name, value)
|
54
54
|
end
|
55
55
|
|
56
56
|
def fetch_with(name:, &block) # rubocop:disable Metrics/AbcSize, Lint/UnusedMethodArgument
|
@@ -59,7 +59,7 @@ module Servactory
|
|
59
59
|
|
60
60
|
return yield if output.nil?
|
61
61
|
|
62
|
-
output_value = @context.send(:
|
62
|
+
output_value = @context.send(:servactory_service_warehouse).fetch_output(output.name)
|
63
63
|
|
64
64
|
if name.to_s.end_with?("?") && @context.class.config.predicate_methods_enabled?
|
65
65
|
Servactory::Utils.query_attribute(output_value)
|
@@ -126,8 +126,8 @@ module Servactory
|
|
126
126
|
@servactory_service_info ||= self.class::Actor.new(self)
|
127
127
|
end
|
128
128
|
|
129
|
-
def
|
130
|
-
@
|
129
|
+
def servactory_service_warehouse
|
130
|
+
@servactory_service_warehouse ||= Warehouse::Setup.new(self)
|
131
131
|
end
|
132
132
|
end
|
133
133
|
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Servactory
|
4
|
+
module Info
|
5
|
+
class Builder
|
6
|
+
attr_reader :inputs,
|
7
|
+
:internals,
|
8
|
+
:outputs
|
9
|
+
|
10
|
+
def self.build(...)
|
11
|
+
new.build(...)
|
12
|
+
end
|
13
|
+
|
14
|
+
def build(collection_of_inputs:, collection_of_internals:, collection_of_outputs:, config:)
|
15
|
+
dynamic_options = config.input_option_helpers.dynamic_options
|
16
|
+
|
17
|
+
build_inputs_with(collection_of_inputs:, dynamic_options:)
|
18
|
+
build_internals_with(collection_of_internals:, dynamic_options:)
|
19
|
+
build_outputs_with(collection_of_outputs:, dynamic_options:)
|
20
|
+
|
21
|
+
self
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def build_inputs_with(collection_of_inputs:, dynamic_options:)
|
27
|
+
@inputs = collection_of_inputs.to_h do |input|
|
28
|
+
options = build_options_for(input, dynamic_options)
|
29
|
+
options = enrich_options_for(input, options)
|
30
|
+
|
31
|
+
options[:required] = input.required
|
32
|
+
options[:default] = input.default
|
33
|
+
|
34
|
+
[
|
35
|
+
input.name,
|
36
|
+
options
|
37
|
+
]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def build_internals_with(collection_of_internals:, dynamic_options:)
|
42
|
+
@internals = collection_of_internals.to_h do |internal|
|
43
|
+
options = build_options_for(internal, dynamic_options)
|
44
|
+
options = enrich_options_for(internal, options)
|
45
|
+
|
46
|
+
[
|
47
|
+
internal.name,
|
48
|
+
options
|
49
|
+
]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def build_outputs_with(collection_of_outputs:, dynamic_options:)
|
54
|
+
@outputs = collection_of_outputs.to_h do |output|
|
55
|
+
options = build_options_for(output, dynamic_options)
|
56
|
+
options = enrich_options_for(output, options)
|
57
|
+
|
58
|
+
[
|
59
|
+
output.name,
|
60
|
+
options
|
61
|
+
]
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
##########################################################################
|
66
|
+
|
67
|
+
def build_options_for(attribute, dynamic_options)
|
68
|
+
attribute.options.to_h do |key, value|
|
69
|
+
dynamic_option = dynamic_options.find_by(name: key)
|
70
|
+
|
71
|
+
next [nil, nil] if dynamic_option.nil?
|
72
|
+
|
73
|
+
body_key = dynamic_option.meta.fetch(:body_key)
|
74
|
+
|
75
|
+
option = build_option_from(body_key:, value:)
|
76
|
+
|
77
|
+
[
|
78
|
+
dynamic_option.name,
|
79
|
+
option
|
80
|
+
]
|
81
|
+
end.compact
|
82
|
+
end
|
83
|
+
|
84
|
+
def build_option_from(body_key:, value:)
|
85
|
+
{
|
86
|
+
body_key => value.is_a?(Hash) ? value.fetch(body_key, value) : value,
|
87
|
+
message: value.is_a?(Hash) ? value.fetch(:message, nil) : nil
|
88
|
+
}
|
89
|
+
end
|
90
|
+
|
91
|
+
def enrich_options_for(attribute, options)
|
92
|
+
actor = attribute.class::Actor.new(attribute)
|
93
|
+
must = attribute.collection_of_options.find_by(name: :must)
|
94
|
+
|
95
|
+
options.merge(
|
96
|
+
actor:,
|
97
|
+
types: attribute.types,
|
98
|
+
must: must.body
|
99
|
+
)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
data/lib/servactory/info/dsl.rb
CHANGED
@@ -8,58 +8,15 @@ module Servactory
|
|
8
8
|
end
|
9
9
|
|
10
10
|
module ClassMethods
|
11
|
-
def info
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
[
|
19
|
-
input.name,
|
20
|
-
{
|
21
|
-
actor:,
|
22
|
-
types: input.types,
|
23
|
-
required: input.required,
|
24
|
-
default: input.default,
|
25
|
-
inclusion: inclusion.body,
|
26
|
-
must: must.body
|
27
|
-
}
|
28
|
-
]
|
29
|
-
end,
|
30
|
-
|
31
|
-
internals: collection_of_internals.to_h do |internal|
|
32
|
-
actor = internal.class::Actor.new(internal)
|
33
|
-
inclusion = internal.collection_of_options.find_by(name: :inclusion)
|
34
|
-
must = internal.collection_of_options.find_by(name: :must)
|
35
|
-
|
36
|
-
[
|
37
|
-
internal.name,
|
38
|
-
{
|
39
|
-
actor:,
|
40
|
-
types: internal.types,
|
41
|
-
inclusion: inclusion.body,
|
42
|
-
must: must.body
|
43
|
-
}
|
44
|
-
]
|
45
|
-
end,
|
46
|
-
|
47
|
-
outputs: collection_of_outputs.to_h do |output|
|
48
|
-
actor = output.class::Actor.new(output)
|
49
|
-
inclusion = output.collection_of_options.find_by(name: :inclusion)
|
50
|
-
must = output.collection_of_options.find_by(name: :must)
|
51
|
-
|
52
|
-
[
|
53
|
-
output.name,
|
54
|
-
{
|
55
|
-
actor:,
|
56
|
-
types: output.types,
|
57
|
-
inclusion: inclusion.body,
|
58
|
-
must: must.body
|
59
|
-
}
|
60
|
-
]
|
61
|
-
end
|
11
|
+
def info
|
12
|
+
builder = Builder.build(
|
13
|
+
collection_of_inputs:,
|
14
|
+
collection_of_internals:,
|
15
|
+
collection_of_outputs:,
|
16
|
+
config:
|
62
17
|
)
|
18
|
+
|
19
|
+
Result.new(builder)
|
63
20
|
end
|
64
21
|
end
|
65
22
|
end
|
@@ -7,10 +7,10 @@ module Servactory
|
|
7
7
|
:internals,
|
8
8
|
:outputs
|
9
9
|
|
10
|
-
def initialize(
|
11
|
-
@inputs = inputs
|
12
|
-
@internals = internals
|
13
|
-
@outputs = outputs
|
10
|
+
def initialize(builder)
|
11
|
+
@inputs = builder.inputs
|
12
|
+
@internals = builder.internals
|
13
|
+
@outputs = builder.outputs
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
@@ -7,13 +7,15 @@ module Servactory
|
|
7
7
|
attr_reader :name,
|
8
8
|
:internal_name,
|
9
9
|
:types,
|
10
|
-
:
|
10
|
+
:default,
|
11
|
+
:options
|
11
12
|
|
12
|
-
def initialize(input) # rubocop:disable Metrics/MethodLength
|
13
|
+
def initialize(input) # rubocop:disable Metrics/MethodLength
|
13
14
|
@name = input.name
|
14
15
|
@internal_name = input.internal_name
|
15
16
|
@types = input.types
|
16
|
-
@
|
17
|
+
@default = input.default
|
18
|
+
@options = input.options
|
17
19
|
|
18
20
|
define_singleton_method(:system_name) { input.system_name }
|
19
21
|
define_singleton_method(:i18n_name) { input.i18n_name }
|
@@ -28,7 +30,8 @@ module Servactory
|
|
28
30
|
|
29
31
|
attr_reader :name,
|
30
32
|
:internal_name,
|
31
|
-
:collection_of_options
|
33
|
+
:collection_of_options,
|
34
|
+
:options
|
32
35
|
|
33
36
|
# rubocop:disable Style/KeywordParametersOrder
|
34
37
|
def initialize(
|
@@ -75,12 +78,12 @@ module Servactory
|
|
75
78
|
types: true,
|
76
79
|
default: true,
|
77
80
|
hash: true,
|
78
|
-
inclusion: true,
|
79
81
|
must: true,
|
80
82
|
prepare: true
|
81
83
|
}
|
82
84
|
)
|
83
85
|
|
86
|
+
@options = options
|
84
87
|
@collection_of_options = options_registrar.collection
|
85
88
|
end
|
86
89
|
|