schema-model 0.5.0 → 0.5.1
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 +41 -0
- data/lib/schema/csv_parser.rb +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e57c8c78613d7ee20ab7f3e6a47cada9bdead12040f43d54932bcda82f0d6935
|
4
|
+
data.tar.gz: d16c1a6a36b4ba287afeb2c7bd961a26475dcdffa7be46edca5f1dce85ea63dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb6bca0570036457fea00cd3f09bd1775564a71844442cd13d6ed2ff9daac848b92e84c652205de897a68c7cf587c676805210edef0ff1a4aa5e9d8667c95a3c
|
7
|
+
data.tar.gz: 636b52ac448af439b79a9f64132fd85509433a6f65b426627a1f06930c498f2ea9da89353a9294a078142ebae1213468a70fbfe28a5f9bd8bbe0d4c2301486a2
|
data/lib/schema/arrays.rb
CHANGED
@@ -12,6 +12,47 @@ module Schema
|
|
12
12
|
def from_array(array, mapped_headers)
|
13
13
|
new.update_attributes_with_array(array, mapped_headers)
|
14
14
|
end
|
15
|
+
|
16
|
+
def to_empty_array
|
17
|
+
data = []
|
18
|
+
schema.each do |_, field_options|
|
19
|
+
next if field_options[:alias_of]
|
20
|
+
|
21
|
+
data <<
|
22
|
+
case field_options[:type]
|
23
|
+
when :has_one
|
24
|
+
const_get(field_options[:class_name]).to_empty_array
|
25
|
+
when :has_many
|
26
|
+
field_options[:size].times.map { const_get(field_options[:class_name]).to_empty_array }
|
27
|
+
else
|
28
|
+
nil
|
29
|
+
end
|
30
|
+
end
|
31
|
+
data
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def to_a
|
36
|
+
data = []
|
37
|
+
self.class.schema.each do |_, field_options|
|
38
|
+
next if field_options[:alias_of]
|
39
|
+
|
40
|
+
value = public_send(field_options[:getter])
|
41
|
+
data <<
|
42
|
+
case field_options[:type]
|
43
|
+
when :has_one
|
44
|
+
value ? value.to_a : self.class.const_get(field_options[:class_name]).to_empty_array
|
45
|
+
when :has_many
|
46
|
+
values = value || []
|
47
|
+
field_options[:size].times.map do |idx|
|
48
|
+
value = values[idx]
|
49
|
+
value ? value.to_a : self.class.const_get(field_options[:class_name]).to_empty_array
|
50
|
+
end
|
51
|
+
else
|
52
|
+
value
|
53
|
+
end
|
54
|
+
end
|
55
|
+
data
|
15
56
|
end
|
16
57
|
|
17
58
|
def update_attributes_with_array(array, mapped_headers, offset = nil)
|
data/lib/schema/csv_parser.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schema-model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Doug Youch
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-08-
|
11
|
+
date: 2019-08-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: inheritance-helper
|