servactory 2.0.2 → 2.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/servactory/context/workspace/inputs.rb +8 -6
- data/lib/servactory/context/workspace.rb +1 -0
- data/lib/servactory/inputs/input.rb +31 -206
- data/lib/servactory/internals/internal.rb +16 -62
- data/lib/servactory/maintenance/attributes/options/registrar.rb +240 -0
- data/lib/servactory/outputs/output.rb +16 -62
- data/lib/servactory/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f3edad8d15393a6541eee430383fcd03da3ddf339bf6215ddf95d391487dde6
|
4
|
+
data.tar.gz: 7143c15722e8d1183f523126dbf265315f182588b193f233a6f140612c532af0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0f2f96d3707a5ea5787a837e90e4c3a45ccf0464499525259e357d918ea6173b3e4318ff1f3fc70841f04bfbc2971e2f66fd378bdaf733d82e0237b5dff242ad
|
7
|
+
data.tar.gz: 5aae275ca976e9a4b5d3db1bec44e2a9bcfac18ef53c7b6e6fbd15a874d89970d066073eea09369d80bacc0ce81d6a6190883178d58c92b9965def62f3be809f
|
@@ -7,8 +7,9 @@ module Servactory
|
|
7
7
|
RESERVED_ATTRIBUTES = %i[type required default].freeze
|
8
8
|
private_constant :RESERVED_ATTRIBUTES
|
9
9
|
|
10
|
-
def initialize(context:, collection_of_inputs:)
|
10
|
+
def initialize(context:, incoming_arguments:, collection_of_inputs:)
|
11
11
|
@context = context
|
12
|
+
@incoming_arguments = incoming_arguments
|
12
13
|
@collection_of_inputs = collection_of_inputs
|
13
14
|
end
|
14
15
|
|
@@ -47,19 +48,20 @@ module Servactory
|
|
47
48
|
|
48
49
|
return yield if input.nil?
|
49
50
|
|
50
|
-
|
51
|
+
input_value = @incoming_arguments.fetch(input.name, nil)
|
52
|
+
input_value = input.default if input.optional? && input_value.blank?
|
51
53
|
|
52
54
|
if input.hash_mode? && (tmp_schema = input.schema.fetch(:is)).present?
|
53
|
-
|
55
|
+
input_value = prepare_hash_values_inside(object: input_value, schema: tmp_schema)
|
54
56
|
end
|
55
57
|
|
56
58
|
input_prepare = input.prepare.fetch(:in, nil)
|
57
|
-
|
59
|
+
input_value = input_prepare.call(value: input_value) if input_prepare.present?
|
58
60
|
|
59
61
|
if name.to_s.end_with?("?")
|
60
|
-
Servactory::Utils.query_attribute(
|
62
|
+
Servactory::Utils.query_attribute(input_value)
|
61
63
|
else
|
62
|
-
|
64
|
+
input_value
|
63
65
|
end
|
64
66
|
end
|
65
67
|
# rubocop:enable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Lint/UnusedMethodArgument
|
@@ -2,14 +2,12 @@
|
|
2
2
|
|
3
3
|
module Servactory
|
4
4
|
module Inputs
|
5
|
-
class Input
|
5
|
+
class Input
|
6
6
|
attr_accessor :value
|
7
7
|
|
8
8
|
attr_reader :name,
|
9
9
|
:internal_name,
|
10
|
-
:
|
11
|
-
:hash_mode_class_names,
|
12
|
-
:option_helpers
|
10
|
+
:collection_of_options
|
13
11
|
|
14
12
|
# rubocop:disable Style/KeywordParametersOrder
|
15
13
|
def initialize(
|
@@ -27,14 +25,12 @@ module Servactory
|
|
27
25
|
@hash_mode_class_names = hash_mode_class_names
|
28
26
|
@option_helpers = option_helpers
|
29
27
|
|
30
|
-
|
31
|
-
|
32
|
-
add_basic_options_with(options)
|
28
|
+
register_options(helpers: helpers, options: options)
|
33
29
|
end
|
34
30
|
# rubocop:enable Style/KeywordParametersOrder
|
35
31
|
|
36
32
|
def method_missing(name, *args, &block)
|
37
|
-
option = collection_of_options.find_by(name: name)
|
33
|
+
option = @collection_of_options.find_by(name: name)
|
38
34
|
|
39
35
|
return super if option.nil?
|
40
36
|
|
@@ -42,14 +38,37 @@ module Servactory
|
|
42
38
|
end
|
43
39
|
|
44
40
|
def respond_to_missing?(name, *)
|
45
|
-
collection_of_options.names.include?(name) || super
|
41
|
+
@collection_of_options.names.include?(name) || super
|
42
|
+
end
|
43
|
+
|
44
|
+
def register_options(helpers:, options:) # rubocop:disable Metrics/MethodLength
|
45
|
+
options = apply_helpers_for_options(helpers: helpers, options: options) if helpers.present?
|
46
|
+
|
47
|
+
options_registrar = Servactory::Maintenance::Attributes::Options::Registrar.register(
|
48
|
+
attribute: self,
|
49
|
+
collection_mode_class_names: @collection_mode_class_names,
|
50
|
+
hash_mode_class_names: @hash_mode_class_names,
|
51
|
+
options: options,
|
52
|
+
features: {
|
53
|
+
required: true,
|
54
|
+
types: true,
|
55
|
+
default: true,
|
56
|
+
collection: true,
|
57
|
+
hash: true,
|
58
|
+
inclusion: true,
|
59
|
+
must: true,
|
60
|
+
prepare: true
|
61
|
+
}
|
62
|
+
)
|
63
|
+
|
64
|
+
@collection_of_options = options_registrar.collection
|
46
65
|
end
|
47
66
|
|
48
67
|
def apply_helpers_for_options(helpers:, options:)
|
49
68
|
prepared_options = {}
|
50
69
|
|
51
70
|
helpers.each do |helper|
|
52
|
-
found_helper = option_helpers.find_by(name: helper)
|
71
|
+
found_helper = @option_helpers.find_by(name: helper)
|
53
72
|
|
54
73
|
next if found_helper.blank?
|
55
74
|
|
@@ -59,206 +78,12 @@ module Servactory
|
|
59
78
|
options.merge(prepared_options)
|
60
79
|
end
|
61
80
|
|
62
|
-
def add_basic_options_with(options)
|
63
|
-
# Check Class: Servactory::Inputs::Validations::Required
|
64
|
-
add_required_option_with(options)
|
65
|
-
|
66
|
-
# Check Class: Servactory::Inputs::Validations::Type
|
67
|
-
add_types_option_with(options)
|
68
|
-
add_default_option_with(options)
|
69
|
-
add_collection_option_with(options)
|
70
|
-
add_hash_option_with(options)
|
71
|
-
|
72
|
-
# Check Class: Servactory::Inputs::Validations::Inclusion
|
73
|
-
add_inclusion_option_with(options)
|
74
|
-
|
75
|
-
# Check Class: Servactory::Inputs::Validations::Must
|
76
|
-
add_must_option_with(options)
|
77
|
-
|
78
|
-
# Check Class: nil
|
79
|
-
add_prepare_option_with(options)
|
80
|
-
end
|
81
|
-
|
82
|
-
def add_required_option_with(options) # rubocop:disable Metrics/MethodLength
|
83
|
-
collection_of_options << Servactory::Maintenance::Attributes::Option.new(
|
84
|
-
name: :required,
|
85
|
-
attribute: self,
|
86
|
-
validation_class: Servactory::Inputs::Validations::Required,
|
87
|
-
define_methods: [
|
88
|
-
Servactory::Maintenance::Attributes::DefineMethod.new(
|
89
|
-
name: :required?,
|
90
|
-
content: ->(option:) { Servactory::Utils.true?(option[:is]) }
|
91
|
-
),
|
92
|
-
Servactory::Maintenance::Attributes::DefineMethod.new(
|
93
|
-
name: :optional?,
|
94
|
-
content: ->(option:) { !Servactory::Utils.true?(option[:is]) }
|
95
|
-
)
|
96
|
-
],
|
97
|
-
define_conflicts: [
|
98
|
-
Servactory::Maintenance::Attributes::DefineConflict.new(
|
99
|
-
content: -> { :required_vs_default if required? && default_value_present? }
|
100
|
-
)
|
101
|
-
],
|
102
|
-
need_for_checks: true,
|
103
|
-
body_key: :is,
|
104
|
-
body_fallback: true,
|
105
|
-
**options
|
106
|
-
)
|
107
|
-
end
|
108
|
-
|
109
|
-
def add_types_option_with(options)
|
110
|
-
collection_of_options << Servactory::Maintenance::Attributes::Option.new(
|
111
|
-
name: :types,
|
112
|
-
attribute: self,
|
113
|
-
validation_class: Servactory::Inputs::Validations::Type,
|
114
|
-
original_value: Array(options.fetch(:type)),
|
115
|
-
need_for_checks: true,
|
116
|
-
body_fallback: nil,
|
117
|
-
with_advanced_mode: false
|
118
|
-
)
|
119
|
-
end
|
120
|
-
|
121
|
-
def add_default_option_with(options) # rubocop:disable Metrics/MethodLength
|
122
|
-
collection_of_options << Servactory::Maintenance::Attributes::Option.new(
|
123
|
-
name: :default,
|
124
|
-
attribute: self,
|
125
|
-
validation_class: Servactory::Inputs::Validations::Type,
|
126
|
-
define_methods: [
|
127
|
-
Servactory::Maintenance::Attributes::DefineMethod.new(
|
128
|
-
name: :default_value_present?,
|
129
|
-
content: ->(option:) { !option.nil? }
|
130
|
-
)
|
131
|
-
],
|
132
|
-
need_for_checks: true,
|
133
|
-
body_fallback: nil,
|
134
|
-
with_advanced_mode: false,
|
135
|
-
**options
|
136
|
-
)
|
137
|
-
end
|
138
|
-
|
139
|
-
def add_collection_option_with(options) # rubocop:disable Metrics/MethodLength
|
140
|
-
collection_of_options << Servactory::Maintenance::Attributes::Option.new(
|
141
|
-
name: :consists_of,
|
142
|
-
attribute: self,
|
143
|
-
validation_class: Servactory::Inputs::Validations::Type,
|
144
|
-
define_methods: [
|
145
|
-
Servactory::Maintenance::Attributes::DefineMethod.new(
|
146
|
-
name: :collection_mode?,
|
147
|
-
content: ->(**) { collection_mode_class_names.include?(options.fetch(:type)) }
|
148
|
-
)
|
149
|
-
],
|
150
|
-
define_conflicts: [
|
151
|
-
Servactory::Maintenance::Attributes::DefineConflict.new(
|
152
|
-
content: -> { :collection_vs_inclusion if collection_mode? && inclusion_present? }
|
153
|
-
)
|
154
|
-
],
|
155
|
-
need_for_checks: false,
|
156
|
-
body_key: :type,
|
157
|
-
body_value: String,
|
158
|
-
body_fallback: String,
|
159
|
-
**options
|
160
|
-
)
|
161
|
-
end
|
162
|
-
|
163
|
-
def add_hash_option_with(options) # rubocop:disable Metrics/MethodLength
|
164
|
-
collection_of_options << Servactory::Maintenance::Attributes::Option.new(
|
165
|
-
name: :schema,
|
166
|
-
attribute: self,
|
167
|
-
validation_class: Servactory::Inputs::Validations::Type,
|
168
|
-
define_methods: [
|
169
|
-
Servactory::Maintenance::Attributes::DefineMethod.new(
|
170
|
-
name: :hash_mode?,
|
171
|
-
content: ->(**) { hash_mode_class_names.include?(options.fetch(:type)) }
|
172
|
-
)
|
173
|
-
],
|
174
|
-
define_conflicts: [
|
175
|
-
Servactory::Maintenance::Attributes::DefineConflict.new(
|
176
|
-
content: -> { :object_vs_inclusion if hash_mode? && inclusion_present? }
|
177
|
-
)
|
178
|
-
],
|
179
|
-
need_for_checks: false,
|
180
|
-
body_key: :is,
|
181
|
-
body_fallback: {},
|
182
|
-
**options
|
183
|
-
)
|
184
|
-
end
|
185
|
-
|
186
|
-
def add_inclusion_option_with(options) # rubocop:disable Metrics/MethodLength
|
187
|
-
collection_of_options << Servactory::Maintenance::Attributes::Option.new(
|
188
|
-
name: :inclusion,
|
189
|
-
attribute: self,
|
190
|
-
validation_class: Servactory::Inputs::Validations::Inclusion,
|
191
|
-
define_methods: [
|
192
|
-
Servactory::Maintenance::Attributes::DefineMethod.new(
|
193
|
-
name: :inclusion_present?,
|
194
|
-
content: ->(option:) { option[:in].is_a?(Array) && option[:in].present? }
|
195
|
-
)
|
196
|
-
],
|
197
|
-
need_for_checks: true,
|
198
|
-
body_key: :in,
|
199
|
-
body_fallback: nil,
|
200
|
-
**options
|
201
|
-
)
|
202
|
-
end
|
203
|
-
|
204
|
-
def add_must_option_with(options) # rubocop:disable Metrics/MethodLength
|
205
|
-
collection_of_options << Servactory::Maintenance::Attributes::Option.new(
|
206
|
-
name: :must,
|
207
|
-
attribute: self,
|
208
|
-
validation_class: Servactory::Inputs::Validations::Must,
|
209
|
-
define_methods: [
|
210
|
-
Servactory::Maintenance::Attributes::DefineMethod.new(
|
211
|
-
name: :must_present?,
|
212
|
-
content: ->(option:) { option.present? }
|
213
|
-
)
|
214
|
-
],
|
215
|
-
need_for_checks: true,
|
216
|
-
body_key: :is,
|
217
|
-
body_fallback: nil,
|
218
|
-
with_advanced_mode: false,
|
219
|
-
**options
|
220
|
-
)
|
221
|
-
end
|
222
|
-
|
223
|
-
def add_prepare_option_with(options) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
224
|
-
collection_of_options << Servactory::Maintenance::Attributes::Option.new(
|
225
|
-
name: :prepare,
|
226
|
-
attribute: self,
|
227
|
-
validation_class: nil,
|
228
|
-
define_methods: [
|
229
|
-
Servactory::Maintenance::Attributes::DefineMethod.new(
|
230
|
-
name: :prepare_present?,
|
231
|
-
content: ->(option:) { option[:in].present? }
|
232
|
-
)
|
233
|
-
],
|
234
|
-
define_conflicts: [
|
235
|
-
Servactory::Maintenance::Attributes::DefineConflict.new(
|
236
|
-
content: -> { :prepare_vs_collection if prepare_present? && collection_mode? }
|
237
|
-
),
|
238
|
-
Servactory::Maintenance::Attributes::DefineConflict.new(
|
239
|
-
content: -> { :prepare_vs_inclusion if prepare_present? && inclusion_present? }
|
240
|
-
),
|
241
|
-
Servactory::Maintenance::Attributes::DefineConflict.new(
|
242
|
-
content: -> { :prepare_vs_must if prepare_present? && must_present? }
|
243
|
-
)
|
244
|
-
],
|
245
|
-
need_for_checks: false,
|
246
|
-
body_key: :in,
|
247
|
-
body_fallback: false,
|
248
|
-
**options
|
249
|
-
)
|
250
|
-
end
|
251
|
-
|
252
|
-
def collection_of_options
|
253
|
-
@collection_of_options ||= Servactory::Maintenance::Attributes::OptionsCollection.new
|
254
|
-
end
|
255
|
-
|
256
81
|
def options_for_checks
|
257
|
-
collection_of_options.options_for_checks
|
82
|
+
@collection_of_options.options_for_checks
|
258
83
|
end
|
259
84
|
|
260
85
|
def conflict_code
|
261
|
-
collection_of_options.defined_conflict_code
|
86
|
+
@collection_of_options.defined_conflict_code
|
262
87
|
end
|
263
88
|
|
264
89
|
def with_conflicts?
|
@@ -3,9 +3,7 @@
|
|
3
3
|
module Servactory
|
4
4
|
module Internals
|
5
5
|
class Internal
|
6
|
-
attr_reader :name
|
7
|
-
:collection_mode_class_names,
|
8
|
-
:hash_mode_class_names
|
6
|
+
attr_reader :name
|
9
7
|
|
10
8
|
def initialize(
|
11
9
|
name,
|
@@ -17,11 +15,11 @@ module Servactory
|
|
17
15
|
@collection_mode_class_names = collection_mode_class_names
|
18
16
|
@hash_mode_class_names = hash_mode_class_names
|
19
17
|
|
20
|
-
|
18
|
+
register_options(options: options)
|
21
19
|
end
|
22
20
|
|
23
21
|
def method_missing(name, *args, &block)
|
24
|
-
option = collection_of_options.find_by(name: name)
|
22
|
+
option = @collection_of_options.find_by(name: name)
|
25
23
|
|
26
24
|
return super if option.nil?
|
27
25
|
|
@@ -29,71 +27,27 @@ module Servactory
|
|
29
27
|
end
|
30
28
|
|
31
29
|
def respond_to_missing?(name, *)
|
32
|
-
collection_of_options.names.include?(name) || super
|
30
|
+
@collection_of_options.names.include?(name) || super
|
33
31
|
end
|
34
32
|
|
35
|
-
def
|
36
|
-
|
37
|
-
add_types_option_with(options)
|
38
|
-
add_collection_option_with(options)
|
39
|
-
add_hash_option_with(options)
|
40
|
-
end
|
41
|
-
|
42
|
-
def add_types_option_with(options)
|
43
|
-
collection_of_options << Servactory::Maintenance::Attributes::Option.new(
|
44
|
-
name: :types,
|
45
|
-
attribute: self,
|
46
|
-
validation_class: Servactory::Internals::Validations::Type,
|
47
|
-
original_value: Array(options.fetch(:type)),
|
48
|
-
need_for_checks: true,
|
49
|
-
body_fallback: nil,
|
50
|
-
with_advanced_mode: false
|
51
|
-
)
|
52
|
-
end
|
53
|
-
|
54
|
-
def add_collection_option_with(options) # rubocop:disable Metrics/MethodLength
|
55
|
-
collection_of_options << Servactory::Maintenance::Attributes::Option.new(
|
56
|
-
name: :consists_of,
|
33
|
+
def register_options(options:) # rubocop:disable Metrics/MethodLength
|
34
|
+
options_registrar = Servactory::Maintenance::Attributes::Options::Registrar.register(
|
57
35
|
attribute: self,
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
body_key: :type,
|
67
|
-
body_value: String,
|
68
|
-
body_fallback: String,
|
69
|
-
**options
|
36
|
+
collection_mode_class_names: @collection_mode_class_names,
|
37
|
+
hash_mode_class_names: @hash_mode_class_names,
|
38
|
+
options: options,
|
39
|
+
features: {
|
40
|
+
types: true,
|
41
|
+
collection: true,
|
42
|
+
hash: true
|
43
|
+
}
|
70
44
|
)
|
71
|
-
end
|
72
|
-
|
73
|
-
def add_hash_option_with(options) # rubocop:disable Metrics/MethodLength
|
74
|
-
collection_of_options << Servactory::Maintenance::Attributes::Option.new(
|
75
|
-
name: :schema,
|
76
|
-
attribute: self,
|
77
|
-
validation_class: Servactory::Inputs::Validations::Type,
|
78
|
-
define_methods: [
|
79
|
-
Servactory::Maintenance::Attributes::DefineMethod.new(
|
80
|
-
name: :hash_mode?,
|
81
|
-
content: ->(**) { hash_mode_class_names.include?(options.fetch(:type)) }
|
82
|
-
)
|
83
|
-
],
|
84
|
-
need_for_checks: false,
|
85
|
-
body_key: :is,
|
86
|
-
body_fallback: {},
|
87
|
-
**options
|
88
|
-
)
|
89
|
-
end
|
90
45
|
|
91
|
-
|
92
|
-
@collection_of_options ||= Servactory::Maintenance::Attributes::OptionsCollection.new
|
46
|
+
@collection_of_options = options_registrar.collection
|
93
47
|
end
|
94
48
|
|
95
49
|
def options_for_checks
|
96
|
-
collection_of_options.options_for_checks
|
50
|
+
@collection_of_options.options_for_checks
|
97
51
|
end
|
98
52
|
end
|
99
53
|
end
|
@@ -0,0 +1,240 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Servactory
|
4
|
+
module Maintenance
|
5
|
+
module Attributes
|
6
|
+
module Options
|
7
|
+
class Registrar # rubocop:disable Metrics/ClassLength
|
8
|
+
DEFAULT_FEATURES = {
|
9
|
+
required: false,
|
10
|
+
types: false,
|
11
|
+
default: false,
|
12
|
+
collection: false,
|
13
|
+
hash: false,
|
14
|
+
inclusion: false,
|
15
|
+
must: false,
|
16
|
+
prepare: false
|
17
|
+
}.freeze
|
18
|
+
|
19
|
+
private_constant :DEFAULT_FEATURES
|
20
|
+
|
21
|
+
def self.register(...)
|
22
|
+
new(...).register
|
23
|
+
end
|
24
|
+
|
25
|
+
def initialize(attribute:, collection_mode_class_names:, hash_mode_class_names:, options:, features:)
|
26
|
+
@attribute = attribute
|
27
|
+
@collection_mode_class_names = collection_mode_class_names
|
28
|
+
@hash_mode_class_names = hash_mode_class_names
|
29
|
+
@options = options
|
30
|
+
@features = DEFAULT_FEATURES.merge(features)
|
31
|
+
end
|
32
|
+
|
33
|
+
########################################################################
|
34
|
+
|
35
|
+
def register # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
36
|
+
# Check Class: Servactory::Inputs::Validations::Required
|
37
|
+
register_required_option if @features.fetch(:required)
|
38
|
+
|
39
|
+
# Check Class: Servactory::Inputs::Validations::Type
|
40
|
+
register_types_option if @features.fetch(:types)
|
41
|
+
register_default_option if @features.fetch(:default)
|
42
|
+
register_collection_option if @features.fetch(:collection)
|
43
|
+
register_hash_option if @features.fetch(:hash)
|
44
|
+
|
45
|
+
# Check Class: Servactory::Inputs::Validations::Inclusion
|
46
|
+
register_inclusion_option if @features.fetch(:inclusion)
|
47
|
+
|
48
|
+
# Check Class: Servactory::Inputs::Validations::Must
|
49
|
+
register_must_option if @features.fetch(:must)
|
50
|
+
|
51
|
+
# Check Class: nil
|
52
|
+
register_prepare_option if @features.fetch(:prepare)
|
53
|
+
|
54
|
+
self
|
55
|
+
end
|
56
|
+
|
57
|
+
########################################################################
|
58
|
+
|
59
|
+
def register_required_option # rubocop:disable Metrics/MethodLength
|
60
|
+
collection << Servactory::Maintenance::Attributes::Option.new(
|
61
|
+
name: :required,
|
62
|
+
attribute: @attribute,
|
63
|
+
validation_class: Servactory::Inputs::Validations::Required,
|
64
|
+
define_methods: [
|
65
|
+
Servactory::Maintenance::Attributes::DefineMethod.new(
|
66
|
+
name: :required?,
|
67
|
+
content: ->(option:) { Servactory::Utils.true?(option[:is]) }
|
68
|
+
),
|
69
|
+
Servactory::Maintenance::Attributes::DefineMethod.new(
|
70
|
+
name: :optional?,
|
71
|
+
content: ->(option:) { !Servactory::Utils.true?(option[:is]) }
|
72
|
+
)
|
73
|
+
],
|
74
|
+
define_conflicts: [
|
75
|
+
Servactory::Maintenance::Attributes::DefineConflict.new(
|
76
|
+
content: -> { :required_vs_default if @attribute.required? && @attribute.default_value_present? }
|
77
|
+
)
|
78
|
+
],
|
79
|
+
need_for_checks: true,
|
80
|
+
body_key: :is,
|
81
|
+
body_fallback: true,
|
82
|
+
**@options
|
83
|
+
)
|
84
|
+
end
|
85
|
+
|
86
|
+
def register_types_option
|
87
|
+
collection << Servactory::Maintenance::Attributes::Option.new(
|
88
|
+
name: :types,
|
89
|
+
attribute: @attribute,
|
90
|
+
validation_class: Servactory::Inputs::Validations::Type,
|
91
|
+
original_value: Array(@options.fetch(:type)),
|
92
|
+
need_for_checks: true,
|
93
|
+
body_fallback: nil,
|
94
|
+
with_advanced_mode: false
|
95
|
+
)
|
96
|
+
end
|
97
|
+
|
98
|
+
def register_default_option # rubocop:disable Metrics/MethodLength
|
99
|
+
collection << Servactory::Maintenance::Attributes::Option.new(
|
100
|
+
name: :default,
|
101
|
+
attribute: @attribute,
|
102
|
+
validation_class: Servactory::Inputs::Validations::Type,
|
103
|
+
define_methods: [
|
104
|
+
Servactory::Maintenance::Attributes::DefineMethod.new(
|
105
|
+
name: :default_value_present?,
|
106
|
+
content: ->(option:) { !option.nil? }
|
107
|
+
)
|
108
|
+
],
|
109
|
+
need_for_checks: true,
|
110
|
+
body_fallback: nil,
|
111
|
+
with_advanced_mode: false,
|
112
|
+
**@options
|
113
|
+
)
|
114
|
+
end
|
115
|
+
|
116
|
+
def register_collection_option # rubocop:disable Metrics/MethodLength
|
117
|
+
collection << Servactory::Maintenance::Attributes::Option.new(
|
118
|
+
name: :consists_of,
|
119
|
+
attribute: @attribute,
|
120
|
+
validation_class: Servactory::Inputs::Validations::Type,
|
121
|
+
define_methods: [
|
122
|
+
Servactory::Maintenance::Attributes::DefineMethod.new(
|
123
|
+
name: :collection_mode?,
|
124
|
+
content: ->(**) { @collection_mode_class_names.include?(@options.fetch(:type)) }
|
125
|
+
)
|
126
|
+
],
|
127
|
+
define_conflicts: [
|
128
|
+
Servactory::Maintenance::Attributes::DefineConflict.new(
|
129
|
+
content: lambda {
|
130
|
+
:collection_vs_inclusion if @attribute.collection_mode? && @attribute.inclusion_present?
|
131
|
+
}
|
132
|
+
)
|
133
|
+
],
|
134
|
+
need_for_checks: false,
|
135
|
+
body_key: :type,
|
136
|
+
body_value: String,
|
137
|
+
body_fallback: String,
|
138
|
+
**@options
|
139
|
+
)
|
140
|
+
end
|
141
|
+
|
142
|
+
def register_hash_option # rubocop:disable Metrics/MethodLength
|
143
|
+
collection << Servactory::Maintenance::Attributes::Option.new(
|
144
|
+
name: :schema,
|
145
|
+
attribute: @attribute,
|
146
|
+
validation_class: Servactory::Inputs::Validations::Type,
|
147
|
+
define_methods: [
|
148
|
+
Servactory::Maintenance::Attributes::DefineMethod.new(
|
149
|
+
name: :hash_mode?,
|
150
|
+
content: ->(**) { @hash_mode_class_names.include?(@options.fetch(:type)) }
|
151
|
+
)
|
152
|
+
],
|
153
|
+
define_conflicts: [
|
154
|
+
Servactory::Maintenance::Attributes::DefineConflict.new(
|
155
|
+
content: -> { :object_vs_inclusion if @attribute.hash_mode? && @attribute.inclusion_present? }
|
156
|
+
)
|
157
|
+
],
|
158
|
+
need_for_checks: false,
|
159
|
+
body_key: :is,
|
160
|
+
body_fallback: {},
|
161
|
+
**@options
|
162
|
+
)
|
163
|
+
end
|
164
|
+
|
165
|
+
def register_inclusion_option # rubocop:disable Metrics/MethodLength
|
166
|
+
collection << Servactory::Maintenance::Attributes::Option.new(
|
167
|
+
name: :inclusion,
|
168
|
+
attribute: @attribute,
|
169
|
+
validation_class: Servactory::Inputs::Validations::Inclusion,
|
170
|
+
define_methods: [
|
171
|
+
Servactory::Maintenance::Attributes::DefineMethod.new(
|
172
|
+
name: :inclusion_present?,
|
173
|
+
content: ->(option:) { option[:in].is_a?(Array) && option[:in].present? }
|
174
|
+
)
|
175
|
+
],
|
176
|
+
need_for_checks: true,
|
177
|
+
body_key: :in,
|
178
|
+
body_fallback: nil,
|
179
|
+
**@options
|
180
|
+
)
|
181
|
+
end
|
182
|
+
|
183
|
+
def register_must_option # rubocop:disable Metrics/MethodLength
|
184
|
+
collection << Servactory::Maintenance::Attributes::Option.new(
|
185
|
+
name: :must,
|
186
|
+
attribute: @attribute,
|
187
|
+
validation_class: Servactory::Inputs::Validations::Must,
|
188
|
+
define_methods: [
|
189
|
+
Servactory::Maintenance::Attributes::DefineMethod.new(
|
190
|
+
name: :must_present?,
|
191
|
+
content: ->(option:) { option.present? }
|
192
|
+
)
|
193
|
+
],
|
194
|
+
need_for_checks: true,
|
195
|
+
body_key: :is,
|
196
|
+
body_fallback: nil,
|
197
|
+
with_advanced_mode: false,
|
198
|
+
**@options
|
199
|
+
)
|
200
|
+
end
|
201
|
+
|
202
|
+
def register_prepare_option # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
203
|
+
collection << Servactory::Maintenance::Attributes::Option.new(
|
204
|
+
name: :prepare,
|
205
|
+
attribute: @attribute,
|
206
|
+
validation_class: nil,
|
207
|
+
define_methods: [
|
208
|
+
Servactory::Maintenance::Attributes::DefineMethod.new(
|
209
|
+
name: :prepare_present?,
|
210
|
+
content: ->(option:) { option[:in].present? }
|
211
|
+
)
|
212
|
+
],
|
213
|
+
define_conflicts: [
|
214
|
+
Servactory::Maintenance::Attributes::DefineConflict.new(
|
215
|
+
content: -> { :prepare_vs_collection if @attribute.prepare_present? && @attribute.collection_mode? }
|
216
|
+
),
|
217
|
+
Servactory::Maintenance::Attributes::DefineConflict.new(
|
218
|
+
content: -> { :prepare_vs_inclusion if @attribute.prepare_present? && @attribute.inclusion_present? }
|
219
|
+
),
|
220
|
+
Servactory::Maintenance::Attributes::DefineConflict.new(
|
221
|
+
content: -> { :prepare_vs_must if @attribute.prepare_present? && @attribute.must_present? }
|
222
|
+
)
|
223
|
+
],
|
224
|
+
need_for_checks: false,
|
225
|
+
body_key: :in,
|
226
|
+
body_fallback: false,
|
227
|
+
**@options
|
228
|
+
)
|
229
|
+
end
|
230
|
+
|
231
|
+
########################################################################
|
232
|
+
|
233
|
+
def collection
|
234
|
+
@collection ||= Servactory::Maintenance::Attributes::OptionsCollection.new
|
235
|
+
end
|
236
|
+
end
|
237
|
+
end
|
238
|
+
end
|
239
|
+
end
|
240
|
+
end
|
@@ -3,9 +3,7 @@
|
|
3
3
|
module Servactory
|
4
4
|
module Outputs
|
5
5
|
class Output
|
6
|
-
attr_reader :name
|
7
|
-
:collection_mode_class_names,
|
8
|
-
:hash_mode_class_names
|
6
|
+
attr_reader :name
|
9
7
|
|
10
8
|
def initialize(
|
11
9
|
name,
|
@@ -17,11 +15,11 @@ module Servactory
|
|
17
15
|
@collection_mode_class_names = collection_mode_class_names
|
18
16
|
@hash_mode_class_names = hash_mode_class_names
|
19
17
|
|
20
|
-
|
18
|
+
register_options(options: options)
|
21
19
|
end
|
22
20
|
|
23
21
|
def method_missing(name, *args, &block)
|
24
|
-
option = collection_of_options.find_by(name: name)
|
22
|
+
option = @collection_of_options.find_by(name: name)
|
25
23
|
|
26
24
|
return super if option.nil?
|
27
25
|
|
@@ -29,71 +27,27 @@ module Servactory
|
|
29
27
|
end
|
30
28
|
|
31
29
|
def respond_to_missing?(name, *)
|
32
|
-
collection_of_options.names.include?(name) || super
|
30
|
+
@collection_of_options.names.include?(name) || super
|
33
31
|
end
|
34
32
|
|
35
|
-
def
|
36
|
-
|
37
|
-
add_types_option_with(options)
|
38
|
-
add_collection_option_with(options)
|
39
|
-
add_hash_option_with(options)
|
40
|
-
end
|
41
|
-
|
42
|
-
def add_types_option_with(options)
|
43
|
-
collection_of_options << Servactory::Maintenance::Attributes::Option.new(
|
44
|
-
name: :types,
|
45
|
-
attribute: self,
|
46
|
-
validation_class: Servactory::Internals::Validations::Type,
|
47
|
-
original_value: Array(options.fetch(:type)),
|
48
|
-
need_for_checks: true,
|
49
|
-
body_fallback: nil,
|
50
|
-
with_advanced_mode: false
|
51
|
-
)
|
52
|
-
end
|
53
|
-
|
54
|
-
def add_collection_option_with(options) # rubocop:disable Metrics/MethodLength
|
55
|
-
collection_of_options << Servactory::Maintenance::Attributes::Option.new(
|
56
|
-
name: :consists_of,
|
33
|
+
def register_options(options:) # rubocop:disable Metrics/MethodLength
|
34
|
+
options_registrar = Servactory::Maintenance::Attributes::Options::Registrar.register(
|
57
35
|
attribute: self,
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
body_key: :type,
|
67
|
-
body_value: String,
|
68
|
-
body_fallback: String,
|
69
|
-
**options
|
36
|
+
collection_mode_class_names: @collection_mode_class_names,
|
37
|
+
hash_mode_class_names: @hash_mode_class_names,
|
38
|
+
options: options,
|
39
|
+
features: {
|
40
|
+
types: true,
|
41
|
+
collection: true,
|
42
|
+
hash: true
|
43
|
+
}
|
70
44
|
)
|
71
|
-
end
|
72
|
-
|
73
|
-
def add_hash_option_with(options) # rubocop:disable Metrics/MethodLength
|
74
|
-
collection_of_options << Servactory::Maintenance::Attributes::Option.new(
|
75
|
-
name: :schema,
|
76
|
-
attribute: self,
|
77
|
-
validation_class: Servactory::Inputs::Validations::Type,
|
78
|
-
define_methods: [
|
79
|
-
Servactory::Maintenance::Attributes::DefineMethod.new(
|
80
|
-
name: :hash_mode?,
|
81
|
-
content: ->(**) { hash_mode_class_names.include?(options.fetch(:type)) }
|
82
|
-
)
|
83
|
-
],
|
84
|
-
need_for_checks: false,
|
85
|
-
body_key: :is,
|
86
|
-
body_fallback: {},
|
87
|
-
**options
|
88
|
-
)
|
89
|
-
end
|
90
45
|
|
91
|
-
|
92
|
-
@collection_of_options ||= Servactory::Maintenance::Attributes::OptionsCollection.new
|
46
|
+
@collection_of_options = options_registrar.collection
|
93
47
|
end
|
94
48
|
|
95
49
|
def options_for_checks
|
96
|
-
collection_of_options.options_for_checks
|
50
|
+
@collection_of_options.options_for_checks
|
97
51
|
end
|
98
52
|
end
|
99
53
|
end
|
data/lib/servactory/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: servactory
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anton Sokolov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-12-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -277,6 +277,7 @@ files:
|
|
277
277
|
- lib/servactory/maintenance/attributes/option.rb
|
278
278
|
- lib/servactory/maintenance/attributes/option_helper.rb
|
279
279
|
- lib/servactory/maintenance/attributes/option_helpers_collection.rb
|
280
|
+
- lib/servactory/maintenance/attributes/options/registrar.rb
|
280
281
|
- lib/servactory/maintenance/attributes/options_collection.rb
|
281
282
|
- lib/servactory/maintenance/collection_mode/class_names_collection.rb
|
282
283
|
- lib/servactory/maintenance/hash_mode/class_names_collection.rb
|
@@ -318,7 +319,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
318
319
|
- !ruby/object:Gem::Version
|
319
320
|
version: '0'
|
320
321
|
requirements: []
|
321
|
-
rubygems_version: 3.
|
322
|
+
rubygems_version: 3.5.1
|
322
323
|
signing_key:
|
323
324
|
specification_version: 4
|
324
325
|
summary: A set of tools for building reliable services of any complexity
|