forest_liana 1.5.22 → 1.5.23
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
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5e3830a496e84b24397137ab4b61c3a11dc0eea9
|
4
|
+
data.tar.gz: 0bd3a0aa17c384f9d8c6f8d0f30e6e8d46e535ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e434a6e17a9fded4ead12220c140491de45227fe9f75cb381b2bf8abe9ed36f12137441edb524ba6c22322a6e7cac93e0fab0271f78c0ce4f2b68f74ecd0dd00
|
7
|
+
data.tar.gz: 808304e8300720bffe02bad42128aa75658a19f895fa9025610aa7857e5c4f2253b48ff98c254358c4fa268a77b7dc0a8d065878b58ef59d8a7ca396f25ddcfe
|
@@ -223,6 +223,7 @@ module ForestLiana
|
|
223
223
|
def get_schema_for_column(column)
|
224
224
|
schema = { field: column.name, type: get_type_for(column) }
|
225
225
|
add_enum_values_if_is_enum(schema, column)
|
226
|
+
add_enum_values_if_is_sti_model(schema, column)
|
226
227
|
end
|
227
228
|
|
228
229
|
def get_schema_for_association(association)
|
@@ -271,6 +272,23 @@ module ForestLiana
|
|
271
272
|
column_schema
|
272
273
|
end
|
273
274
|
|
275
|
+
def add_enum_values_if_is_sti_model(column_schema, column)
|
276
|
+
if sti_column?(column)
|
277
|
+
column_schema[:enums] = []
|
278
|
+
column_schema[:type] = 'Enum'
|
279
|
+
@model.descendants.each do |sti_model|
|
280
|
+
column_schema[:enums] << sti_model.name
|
281
|
+
end
|
282
|
+
end
|
283
|
+
|
284
|
+
column_schema
|
285
|
+
end
|
286
|
+
|
287
|
+
def sti_column?(column)
|
288
|
+
(@model.inheritance_column &&
|
289
|
+
column.name == @model.inheritance_column) || column.name == 'type'
|
290
|
+
end
|
291
|
+
|
274
292
|
def get_ref_for(association)
|
275
293
|
if association.options[:polymorphic] == true
|
276
294
|
'*.id'
|
@@ -70,5 +70,14 @@ module ForestLiana
|
|
70
70
|
def self.habtm?(model)
|
71
71
|
model.name.starts_with?('HABTM')
|
72
72
|
end
|
73
|
+
|
74
|
+
def self.sti?(model)
|
75
|
+
inheritance_column = model.columns.find do |c|
|
76
|
+
(model.inheritance_column && c.name == model.inheritance_column) ||
|
77
|
+
c.name == 'type'
|
78
|
+
end
|
79
|
+
|
80
|
+
return inheritance_column.present?
|
81
|
+
end
|
73
82
|
end
|
74
83
|
end
|
@@ -31,20 +31,9 @@ module ForestLiana
|
|
31
31
|
|
32
32
|
private
|
33
33
|
|
34
|
-
def fetch_sti_models(model)
|
35
|
-
type_field = model.columns.find { |c| c.name == 'type' }
|
36
|
-
if type_field
|
37
|
-
model.descendants.each do |sti_model|
|
38
|
-
if analyze_model?(sti_model)
|
39
|
-
ForestLiana.models << sti_model
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
34
|
def analyze_model?(model)
|
46
35
|
return model && model.table_exists? && !SchemaUtils.habtm?(model) &&
|
47
|
-
SchemaUtils.model_included?(model)
|
36
|
+
SchemaUtils.model_included?(model) && !SchemaUtils.sti?(model)
|
48
37
|
end
|
49
38
|
|
50
39
|
def fetch_models
|
@@ -56,8 +45,6 @@ module ForestLiana
|
|
56
45
|
if model.abstract_class?
|
57
46
|
model.descendants.each { |submodel| fetch_model(submodel) }
|
58
47
|
else
|
59
|
-
fetch_sti_models(model) if model.try(:table_exists?)
|
60
|
-
|
61
48
|
if analyze_model?(model)
|
62
49
|
ForestLiana.models << model
|
63
50
|
end
|
data/lib/forest_liana/version.rb
CHANGED