schema-model 0.3.2 → 0.3.5
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da011575b9914ac318fbb72560445ea592d6a90ae38cb585938875545623e0e1
|
4
|
+
data.tar.gz: 79a01b51f835ce95c06ab76455c6b003195b594320b847ce2c86f65654e7ea23
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c2ee95f2602f4217373b1f65ecbfd8f6f16c39e0cc1d3627f60b34340ba67071b120a336a96017ff2f219a854aca6dcd243fa6dc759a79d223922b10035287f5
|
7
|
+
data.tar.gz: 9b3a13a9c2e825a47f76b82f19942703be354d5c8ae912d4f1c2b44e9a5f31f3e9134b6df509531be5113ae75eacdf7a225007cbeead2992404f1b442e302d1a
|
@@ -58,7 +58,13 @@ module Schema
|
|
58
58
|
name = name.downcase if @ignorecase
|
59
59
|
return base_schema.class.const_get(class_name) if name == type
|
60
60
|
end
|
61
|
-
|
61
|
+
get_default_dynamic_schema_class(base_schema)
|
62
|
+
end
|
63
|
+
|
64
|
+
def get_default_dynamic_schema_class(base_schema)
|
65
|
+
return unless (class_name = @types[:default])
|
66
|
+
|
67
|
+
base_schema.class.const_get(class_name)
|
62
68
|
end
|
63
69
|
|
64
70
|
def get_dynamic_type(base_schema, data)
|
data/lib/schema/parsers/array.rb
CHANGED
@@ -7,7 +7,8 @@ module Schema
|
|
7
7
|
def parse_array(field_name, parsing_errors, value)
|
8
8
|
case value
|
9
9
|
when ::Array
|
10
|
-
|
10
|
+
schema_options = self.class.schema[field_name]
|
11
|
+
Array.convert_array_values(self, field_name, parsing_errors, value, schema_options)
|
11
12
|
when String
|
12
13
|
schema_options = self.class.schema[field_name]
|
13
14
|
if (data = Array.parse_string_array(self, field_name, parsing_errors, value, schema_options))
|
data/lib/schema_validator.rb
CHANGED
@@ -3,6 +3,20 @@
|
|
3
3
|
# SchemaValidator validates nested schemas
|
4
4
|
class SchemaValidator < ActiveModel::EachValidator
|
5
5
|
def validate_each(record, attribute, value)
|
6
|
-
record.errors.add(attribute, options.fetch(:message, :invalid))
|
6
|
+
record.errors.add(attribute, options.fetch(:message, :invalid)) unless valid_schema?(value)
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def valid_schema?(value)
|
12
|
+
return true unless value
|
13
|
+
|
14
|
+
if value.is_a?(Array)
|
15
|
+
value.all? do |schema|
|
16
|
+
!schema || schema.valid?
|
17
|
+
end
|
18
|
+
else
|
19
|
+
value.valid?
|
20
|
+
end
|
7
21
|
end
|
8
22
|
end
|