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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fe6d443393897ff1afd8170d5be1d363c4a81d0c173fb661f3e7aee01fb9f39c
4
- data.tar.gz: d4b204f257a9bbfbf60d55ada9d3cd02efdaf56c13e3ef7edb141bf48c7d31a4
3
+ metadata.gz: e57c8c78613d7ee20ab7f3e6a47cada9bdead12040f43d54932bcda82f0d6935
4
+ data.tar.gz: d16c1a6a36b4ba287afeb2c7bd961a26475dcdffa7be46edca5f1dce85ea63dd
5
5
  SHA512:
6
- metadata.gz: f6127881ad0492a5d1ae67c15dd8a06cc03f7f128094ccf0ed41b9805e8b3b05a4da2e93aa9934dfe9c92575ab773a76be5edbd695de245854c47fc36bfa2d25
7
- data.tar.gz: 8f4edb0b2a479eba63a4ffd81e8d3019486bf64f2e616a1cb6e73c6551b3abd0d5fed2e757487aa828d7d42d95a770e1b7f121eee722a5d3a88f9149a9e80d2e
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)
@@ -15,6 +15,7 @@ module Schema
15
15
  def missing_fields(required_fields)
16
16
  required_fields - get_mapped_headers(@mapped_headers)
17
17
  end
18
+ alias missing_headers missing_fields
18
19
 
19
20
  def shift
20
21
  return unless (row = @csv.shift)
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.0
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-20 00:00:00.000000000 Z
11
+ date: 2019-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: inheritance-helper