yaml-file-db 0.1.5 → 0.1.6
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 +4 -4
- data/lib/yaml-file-db/database.rb +3 -3
- data/lib/yaml-file-db/row.rb +10 -7
- 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: e267ac60c172096d2484e3e86854886c4c4dbbeb7c895cae083eea0781d4fb00
|
4
|
+
data.tar.gz: 96258128806aea1f96017700203a485f204da736ab0ebcffce36fbfdc2654f57
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 34099bed1433f9fe540fb4a0f5f1a9a16c63b44f17b2809f6a535438da4968b6e1ae7874278b1628335f391b8fa280af442cd03235b6235764fe01b2501b4c73
|
7
|
+
data.tar.gz: ef76c1a1cafe075452fdaaf0d2f0250c0141a05cf81edf028c76bdf54cfb8e22653464df87e15e7430bebcc76367f650f838ff937f6ea3b3b5ac630fe4f950fa
|
@@ -71,9 +71,9 @@ module YDB
|
|
71
71
|
|
72
72
|
table = instance_variable_get var
|
73
73
|
table.each do |_id, row|
|
74
|
-
block.call(row)
|
75
|
-
|
76
|
-
|
74
|
+
block.call(row).each do |error|
|
75
|
+
@errors << "[#{row.source.split('/')[-3..].join('/')}] #{error}"
|
76
|
+
end
|
77
77
|
end
|
78
78
|
end
|
79
79
|
end
|
data/lib/yaml-file-db/row.rb
CHANGED
@@ -15,6 +15,7 @@ module YDB
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def build_relationships(db, keywords)
|
18
|
+
errors = []
|
18
19
|
iterate_over_columns do |key, value|
|
19
20
|
if keywords.include?(key)
|
20
21
|
if key.pluralize == key
|
@@ -22,39 +23,41 @@ module YDB
|
|
22
23
|
table = db.public_send(key.to_sym)
|
23
24
|
value.each do |primary_key|
|
24
25
|
row = table[primary_key]
|
25
|
-
|
26
|
-
|
26
|
+
errors << "Invalid primary_key: #{primary_key} isn't part of table #{key}" if row.nil?
|
27
27
|
rows << row
|
28
28
|
end
|
29
29
|
instance_variable_set("@#{key}", rows)
|
30
30
|
else
|
31
31
|
row = db.public_send(key.pluralize.to_sym)[value]
|
32
|
-
|
33
|
-
|
32
|
+
errors << "Invalid primary_key: #{value} isn't part of table #{key.pluralize}" if row.nil?
|
34
33
|
instance_variable_set("@#{key}", row)
|
35
34
|
end
|
36
35
|
end
|
37
36
|
end
|
37
|
+
errors
|
38
38
|
end
|
39
39
|
|
40
40
|
def check_relationships(_db, keywords)
|
41
|
+
errors = []
|
41
42
|
iterate_over_columns do |key, value|
|
42
43
|
if keywords.include?(key)
|
43
|
-
|
44
|
+
next if value.nil?
|
45
|
+
|
44
46
|
value = [value] if value.is_a?(YDB::Row)
|
45
47
|
value.each do |row|
|
46
48
|
if row.respond_to?(self.class.to_s.downcase.to_sym)
|
47
49
|
unless row.public_send(self.class.to_s.downcase.to_sym) == self
|
48
|
-
|
50
|
+
errors << "Inconsistent relationship: #{row.id} doesn't link back to #{id}"
|
49
51
|
end
|
50
52
|
elsif row.respond_to?(self.class.to_s.downcase.pluralize.to_sym)
|
51
53
|
unless row.public_send(self.class.to_s.downcase.pluralize.to_sym).include?(self)
|
52
|
-
|
54
|
+
errors << "Inconsistent relationship: #{row.id} doesn't link back to #{id}"
|
53
55
|
end
|
54
56
|
end
|
55
57
|
end
|
56
58
|
end
|
57
59
|
end
|
60
|
+
errors
|
58
61
|
end
|
59
62
|
|
60
63
|
private
|