servactory 3.0.4 → 3.1.0.rc1
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/lib/servactory/actions/action.rb +2 -2
- data/lib/servactory/actions/collection.rb +1 -1
- data/lib/servactory/actions/stages/collection.rb +1 -1
- data/lib/servactory/configuration/config.rb +0 -16
- data/lib/servactory/configuration/configurable.rb +3 -6
- data/lib/servactory/configuration/hash_mode/class_names_collection.rb +1 -4
- data/lib/servactory/configuration/option_helpers/option_helpers_collection.rb +57 -8
- data/lib/servactory/context/warehouse/inputs.rb +28 -15
- data/lib/servactory/context/workspace/inputs.rb +27 -18
- data/lib/servactory/context/workspace/internals.rb +44 -27
- data/lib/servactory/context/workspace/outputs.rb +31 -23
- data/lib/servactory/dsl.rb +1 -1
- data/lib/servactory/info/builder.rb +2 -3
- data/lib/servactory/inputs/collection.rb +14 -21
- data/lib/servactory/inputs/input.rb +6 -103
- data/lib/servactory/inputs/tools/validation.rb +32 -57
- data/lib/servactory/inputs/validations/required.rb +3 -2
- data/lib/servactory/internals/collection.rb +5 -24
- data/lib/servactory/internals/internal.rb +4 -112
- data/lib/servactory/maintenance/attributes/base.rb +135 -0
- data/lib/servactory/maintenance/attributes/collection.rb +109 -0
- data/lib/servactory/maintenance/attributes/option_helper.rb +33 -12
- data/lib/servactory/maintenance/{attributes/options_collection.rb → options/collection.rb} +6 -7
- data/lib/servactory/maintenance/{attributes → options}/define_conflict.rb +1 -1
- data/lib/servactory/maintenance/{attributes → options}/define_method.rb +1 -1
- data/lib/servactory/maintenance/options/helper.rb +23 -0
- data/lib/servactory/maintenance/{attributes → options}/option.rb +50 -27
- data/lib/servactory/maintenance/options/registrar.rb +200 -0
- data/lib/servactory/maintenance/{attributes/validations → validations/checkers}/must.rb +25 -8
- data/lib/servactory/maintenance/{attributes/validations → validations/checkers}/type.rb +6 -5
- data/lib/servactory/maintenance/validations/concerns/error_builder.rb +50 -0
- data/lib/servactory/maintenance/validations/performer.rb +57 -0
- data/lib/servactory/maintenance/validations/support/type_validator.rb +36 -0
- data/lib/servactory/maintenance/{attributes → validations}/translator/must.rb +1 -1
- data/lib/servactory/maintenance/{attributes → validations}/translator/type.rb +1 -1
- data/lib/servactory/outputs/collection.rb +5 -24
- data/lib/servactory/outputs/output.rb +4 -112
- data/lib/servactory/result.rb +48 -39
- data/lib/servactory/tool_kit/dynamic_options/consists_of.rb +2 -4
- data/lib/servactory/tool_kit/dynamic_options/must.rb +2 -2
- data/lib/servactory/tool_kit/dynamic_options/schema.rb +7 -9
- data/lib/servactory/utils.rb +0 -8
- data/lib/servactory/version.rb +3 -3
- data/lib/servactory.rb +4 -0
- metadata +19 -22
- data/lib/servactory/maintenance/attributes/options/registrar.rb +0 -183
- data/lib/servactory/maintenance/attributes/tools/validation.rb +0 -84
- data/lib/servactory/maintenance/attributes/validations/concerns/error_builder.rb +0 -52
- data/lib/servactory/maintenance/validations/types.rb +0 -34
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: servactory
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.0.
|
|
4
|
+
version: 3.1.0.rc1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Anton Sokolov
|
|
@@ -43,20 +43,14 @@ dependencies:
|
|
|
43
43
|
requirements:
|
|
44
44
|
- - ">="
|
|
45
45
|
- !ruby/object:Gem::Version
|
|
46
|
-
version: '0.
|
|
47
|
-
- - "<"
|
|
48
|
-
- !ruby/object:Gem::Version
|
|
49
|
-
version: '1.0'
|
|
46
|
+
version: '0.4'
|
|
50
47
|
type: :runtime
|
|
51
48
|
prerelease: false
|
|
52
49
|
version_requirements: !ruby/object:Gem::Requirement
|
|
53
50
|
requirements:
|
|
54
51
|
- - ">="
|
|
55
52
|
- !ruby/object:Gem::Version
|
|
56
|
-
version: '0.
|
|
57
|
-
- - "<"
|
|
58
|
-
- !ruby/object:Gem::Version
|
|
59
|
-
version: '1.0'
|
|
53
|
+
version: '0.4'
|
|
60
54
|
- !ruby/object:Gem::Dependency
|
|
61
55
|
name: zeitwerk
|
|
62
56
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -270,19 +264,22 @@ files:
|
|
|
270
264
|
- lib/servactory/internals/collection.rb
|
|
271
265
|
- lib/servactory/internals/dsl.rb
|
|
272
266
|
- lib/servactory/internals/internal.rb
|
|
273
|
-
- lib/servactory/maintenance/attributes/
|
|
274
|
-
- lib/servactory/maintenance/attributes/
|
|
275
|
-
- lib/servactory/maintenance/attributes/option.rb
|
|
267
|
+
- lib/servactory/maintenance/attributes/base.rb
|
|
268
|
+
- lib/servactory/maintenance/attributes/collection.rb
|
|
276
269
|
- lib/servactory/maintenance/attributes/option_helper.rb
|
|
277
|
-
- lib/servactory/maintenance/
|
|
278
|
-
- lib/servactory/maintenance/
|
|
279
|
-
- lib/servactory/maintenance/
|
|
280
|
-
- lib/servactory/maintenance/
|
|
281
|
-
- lib/servactory/maintenance/
|
|
282
|
-
- lib/servactory/maintenance/
|
|
283
|
-
- lib/servactory/maintenance/
|
|
284
|
-
- lib/servactory/maintenance/
|
|
285
|
-
- lib/servactory/maintenance/validations/
|
|
270
|
+
- lib/servactory/maintenance/options/collection.rb
|
|
271
|
+
- lib/servactory/maintenance/options/define_conflict.rb
|
|
272
|
+
- lib/servactory/maintenance/options/define_method.rb
|
|
273
|
+
- lib/servactory/maintenance/options/helper.rb
|
|
274
|
+
- lib/servactory/maintenance/options/option.rb
|
|
275
|
+
- lib/servactory/maintenance/options/registrar.rb
|
|
276
|
+
- lib/servactory/maintenance/validations/checkers/must.rb
|
|
277
|
+
- lib/servactory/maintenance/validations/checkers/type.rb
|
|
278
|
+
- lib/servactory/maintenance/validations/concerns/error_builder.rb
|
|
279
|
+
- lib/servactory/maintenance/validations/performer.rb
|
|
280
|
+
- lib/servactory/maintenance/validations/support/type_validator.rb
|
|
281
|
+
- lib/servactory/maintenance/validations/translator/must.rb
|
|
282
|
+
- lib/servactory/maintenance/validations/translator/type.rb
|
|
286
283
|
- lib/servactory/outputs/collection.rb
|
|
287
284
|
- lib/servactory/outputs/dsl.rb
|
|
288
285
|
- lib/servactory/outputs/output.rb
|
|
@@ -360,7 +357,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
360
357
|
- !ruby/object:Gem::Version
|
|
361
358
|
version: '0'
|
|
362
359
|
requirements: []
|
|
363
|
-
rubygems_version: 4.0.
|
|
360
|
+
rubygems_version: 4.0.4
|
|
364
361
|
specification_version: 4
|
|
365
362
|
summary: A set of tools for building reliable services of any complexity
|
|
366
363
|
test_files: []
|
|
@@ -1,183 +0,0 @@
|
|
|
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
|
-
RESERVED_OPTIONS = %i[
|
|
9
|
-
type
|
|
10
|
-
required
|
|
11
|
-
default
|
|
12
|
-
collection
|
|
13
|
-
must
|
|
14
|
-
prepare
|
|
15
|
-
].freeze
|
|
16
|
-
|
|
17
|
-
DEFAULT_FEATURES = {
|
|
18
|
-
required: false,
|
|
19
|
-
types: false,
|
|
20
|
-
default: false,
|
|
21
|
-
must: false,
|
|
22
|
-
prepare: false
|
|
23
|
-
}.freeze
|
|
24
|
-
|
|
25
|
-
private_constant :DEFAULT_FEATURES
|
|
26
|
-
|
|
27
|
-
def self.register(...)
|
|
28
|
-
new(...).register
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def initialize(attribute:, options:, features:)
|
|
32
|
-
@attribute = attribute
|
|
33
|
-
@options = options
|
|
34
|
-
@features = DEFAULT_FEATURES.merge(features)
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
########################################################################
|
|
38
|
-
|
|
39
|
-
def register
|
|
40
|
-
register_feature(:required, Servactory::Inputs::Validations::Required)
|
|
41
|
-
register_feature(:types, Servactory::Maintenance::Attributes::Validations::Type)
|
|
42
|
-
register_feature(:default, Servactory::Maintenance::Attributes::Validations::Type)
|
|
43
|
-
register_feature(:must, Servactory::Maintenance::Attributes::Validations::Must)
|
|
44
|
-
register_feature(:prepare, nil)
|
|
45
|
-
|
|
46
|
-
self
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def collection
|
|
50
|
-
@collection ||= Servactory::Maintenance::Attributes::OptionsCollection.new
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
private
|
|
54
|
-
|
|
55
|
-
def register_feature(feature_name, validation_class)
|
|
56
|
-
return unless @features.fetch(feature_name)
|
|
57
|
-
|
|
58
|
-
method_name = "register_#{feature_name}_option"
|
|
59
|
-
send(method_name, validation_class)
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
########################################################################
|
|
63
|
-
|
|
64
|
-
def register_required_option(validation_class)
|
|
65
|
-
create_option(
|
|
66
|
-
name: :required,
|
|
67
|
-
validation_class:,
|
|
68
|
-
define_methods: required_define_methods,
|
|
69
|
-
define_conflicts: required_define_conflicts,
|
|
70
|
-
need_for_checks: true,
|
|
71
|
-
body_key: :is,
|
|
72
|
-
body_fallback: true
|
|
73
|
-
)
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
def register_types_option(validation_class)
|
|
77
|
-
create_option(
|
|
78
|
-
name: :types,
|
|
79
|
-
validation_class:,
|
|
80
|
-
original_value: Array(@options.fetch(:type)).uniq,
|
|
81
|
-
need_for_checks: true,
|
|
82
|
-
body_key: :is,
|
|
83
|
-
body_fallback: nil,
|
|
84
|
-
with_advanced_mode: false
|
|
85
|
-
)
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
def register_default_option(validation_class) # rubocop:disable Metrics/MethodLength
|
|
89
|
-
create_option(
|
|
90
|
-
name: :default,
|
|
91
|
-
validation_class:,
|
|
92
|
-
define_methods: [
|
|
93
|
-
create_define_method(
|
|
94
|
-
name: :default_value_present?,
|
|
95
|
-
content: ->(option:) { !option.nil? }
|
|
96
|
-
)
|
|
97
|
-
],
|
|
98
|
-
need_for_checks: true,
|
|
99
|
-
body_key: :is,
|
|
100
|
-
body_fallback: nil,
|
|
101
|
-
with_advanced_mode: false
|
|
102
|
-
)
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
def register_must_option(validation_class) # rubocop:disable Metrics/MethodLength
|
|
106
|
-
create_option(
|
|
107
|
-
name: :must,
|
|
108
|
-
validation_class:,
|
|
109
|
-
define_methods: [
|
|
110
|
-
create_define_method(
|
|
111
|
-
name: :must_present?,
|
|
112
|
-
content: ->(option:) { option.present? }
|
|
113
|
-
)
|
|
114
|
-
],
|
|
115
|
-
need_for_checks: true,
|
|
116
|
-
body_key: :is,
|
|
117
|
-
body_fallback: nil,
|
|
118
|
-
with_advanced_mode: false
|
|
119
|
-
)
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
def register_prepare_option(_validation_class) # rubocop:disable Metrics/MethodLength
|
|
123
|
-
create_option(
|
|
124
|
-
name: :prepare,
|
|
125
|
-
validation_class: nil,
|
|
126
|
-
define_methods: [
|
|
127
|
-
create_define_method(
|
|
128
|
-
name: :prepare_present?,
|
|
129
|
-
content: ->(option:) { option[:in].present? }
|
|
130
|
-
)
|
|
131
|
-
],
|
|
132
|
-
need_for_checks: false,
|
|
133
|
-
body_key: :in,
|
|
134
|
-
body_fallback: false
|
|
135
|
-
)
|
|
136
|
-
end
|
|
137
|
-
|
|
138
|
-
########################################################################
|
|
139
|
-
|
|
140
|
-
def required_define_methods
|
|
141
|
-
[
|
|
142
|
-
create_define_method(
|
|
143
|
-
name: :required?,
|
|
144
|
-
content: ->(option:) { Servactory::Utils.true?(option[:is]) }
|
|
145
|
-
),
|
|
146
|
-
create_define_method(
|
|
147
|
-
name: :optional?,
|
|
148
|
-
content: ->(option:) { !Servactory::Utils.true?(option[:is]) }
|
|
149
|
-
)
|
|
150
|
-
]
|
|
151
|
-
end
|
|
152
|
-
|
|
153
|
-
def required_define_conflicts
|
|
154
|
-
[
|
|
155
|
-
Servactory::Maintenance::Attributes::DefineConflict.new(
|
|
156
|
-
content: -> { :required_vs_default if @attribute.required? && @attribute.default_value_present? }
|
|
157
|
-
)
|
|
158
|
-
]
|
|
159
|
-
end
|
|
160
|
-
|
|
161
|
-
########################################################################
|
|
162
|
-
|
|
163
|
-
def create_option(name:, validation_class:, **options)
|
|
164
|
-
collection << Servactory::Maintenance::Attributes::Option.new(
|
|
165
|
-
name:,
|
|
166
|
-
attribute: @attribute,
|
|
167
|
-
validation_class:,
|
|
168
|
-
**options,
|
|
169
|
-
**@options
|
|
170
|
-
)
|
|
171
|
-
end
|
|
172
|
-
|
|
173
|
-
def create_define_method(name:, content:)
|
|
174
|
-
Servactory::Maintenance::Attributes::DefineMethod.new(
|
|
175
|
-
name:,
|
|
176
|
-
content:
|
|
177
|
-
)
|
|
178
|
-
end
|
|
179
|
-
end
|
|
180
|
-
end
|
|
181
|
-
end
|
|
182
|
-
end
|
|
183
|
-
end
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Servactory
|
|
4
|
-
module Maintenance
|
|
5
|
-
module Attributes
|
|
6
|
-
module Tools
|
|
7
|
-
class Validation
|
|
8
|
-
def self.validate!(...)
|
|
9
|
-
new(...).validate!
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def initialize(context:, attribute:, value:)
|
|
13
|
-
@context = context
|
|
14
|
-
@attribute = attribute
|
|
15
|
-
@value = value
|
|
16
|
-
@first_error = nil
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def validate!
|
|
20
|
-
process
|
|
21
|
-
|
|
22
|
-
raise_errors
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
private
|
|
26
|
-
|
|
27
|
-
def process
|
|
28
|
-
@attribute.options_for_checks.each do |check_key, check_options|
|
|
29
|
-
process_option(check_key, check_options)
|
|
30
|
-
break if @first_error.present?
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def process_option(check_key, check_options) # rubocop:disable Metrics/MethodLength
|
|
35
|
-
return if validation_classes.empty?
|
|
36
|
-
|
|
37
|
-
validation_classes.each do |validation_class|
|
|
38
|
-
error_message = process_validation_class(
|
|
39
|
-
validation_class:,
|
|
40
|
-
check_key:,
|
|
41
|
-
check_options:
|
|
42
|
-
)
|
|
43
|
-
|
|
44
|
-
next if error_message.blank?
|
|
45
|
-
|
|
46
|
-
@first_error = error_message
|
|
47
|
-
break
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
def process_validation_class(
|
|
52
|
-
validation_class:,
|
|
53
|
-
check_key:,
|
|
54
|
-
check_options:
|
|
55
|
-
)
|
|
56
|
-
validation_class.check(
|
|
57
|
-
context: @context,
|
|
58
|
-
attribute: @attribute,
|
|
59
|
-
value: @value,
|
|
60
|
-
check_key:,
|
|
61
|
-
check_options:
|
|
62
|
-
)
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
########################################################################
|
|
66
|
-
|
|
67
|
-
def validation_classes
|
|
68
|
-
@validation_classes ||= @attribute.collection_of_options.validation_classes
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
########################################################################
|
|
72
|
-
|
|
73
|
-
def raise_errors
|
|
74
|
-
return if @first_error.nil?
|
|
75
|
-
|
|
76
|
-
raise @context.config
|
|
77
|
-
.public_send(:"#{@attribute.system_name}_exception_class")
|
|
78
|
-
.new(context: @context, message: @first_error)
|
|
79
|
-
end
|
|
80
|
-
end
|
|
81
|
-
end
|
|
82
|
-
end
|
|
83
|
-
end
|
|
84
|
-
end
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Servactory
|
|
4
|
-
module Maintenance
|
|
5
|
-
module Attributes
|
|
6
|
-
module Validations
|
|
7
|
-
module Concerns
|
|
8
|
-
# Concern providing error message processing for validators.
|
|
9
|
-
#
|
|
10
|
-
# ## Purpose
|
|
11
|
-
#
|
|
12
|
-
# ErrorBuilder provides shared logic for processing error messages that
|
|
13
|
-
# can be either static strings or dynamic Procs. This allows validators
|
|
14
|
-
# to support both simple error messages and context-aware messages.
|
|
15
|
-
#
|
|
16
|
-
# ## Usage
|
|
17
|
-
#
|
|
18
|
-
# Extend in validator classes:
|
|
19
|
-
#
|
|
20
|
-
# ```ruby
|
|
21
|
-
# class MyValidator
|
|
22
|
-
# extend Concerns::ErrorBuilder
|
|
23
|
-
#
|
|
24
|
-
# def self.build_error(...)
|
|
25
|
-
# process_message(message, **context)
|
|
26
|
-
# end
|
|
27
|
-
# end
|
|
28
|
-
# ```
|
|
29
|
-
#
|
|
30
|
-
# ## Methods Provided
|
|
31
|
-
#
|
|
32
|
-
# - `process_message` - converts String or Proc message to String
|
|
33
|
-
module ErrorBuilder
|
|
34
|
-
# Processes a message that may be a String or Proc.
|
|
35
|
-
#
|
|
36
|
-
# If message is a Proc, calls it with the provided attributes.
|
|
37
|
-
# If message is a String, returns it unchanged.
|
|
38
|
-
#
|
|
39
|
-
# @param message [String, Proc] The message to process
|
|
40
|
-
# @param attributes [Hash] Attributes to pass to Proc if message is callable
|
|
41
|
-
# @return [String] The processed message string
|
|
42
|
-
def process_message(message, **attributes)
|
|
43
|
-
return message unless message.is_a?(Proc)
|
|
44
|
-
|
|
45
|
-
message.call(**attributes)
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
end
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Servactory
|
|
4
|
-
module Maintenance
|
|
5
|
-
module Validations
|
|
6
|
-
class Types
|
|
7
|
-
# Validates value against expected types.
|
|
8
|
-
#
|
|
9
|
-
# Returns nil on success, error data Hash on failure.
|
|
10
|
-
#
|
|
11
|
-
# @param context [Object] Service context for error info
|
|
12
|
-
# @param attribute [Inputs::Input, Internals::Internal, Outputs::Output] Attribute being validated
|
|
13
|
-
# @param types [Array<Class, String, Symbol>] Expected type classes
|
|
14
|
-
# @param value [Object] Value to validate
|
|
15
|
-
# @return [Hash, nil] nil on success, error data Hash on failure
|
|
16
|
-
def self.validate(context:, attribute:, types:, value:) # rubocop:disable Metrics/MethodLength
|
|
17
|
-
prepared_types = types.map { |type| Servactory::Utils.constantize_class(type) }
|
|
18
|
-
|
|
19
|
-
return if prepared_types.any? { |type| value.is_a?(type) }
|
|
20
|
-
|
|
21
|
-
{
|
|
22
|
-
message: Servactory::Maintenance::Attributes::Translator::Type.default_message,
|
|
23
|
-
service: context.send(:servactory_service_info),
|
|
24
|
-
attribute:,
|
|
25
|
-
value:,
|
|
26
|
-
key_name: nil,
|
|
27
|
-
expected_type: prepared_types.join(", "),
|
|
28
|
-
given_type: value.class.name
|
|
29
|
-
}
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
end
|