servactory 1.6.2 → 1.6.4
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/context/callable.rb +2 -2
- data/lib/servactory/context/workspace.rb +10 -8
- data/lib/servactory/inputs/input.rb +15 -15
- data/lib/servactory/inputs/option.rb +3 -3
- data/lib/servactory/inputs/options_collection.rb +2 -2
- data/lib/servactory/inputs/tools/find_unnecessary.rb +3 -3
- data/lib/servactory/inputs/tools/prepare.rb +5 -5
- data/lib/servactory/inputs/tools/rules.rb +3 -3
- data/lib/servactory/inputs/tools/{check.rb → validation.rb} +11 -11
- data/lib/servactory/inputs/{checks → validations}/base.rb +2 -4
- data/lib/servactory/inputs/{checks → validations}/errors.rb +1 -1
- data/lib/servactory/inputs/{checks → validations}/inclusion.rb +1 -1
- data/lib/servactory/inputs/{checks → validations}/must.rb +1 -1
- data/lib/servactory/inputs/{checks → validations}/required.rb +1 -1
- data/lib/servactory/inputs/{checks → validations}/type.rb +1 -1
- data/lib/servactory/inputs/workbench.rb +4 -4
- data/lib/servactory/internals/tools/prepare.rb +2 -2
- data/lib/servactory/internals/{checks → validations}/base.rb +1 -1
- data/lib/servactory/internals/{checks → validations}/type.rb +4 -4
- data/lib/servactory/methods/collection.rb +7 -3
- data/lib/servactory/methods/dsl.rb +10 -2
- data/lib/servactory/methods/method.rb +12 -2
- data/lib/servactory/methods/workbench.rb +16 -3
- data/lib/servactory/outputs/output.rb +1 -1
- data/lib/servactory/outputs/tools/conflicts.rb +3 -3
- data/lib/servactory/outputs/tools/prepare.rb +2 -2
- data/lib/servactory/outputs/{checks → validations}/base.rb +1 -1
- data/lib/servactory/outputs/{checks → validations}/type.rb +4 -4
- data/lib/servactory/outputs/workbench.rb +1 -1
- data/lib/servactory/utils.rb +1 -1
- data/lib/servactory/version.rb +1 -1
- metadata +13 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e8baf1ff3aab8a43c92e83987cb5f4cfbc426be9aacabf5fe63dd01e133c891e
|
4
|
+
data.tar.gz: 0af5e8fe8bf02fe5f15c68655e298b2d097b402764d231045683907afa35ded3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa8ffc01e6bab482d397f07e18847ec5d0b70bbd1e94bf7ff1ab6f080efca2502547ee92db3b663ba2bac15c2c6add762094ab37d9c47b73eb7b66f8f3ed9b10
|
7
|
+
data.tar.gz: a15fc2c38e21b6637ff5b9f1273006c0aae2dfe5d8d084390a18e2ce262329510fe80ab2bc16d47f18f3da8a40c5f5daea0533ad4b611a0e9ce8868eacf87b8f
|
@@ -16,7 +16,7 @@ module Servactory
|
|
16
16
|
|
17
17
|
prepare_data
|
18
18
|
|
19
|
-
inputs_workbench.
|
19
|
+
inputs_workbench.validate!
|
20
20
|
|
21
21
|
methods_workbench.run!
|
22
22
|
|
@@ -41,7 +41,7 @@ module Servactory
|
|
41
41
|
|
42
42
|
prepare_data
|
43
43
|
|
44
|
-
inputs_workbench.
|
44
|
+
inputs_workbench.validate!
|
45
45
|
|
46
46
|
methods_workbench.run!
|
47
47
|
|
@@ -3,8 +3,6 @@
|
|
3
3
|
module Servactory
|
4
4
|
module Context
|
5
5
|
module Workspace
|
6
|
-
attr_reader :inputs
|
7
|
-
|
8
6
|
def errors
|
9
7
|
@errors ||= Servactory::Errors::Collection.new
|
10
8
|
end
|
@@ -13,6 +11,16 @@ module Servactory
|
|
13
11
|
@inputs = inputs
|
14
12
|
end
|
15
13
|
|
14
|
+
def raise_first_fail
|
15
|
+
return if (tmp_errors = errors.for_fails.not_blank).empty?
|
16
|
+
|
17
|
+
raise tmp_errors.first
|
18
|
+
end
|
19
|
+
|
20
|
+
protected
|
21
|
+
|
22
|
+
attr_reader :inputs
|
23
|
+
|
16
24
|
def fail_input!(input_name, message:)
|
17
25
|
raise Servactory.configuration.input_error_class.new(
|
18
26
|
input_name: input_name,
|
@@ -23,12 +31,6 @@ module Servactory
|
|
23
31
|
def fail!(message:, meta: nil)
|
24
32
|
errors << Servactory.configuration.failure_class.new(message: message, meta: meta)
|
25
33
|
end
|
26
|
-
|
27
|
-
def raise_first_fail
|
28
|
-
return if (tmp_errors = errors.for_fails.not_blank).empty?
|
29
|
-
|
30
|
-
raise tmp_errors.first
|
31
|
-
end
|
32
34
|
end
|
33
35
|
end
|
34
36
|
end
|
@@ -29,18 +29,18 @@ module Servactory
|
|
29
29
|
# rubocop:enable Style/KeywordParametersOrder
|
30
30
|
|
31
31
|
def add_basic_options_with(type:, options:)
|
32
|
-
# Check Class: Servactory::Inputs::
|
32
|
+
# Check Class: Servactory::Inputs::Validations::Required
|
33
33
|
add_required_option_with(options)
|
34
34
|
|
35
|
-
# Check Class: Servactory::Inputs::
|
35
|
+
# Check Class: Servactory::Inputs::Validations::Type
|
36
36
|
add_types_option_with(type)
|
37
37
|
add_default_option_with(options)
|
38
38
|
add_array_option_with(options)
|
39
39
|
|
40
|
-
# Check Class: Servactory::Inputs::
|
40
|
+
# Check Class: Servactory::Inputs::Validations::Inclusion
|
41
41
|
add_inclusion_option_with(options)
|
42
42
|
|
43
|
-
# Check Class: Servactory::Inputs::
|
43
|
+
# Check Class: Servactory::Inputs::Validations::Must
|
44
44
|
add_must_option_with(options)
|
45
45
|
|
46
46
|
# Check Class: nil
|
@@ -51,15 +51,15 @@ module Servactory
|
|
51
51
|
collection_of_options << Option.new(
|
52
52
|
name: :required,
|
53
53
|
input: self,
|
54
|
-
|
54
|
+
validation_class: Servactory::Inputs::Validations::Required,
|
55
55
|
define_input_methods: [
|
56
56
|
DefineInputMethod.new(
|
57
57
|
name: :required?,
|
58
|
-
content: ->(value:) { Servactory::Utils.
|
58
|
+
content: ->(value:) { Servactory::Utils.true?(value[:is]) }
|
59
59
|
),
|
60
60
|
DefineInputMethod.new(
|
61
61
|
name: :optional?,
|
62
|
-
content: ->(value:) { !Servactory::Utils.
|
62
|
+
content: ->(value:) { !Servactory::Utils.true?(value[:is]) }
|
63
63
|
)
|
64
64
|
],
|
65
65
|
define_input_conflicts: [
|
@@ -76,7 +76,7 @@ module Servactory
|
|
76
76
|
collection_of_options << Option.new(
|
77
77
|
name: :types,
|
78
78
|
input: self,
|
79
|
-
|
79
|
+
validation_class: Servactory::Inputs::Validations::Type,
|
80
80
|
original_value: Array(type),
|
81
81
|
need_for_checks: true,
|
82
82
|
value_fallback: nil,
|
@@ -88,7 +88,7 @@ module Servactory
|
|
88
88
|
collection_of_options << Option.new(
|
89
89
|
name: :default,
|
90
90
|
input: self,
|
91
|
-
|
91
|
+
validation_class: Servactory::Inputs::Validations::Type,
|
92
92
|
define_input_methods: [
|
93
93
|
DefineInputMethod.new(
|
94
94
|
name: :default_value_present?,
|
@@ -106,11 +106,11 @@ module Servactory
|
|
106
106
|
collection_of_options << Option.new(
|
107
107
|
name: :array,
|
108
108
|
input: self,
|
109
|
-
|
109
|
+
validation_class: Servactory::Inputs::Validations::Type,
|
110
110
|
define_input_methods: [
|
111
111
|
DefineInputMethod.new(
|
112
112
|
name: :array?,
|
113
|
-
content: ->(value:) { Servactory::Utils.
|
113
|
+
content: ->(value:) { Servactory::Utils.true?(value[:is]) }
|
114
114
|
)
|
115
115
|
],
|
116
116
|
define_input_conflicts: [
|
@@ -128,7 +128,7 @@ module Servactory
|
|
128
128
|
collection_of_options << Option.new(
|
129
129
|
name: :inclusion,
|
130
130
|
input: self,
|
131
|
-
|
131
|
+
validation_class: Servactory::Inputs::Validations::Inclusion,
|
132
132
|
define_input_methods: [
|
133
133
|
DefineInputMethod.new(
|
134
134
|
name: :inclusion_present?,
|
@@ -146,7 +146,7 @@ module Servactory
|
|
146
146
|
collection_of_options << Option.new(
|
147
147
|
name: :must,
|
148
148
|
input: self,
|
149
|
-
|
149
|
+
validation_class: Servactory::Inputs::Validations::Must,
|
150
150
|
define_input_methods: [
|
151
151
|
DefineInputMethod.new(
|
152
152
|
name: :must_present?,
|
@@ -165,11 +165,11 @@ module Servactory
|
|
165
165
|
collection_of_options << Option.new(
|
166
166
|
name: :internal,
|
167
167
|
input: self,
|
168
|
-
|
168
|
+
validation_class: nil,
|
169
169
|
define_input_methods: [
|
170
170
|
DefineInputMethod.new(
|
171
171
|
name: :internal?,
|
172
|
-
content: ->(value:) { Servactory::Utils.
|
172
|
+
content: ->(value:) { Servactory::Utils.true?(value[:is]) }
|
173
173
|
)
|
174
174
|
],
|
175
175
|
need_for_checks: false,
|
@@ -8,7 +8,7 @@ module Servactory
|
|
8
8
|
private_constant :DEFAULT_VALUE
|
9
9
|
|
10
10
|
attr_reader :name,
|
11
|
-
:
|
11
|
+
:validation_class,
|
12
12
|
:define_input_methods,
|
13
13
|
:define_input_conflicts,
|
14
14
|
:need_for_checks,
|
@@ -19,7 +19,7 @@ module Servactory
|
|
19
19
|
def initialize(
|
20
20
|
name:,
|
21
21
|
input:,
|
22
|
-
|
22
|
+
validation_class:,
|
23
23
|
need_for_checks:,
|
24
24
|
value_fallback:,
|
25
25
|
original_value: nil,
|
@@ -30,7 +30,7 @@ module Servactory
|
|
30
30
|
**options
|
31
31
|
) # do
|
32
32
|
@name = name.to_sym
|
33
|
-
@
|
33
|
+
@validation_class = validation_class
|
34
34
|
@define_input_methods = define_input_methods
|
35
35
|
@define_input_conflicts = define_input_conflicts
|
36
36
|
@need_for_checks = need_for_checks
|
@@ -11,8 +11,8 @@ module Servactory
|
|
11
11
|
@collection = Set.new
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
15
|
-
filter { |option| option.
|
14
|
+
def validation_classes
|
15
|
+
filter { |option| option.validation_class.present? }.map(&:validation_class).uniq
|
16
16
|
end
|
17
17
|
|
18
18
|
def options_for_checks
|
@@ -4,8 +4,8 @@ module Servactory
|
|
4
4
|
module Inputs
|
5
5
|
module Tools
|
6
6
|
class FindUnnecessary
|
7
|
-
def self.
|
8
|
-
new(...).
|
7
|
+
def self.validate!(...)
|
8
|
+
new(...).validate!
|
9
9
|
end
|
10
10
|
|
11
11
|
def initialize(context, incoming_arguments, collection_of_inputs)
|
@@ -14,7 +14,7 @@ module Servactory
|
|
14
14
|
@collection_of_inputs = collection_of_inputs
|
15
15
|
end
|
16
16
|
|
17
|
-
def
|
17
|
+
def validate!
|
18
18
|
return if unnecessary_attributes.empty?
|
19
19
|
|
20
20
|
message_text = I18n.t(
|
@@ -31,11 +31,11 @@ module Servactory
|
|
31
31
|
input_value = @incoming_arguments.fetch(input.name, nil)
|
32
32
|
input_value = input.default if input.optional? && input_value.blank?
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
34
|
+
if input.internal?
|
35
|
+
@internal_variables[input.name] = input_value
|
36
|
+
else
|
37
|
+
@inputs_variables[input.internal_name] = input_value
|
38
|
+
end
|
39
39
|
end
|
40
40
|
|
41
41
|
def create_instance_variables
|
@@ -4,8 +4,8 @@ module Servactory
|
|
4
4
|
module Inputs
|
5
5
|
module Tools
|
6
6
|
class Rules
|
7
|
-
def self.
|
8
|
-
new(...).
|
7
|
+
def self.validate!(...)
|
8
|
+
new(...).validate!
|
9
9
|
end
|
10
10
|
|
11
11
|
def initialize(context, collection_of_inputs)
|
@@ -13,7 +13,7 @@ module Servactory
|
|
13
13
|
@collection_of_inputs = collection_of_inputs
|
14
14
|
end
|
15
15
|
|
16
|
-
def
|
16
|
+
def validate!
|
17
17
|
@collection_of_inputs.each do |input|
|
18
18
|
check_for!(input)
|
19
19
|
end
|
@@ -3,9 +3,9 @@
|
|
3
3
|
module Servactory
|
4
4
|
module Inputs
|
5
5
|
module Tools
|
6
|
-
class
|
7
|
-
def self.
|
8
|
-
new(...).
|
6
|
+
class Validation
|
7
|
+
def self.validate!(...)
|
8
|
+
new(...).validate!
|
9
9
|
end
|
10
10
|
|
11
11
|
def initialize(context, incoming_arguments, collection_of_inputs)
|
@@ -14,7 +14,7 @@ module Servactory
|
|
14
14
|
@collection_of_inputs = collection_of_inputs
|
15
15
|
end
|
16
16
|
|
17
|
-
def
|
17
|
+
def validate!
|
18
18
|
@collection_of_inputs.each do |input|
|
19
19
|
process_input(input)
|
20
20
|
end
|
@@ -31,9 +31,9 @@ module Servactory
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def process_option(check_key, check_options, input:)
|
34
|
-
|
35
|
-
errors_from_checks =
|
36
|
-
|
34
|
+
validation_classes_from(input).each do |validation_class|
|
35
|
+
errors_from_checks = process_validation_classes(
|
36
|
+
validation_class,
|
37
37
|
input: input,
|
38
38
|
check_key: check_key,
|
39
39
|
check_options: check_options
|
@@ -43,8 +43,8 @@ module Servactory
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
-
def
|
47
|
-
|
46
|
+
def process_validation_classes(validation_class, input:, check_key:, check_options:)
|
47
|
+
validation_class.check(
|
48
48
|
context: @context,
|
49
49
|
input: input,
|
50
50
|
value: @incoming_arguments.fetch(input.name, nil),
|
@@ -55,8 +55,8 @@ module Servactory
|
|
55
55
|
|
56
56
|
########################################################################
|
57
57
|
|
58
|
-
def
|
59
|
-
input.collection_of_options.
|
58
|
+
def validation_classes_from(input)
|
59
|
+
input.collection_of_options.validation_classes
|
60
60
|
end
|
61
61
|
|
62
62
|
########################################################################
|
@@ -2,9 +2,9 @@
|
|
2
2
|
|
3
3
|
module Servactory
|
4
4
|
module Inputs
|
5
|
-
module
|
5
|
+
module Validations
|
6
6
|
class Base
|
7
|
-
|
7
|
+
private
|
8
8
|
|
9
9
|
def add_error(message, **attributes)
|
10
10
|
message = message.call(**attributes) if message.is_a?(Proc)
|
@@ -12,8 +12,6 @@ module Servactory
|
|
12
12
|
errors << message
|
13
13
|
end
|
14
14
|
|
15
|
-
private
|
16
|
-
|
17
15
|
def errors
|
18
16
|
@errors ||= Errors.new
|
19
17
|
end
|
@@ -17,19 +17,19 @@ module Servactory
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def find_unnecessary!
|
20
|
-
Tools::FindUnnecessary.
|
20
|
+
Tools::FindUnnecessary.validate!(context, @incoming_arguments, collection_of_inputs)
|
21
21
|
end
|
22
22
|
|
23
23
|
def check_rules!
|
24
|
-
Tools::Rules.
|
24
|
+
Tools::Rules.validate!(context, collection_of_inputs)
|
25
25
|
end
|
26
26
|
|
27
27
|
def prepare
|
28
28
|
Tools::Prepare.prepare(context, @incoming_arguments, collection_of_inputs)
|
29
29
|
end
|
30
30
|
|
31
|
-
def
|
32
|
-
Tools::
|
31
|
+
def validate!
|
32
|
+
Tools::Validation.validate!(context, @incoming_arguments, collection_of_inputs)
|
33
33
|
end
|
34
34
|
|
35
35
|
private
|
@@ -30,7 +30,7 @@ module Servactory
|
|
30
30
|
# EXAMPLE:
|
31
31
|
#
|
32
32
|
# define_method(:user=) do |value|
|
33
|
-
# Servactory::Internals::
|
33
|
+
# Servactory::Internals::Validations::Type.validate!( context: self, internal:, value: )
|
34
34
|
#
|
35
35
|
# instance_variable_set(:@user, value)
|
36
36
|
# end
|
@@ -40,7 +40,7 @@ module Servactory
|
|
40
40
|
def context_internal_template_for(internal)
|
41
41
|
<<-RUBY
|
42
42
|
define_method(:#{internal.name}=) do |value|
|
43
|
-
Servactory::Internals::
|
43
|
+
Servactory::Internals::Validations::Type.validate!(
|
44
44
|
context: self,
|
45
45
|
internal: internal,
|
46
46
|
value: value
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module Servactory
|
4
4
|
module Internals
|
5
|
-
module
|
5
|
+
module Validations
|
6
6
|
class Type < Base
|
7
7
|
DEFAULT_MESSAGE = lambda do |service_class_name:, internal:, expected_type:, given_type:|
|
8
8
|
I18n.t(
|
@@ -16,8 +16,8 @@ module Servactory
|
|
16
16
|
|
17
17
|
private_constant :DEFAULT_MESSAGE
|
18
18
|
|
19
|
-
def self.
|
20
|
-
new(...).
|
19
|
+
def self.validate!(...)
|
20
|
+
new(...).validate!
|
21
21
|
end
|
22
22
|
|
23
23
|
##########################################################################
|
@@ -30,7 +30,7 @@ module Servactory
|
|
30
30
|
@value = value
|
31
31
|
end
|
32
32
|
|
33
|
-
def
|
33
|
+
def validate!
|
34
34
|
return if prepared_types.any? { |type| @value.is_a?(type) }
|
35
35
|
|
36
36
|
raise_error_with(
|
@@ -5,10 +5,14 @@ module Servactory
|
|
5
5
|
class Collection
|
6
6
|
# NOTE: http://words.steveklabnik.com/beware-subclassing-ruby-core-classes
|
7
7
|
extend Forwardable
|
8
|
-
def_delegators :@collection, :<<, :each, :merge
|
8
|
+
def_delegators :@collection, :<<, :each, :merge, :sort_by, :size, :empty?
|
9
9
|
|
10
|
-
def initialize(
|
11
|
-
@collection =
|
10
|
+
def initialize(collection = Set.new)
|
11
|
+
@collection = collection
|
12
|
+
end
|
13
|
+
|
14
|
+
def sorted_by_position
|
15
|
+
Collection.new(sort_by(&:position))
|
12
16
|
end
|
13
17
|
end
|
14
18
|
end
|
@@ -16,8 +16,12 @@ module Servactory
|
|
16
16
|
|
17
17
|
private
|
18
18
|
|
19
|
-
def make(name, **options)
|
20
|
-
collection_of_methods << Method.new(
|
19
|
+
def make(name, position: nil, **options)
|
20
|
+
collection_of_methods << Method.new(
|
21
|
+
name,
|
22
|
+
position: position.presence || next_position,
|
23
|
+
**options
|
24
|
+
)
|
21
25
|
end
|
22
26
|
|
23
27
|
def method_missing(shortcut_name, *args, &block)
|
@@ -34,6 +38,10 @@ module Servactory
|
|
34
38
|
Servactory.configuration.method_shortcuts.include?(shortcut_name) || super
|
35
39
|
end
|
36
40
|
|
41
|
+
def next_position
|
42
|
+
collection_of_methods.size + 1
|
43
|
+
end
|
44
|
+
|
37
45
|
def collection_of_methods
|
38
46
|
@collection_of_methods ||= Collection.new
|
39
47
|
end
|
@@ -4,12 +4,22 @@ module Servactory
|
|
4
4
|
module Methods
|
5
5
|
class Method
|
6
6
|
attr_reader :name,
|
7
|
-
:
|
7
|
+
:position,
|
8
|
+
:condition,
|
9
|
+
:is_condition_opposite
|
8
10
|
|
9
|
-
def initialize(name, **options)
|
11
|
+
def initialize(name, position:, **options)
|
10
12
|
@name = name
|
13
|
+
@position = position
|
11
14
|
|
15
|
+
@is_condition_opposite = false
|
12
16
|
@condition = options.fetch(:if, nil)
|
17
|
+
|
18
|
+
return unless @condition.nil?
|
19
|
+
|
20
|
+
@condition = options.fetch(:unless, nil)
|
21
|
+
|
22
|
+
@is_condition_opposite = true unless @condition.nil?
|
13
23
|
end
|
14
24
|
end
|
15
25
|
end
|
@@ -16,7 +16,9 @@ module Servactory
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def run!
|
19
|
-
collection_of_methods.
|
19
|
+
return try_to_use_call if collection_of_methods.empty?
|
20
|
+
|
21
|
+
collection_of_methods.sorted_by_position.each do |make_method|
|
20
22
|
next if unnecessary_for?(make_method)
|
21
23
|
|
22
24
|
context.send(make_method.name)
|
@@ -28,11 +30,22 @@ module Servactory
|
|
28
30
|
attr_reader :context,
|
29
31
|
:collection_of_methods
|
30
32
|
|
33
|
+
def try_to_use_call
|
34
|
+
context.try(:send, :call)
|
35
|
+
end
|
36
|
+
|
31
37
|
def unnecessary_for?(make_method)
|
32
38
|
condition = make_method.condition
|
39
|
+
is_condition_opposite = make_method.is_condition_opposite
|
40
|
+
|
41
|
+
result = prepare_condition_for(condition)
|
42
|
+
|
43
|
+
is_condition_opposite ? !result : result
|
44
|
+
end
|
33
45
|
|
34
|
-
|
35
|
-
return
|
46
|
+
def prepare_condition_for(condition)
|
47
|
+
return false if condition.nil?
|
48
|
+
return !Servactory::Utils.true?(condition) unless condition.is_a?(Proc)
|
36
49
|
|
37
50
|
!condition.call(context: context)
|
38
51
|
end
|
@@ -4,8 +4,8 @@ module Servactory
|
|
4
4
|
module Outputs
|
5
5
|
module Tools
|
6
6
|
class Conflicts
|
7
|
-
def self.
|
8
|
-
new(...).
|
7
|
+
def self.validate!(...)
|
8
|
+
new(...).validate!
|
9
9
|
end
|
10
10
|
|
11
11
|
def initialize(context, collection_of_outputs, collection_of_internals)
|
@@ -14,7 +14,7 @@ module Servactory
|
|
14
14
|
@collection_of_internals = collection_of_internals
|
15
15
|
end
|
16
16
|
|
17
|
-
def
|
17
|
+
def validate!
|
18
18
|
return if overlapping_attributes.empty?
|
19
19
|
|
20
20
|
message_text = I18n.t(
|
@@ -30,7 +30,7 @@ module Servactory
|
|
30
30
|
# EXAMPLE:
|
31
31
|
#
|
32
32
|
# define_method(:user=) do |value|
|
33
|
-
# Servactory::Internals::
|
33
|
+
# Servactory::Internals::Validations::Type.validate!( context: self, output:, value: )
|
34
34
|
#
|
35
35
|
# instance_variable_set(:@user, value)
|
36
36
|
# end
|
@@ -42,7 +42,7 @@ module Servactory
|
|
42
42
|
def context_output_template_for(output)
|
43
43
|
<<-RUBY
|
44
44
|
define_method(:#{output.name}=) do |value|
|
45
|
-
Servactory::Outputs::
|
45
|
+
Servactory::Outputs::Validations::Type.validate!(
|
46
46
|
context: self,
|
47
47
|
output: output,
|
48
48
|
value: value
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module Servactory
|
4
4
|
module Outputs
|
5
|
-
module
|
5
|
+
module Validations
|
6
6
|
class Type < Base
|
7
7
|
DEFAULT_MESSAGE = lambda do |service_class_name:, output:, expected_type:, given_type:|
|
8
8
|
I18n.t(
|
@@ -16,8 +16,8 @@ module Servactory
|
|
16
16
|
|
17
17
|
private_constant :DEFAULT_MESSAGE
|
18
18
|
|
19
|
-
def self.
|
20
|
-
new(...).
|
19
|
+
def self.validate!(...)
|
20
|
+
new(...).validate!
|
21
21
|
end
|
22
22
|
|
23
23
|
##########################################################################
|
@@ -30,7 +30,7 @@ module Servactory
|
|
30
30
|
@value = value
|
31
31
|
end
|
32
32
|
|
33
|
-
def
|
33
|
+
def validate!
|
34
34
|
return if prepared_types.any? { |type| @value.is_a?(type) }
|
35
35
|
|
36
36
|
raise_error_with(
|
@@ -16,7 +16,7 @@ module Servactory
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def find_conflicts_in!(collection_of_internals:)
|
19
|
-
Tools::Conflicts.
|
19
|
+
Tools::Conflicts.validate!(context, collection_of_outputs, collection_of_internals)
|
20
20
|
end
|
21
21
|
|
22
22
|
def prepare
|
data/lib/servactory/utils.rb
CHANGED
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: 1.6.
|
4
|
+
version: 1.6.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-06-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -205,12 +205,6 @@ files:
|
|
205
205
|
- lib/servactory/errors/input_error.rb
|
206
206
|
- lib/servactory/errors/internal_error.rb
|
207
207
|
- lib/servactory/errors/output_error.rb
|
208
|
-
- lib/servactory/inputs/checks/base.rb
|
209
|
-
- lib/servactory/inputs/checks/errors.rb
|
210
|
-
- lib/servactory/inputs/checks/inclusion.rb
|
211
|
-
- lib/servactory/inputs/checks/must.rb
|
212
|
-
- lib/servactory/inputs/checks/required.rb
|
213
|
-
- lib/servactory/inputs/checks/type.rb
|
214
208
|
- lib/servactory/inputs/collection.rb
|
215
209
|
- lib/servactory/inputs/define_input_conflict.rb
|
216
210
|
- lib/servactory/inputs/define_input_method.rb
|
@@ -218,31 +212,37 @@ files:
|
|
218
212
|
- lib/servactory/inputs/input.rb
|
219
213
|
- lib/servactory/inputs/option.rb
|
220
214
|
- lib/servactory/inputs/options_collection.rb
|
221
|
-
- lib/servactory/inputs/tools/check.rb
|
222
215
|
- lib/servactory/inputs/tools/check_errors.rb
|
223
216
|
- lib/servactory/inputs/tools/find_unnecessary.rb
|
224
217
|
- lib/servactory/inputs/tools/prepare.rb
|
225
218
|
- lib/servactory/inputs/tools/rules.rb
|
219
|
+
- lib/servactory/inputs/tools/validation.rb
|
220
|
+
- lib/servactory/inputs/validations/base.rb
|
221
|
+
- lib/servactory/inputs/validations/errors.rb
|
222
|
+
- lib/servactory/inputs/validations/inclusion.rb
|
223
|
+
- lib/servactory/inputs/validations/must.rb
|
224
|
+
- lib/servactory/inputs/validations/required.rb
|
225
|
+
- lib/servactory/inputs/validations/type.rb
|
226
226
|
- lib/servactory/inputs/workbench.rb
|
227
|
-
- lib/servactory/internals/checks/base.rb
|
228
|
-
- lib/servactory/internals/checks/type.rb
|
229
227
|
- lib/servactory/internals/collection.rb
|
230
228
|
- lib/servactory/internals/dsl.rb
|
231
229
|
- lib/servactory/internals/internal.rb
|
232
230
|
- lib/servactory/internals/tools/prepare.rb
|
231
|
+
- lib/servactory/internals/validations/base.rb
|
232
|
+
- lib/servactory/internals/validations/type.rb
|
233
233
|
- lib/servactory/internals/workbench.rb
|
234
234
|
- lib/servactory/methods/collection.rb
|
235
235
|
- lib/servactory/methods/dsl.rb
|
236
236
|
- lib/servactory/methods/method.rb
|
237
237
|
- lib/servactory/methods/shortcuts/collection.rb
|
238
238
|
- lib/servactory/methods/workbench.rb
|
239
|
-
- lib/servactory/outputs/checks/base.rb
|
240
|
-
- lib/servactory/outputs/checks/type.rb
|
241
239
|
- lib/servactory/outputs/collection.rb
|
242
240
|
- lib/servactory/outputs/dsl.rb
|
243
241
|
- lib/servactory/outputs/output.rb
|
244
242
|
- lib/servactory/outputs/tools/conflicts.rb
|
245
243
|
- lib/servactory/outputs/tools/prepare.rb
|
244
|
+
- lib/servactory/outputs/validations/base.rb
|
245
|
+
- lib/servactory/outputs/validations/type.rb
|
246
246
|
- lib/servactory/outputs/workbench.rb
|
247
247
|
- lib/servactory/result.rb
|
248
248
|
- lib/servactory/utils.rb
|