schema-model 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/schema/arrays.rb +20 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac8d34b4f4d5952110866c557221814712384996a670fd99cffd215d5c3c8c30
|
4
|
+
data.tar.gz: c3d2d96927c520546921ef1b407597141234cd31755f97766f5da3ccab2a8c2a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf04def96de8e9c386715936878c1eb38fdd4b730bf3abddd2693a9d4e1203b4e33708edb0edf0883115913b5e140cdbbb4f79b0413a1cd54e45a871cb9c562b
|
7
|
+
data.tar.gz: ef527623d46265a06dbd499cff99c68b06b2e7892906a314567769852c2e2723c245b897e415728a3909e6d2455da21b21f9971b5e065d4f8065e6a2079e09cd
|
data/lib/schema/arrays.rb
CHANGED
@@ -30,6 +30,26 @@ module Schema
|
|
30
30
|
end
|
31
31
|
data
|
32
32
|
end
|
33
|
+
|
34
|
+
def to_headers(prefix = nil)
|
35
|
+
headers = []
|
36
|
+
schema.each do |_, field_options|
|
37
|
+
next if field_options[:alias_of]
|
38
|
+
|
39
|
+
headers <<
|
40
|
+
case field_options[:type]
|
41
|
+
when :has_one
|
42
|
+
const_get(field_options[:class_name]).to_headers(prefix.to_s + field_options[:key] + '.')
|
43
|
+
when :has_many
|
44
|
+
field_options[:size].times.map do |i|
|
45
|
+
const_get(field_options[:class_name]).to_headers(prefix.to_s + field_options[:key] + "[#{i +1}].")
|
46
|
+
end
|
47
|
+
else
|
48
|
+
prefix.to_s + field_options[:key]
|
49
|
+
end
|
50
|
+
end
|
51
|
+
headers.flatten
|
52
|
+
end
|
33
53
|
end
|
34
54
|
|
35
55
|
def to_a
|