servactory 2.0.1 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c804a894a51f06d11d05d6b60e539d2d1540959312330726010327dab9a40ed
|
4
|
+
data.tar.gz: ab85a273c813f528a596d79efe571d3916f694b1daff5d556d652f28dcab2c98
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a47f20f6976c843de99822ae9b7cd0ba17a9fc59e0d940776f8a2fe66f9145668507ba4bddb21c8a994994eab765d49f0ee656156aa4394e69c768ec831eff60
|
7
|
+
data.tar.gz: 8141c47cd8912dccc02c354cb8c8fa9026238b4c4867de25e1f32c2998aaaf2eb6e4c0ff35e765fced2d585b99f0e458993ac9dfa473674cc07007d2b2ea4033
|
@@ -40,7 +40,8 @@ module Servactory
|
|
40
40
|
|
41
41
|
private
|
42
42
|
|
43
|
-
|
43
|
+
# rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Lint/UnusedMethodArgument
|
44
|
+
def getter_with(name:, &block)
|
44
45
|
input_name = name.to_s.chomp("?").to_sym
|
45
46
|
input = @collection_of_inputs.find_by(name: input_name)
|
46
47
|
|
@@ -61,6 +62,7 @@ module Servactory
|
|
61
62
|
input.value
|
62
63
|
end
|
63
64
|
end
|
65
|
+
# rubocop:enable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Lint/UnusedMethodArgument
|
64
66
|
|
65
67
|
def prepare_hash_values_inside(object:, schema:) # rubocop:disable Metrics/MethodLength
|
66
68
|
return object unless object.respond_to?(:fetch)
|
@@ -10,10 +10,10 @@ module Servactory
|
|
10
10
|
new(...).validate
|
11
11
|
end
|
12
12
|
|
13
|
-
def initialize(
|
14
|
-
@
|
13
|
+
def initialize(attribute:, types:, value:)
|
14
|
+
@attribute = attribute
|
15
15
|
@types = types
|
16
|
-
@
|
16
|
+
@value = value
|
17
17
|
|
18
18
|
@errors = []
|
19
19
|
end
|
@@ -39,21 +39,41 @@ module Servactory
|
|
39
39
|
|
40
40
|
private
|
41
41
|
|
42
|
+
def validate_value!
|
43
|
+
return if unnecessary_types.empty?
|
44
|
+
|
45
|
+
add_error(
|
46
|
+
expected_type: attribute_consists_of_types.join(", "),
|
47
|
+
given_type: unnecessary_types.join(", ")
|
48
|
+
)
|
49
|
+
end
|
50
|
+
|
51
|
+
########################################################################
|
52
|
+
|
42
53
|
def prepared_type
|
43
54
|
@prepared_type ||= @types.fetch(0, Array)
|
44
55
|
end
|
45
56
|
|
46
|
-
def
|
47
|
-
@
|
48
|
-
|
57
|
+
def attribute_consists_of_types
|
58
|
+
@attribute_consists_of_types ||= prepared_types_from(Array(@attribute.consists_of.fetch(:type, [])))
|
59
|
+
end
|
49
60
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
61
|
+
def unnecessary_types
|
62
|
+
@unnecessary_types ||= @value&.map(&:class)&.difference(attribute_consists_of_types).presence || []
|
63
|
+
end
|
64
|
+
|
65
|
+
def prepared_types_from(types)
|
66
|
+
types.map do |type|
|
67
|
+
if type.is_a?(String)
|
68
|
+
Object.const_get(type)
|
69
|
+
else
|
70
|
+
type
|
71
|
+
end
|
54
72
|
end
|
55
73
|
end
|
56
74
|
|
75
|
+
########################################################################
|
76
|
+
|
57
77
|
def add_error(expected_type:, given_type:)
|
58
78
|
@errors << {
|
59
79
|
expected_type: expected_type,
|
@@ -92,23 +92,23 @@ module Servactory
|
|
92
92
|
collection_validator = nil
|
93
93
|
object_schema_validator = nil
|
94
94
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
)
|
95
|
+
if @attribute.collection_mode?
|
96
|
+
collection_validator = Servactory::Maintenance::Validations::Collection.validate(
|
97
|
+
attribute: @attribute,
|
98
|
+
types: @types,
|
99
|
+
value: @value
|
100
|
+
)
|
102
101
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
102
|
+
return if collection_validator.valid?
|
103
|
+
elsif @attribute.hash_mode?
|
104
|
+
object_schema_validator = Servactory::Maintenance::Validations::ObjectSchema.validate(
|
105
|
+
object: @value,
|
106
|
+
schema: @attribute.schema
|
107
|
+
)
|
109
108
|
|
110
|
-
|
111
|
-
|
109
|
+
return if object_schema_validator.valid?
|
110
|
+
else
|
111
|
+
return if prepared_types.any? do |type| # rubocop:disable Style/IfInsideElse
|
112
112
|
@value.is_a?(type)
|
113
113
|
end
|
114
114
|
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.2
|
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-
|
11
|
+
date: 2023-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|