schema_serializer 0.2.3 → 0.2.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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7914525cee8225376bf03508351a44a4390e902b632f79bebfe02090360edabb
|
4
|
+
data.tar.gz: b1f3ecc4f8def7a57328f07ae27ecb1aef9bf4978d303e32548e9e3e87fa001f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 55fae4ec059c7678f7bafbe0e6587b6364c9399ffb116a95338dc90a7438a4cfc7b83d5437d7b95a8b125b17d1abe88c85f674cd173b6e79dbe473ea00415842
|
7
|
+
data.tar.gz: c7cc06fb4ac73182796ac6c953ef8f5516db39cb67733d3332bc35c6663882954b1659cd4790811f88f80271adf6977d1b1b484a5ee79bf86812eb1f7dfbd80f
|
@@ -9,11 +9,11 @@ class SchemaSerializer
|
|
9
9
|
|
10
10
|
case type
|
11
11
|
when "array"
|
12
|
-
@items = self.class.new(hash.fetch("items"))
|
12
|
+
@items = self.class.new(@key, hash.fetch("items"))
|
13
13
|
when "object", nil
|
14
14
|
@required = hash["required"] || []
|
15
15
|
@properties = hash.fetch("properties").each_with_object({}) { |(column, property), obj|
|
16
|
-
obj[column] = self.class.new(property)
|
16
|
+
obj[column] = self.class.new(column, property)
|
17
17
|
}
|
18
18
|
end
|
19
19
|
end
|
@@ -34,8 +34,19 @@ class SchemaSerializer
|
|
34
34
|
when "boolean"
|
35
35
|
!!object
|
36
36
|
when "array"
|
37
|
-
object
|
37
|
+
serialize_array(object)
|
38
38
|
else
|
39
|
+
serialize_object(object)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def serialize_array(object)
|
46
|
+
object.map { |item| items.serialize(item) }
|
47
|
+
end
|
48
|
+
|
49
|
+
def serialize_object(object)
|
39
50
|
not_enough_columns = required - properties.keys
|
40
51
|
raise RequiredNotDefined, not_enough_columns.join(", ") unless not_enough_columns.empty?
|
41
52
|
|
@@ -43,9 +54,6 @@ class SchemaSerializer
|
|
43
54
|
obj[column] = schema.serialize(get_value(object, column))
|
44
55
|
}
|
45
56
|
end
|
46
|
-
end
|
47
|
-
|
48
|
-
private
|
49
57
|
|
50
58
|
def get_value(object, column)
|
51
59
|
return object[column] || object[column.to_sym] if object.is_a?(Hash)
|