forest_liana 1.5.22 → 1.5.23

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
  SHA1:
3
- metadata.gz: 66115c380e28a1968e472cb604a4cc6e2cfa6336
4
- data.tar.gz: 89487bf26d2e6c4bd59f01315307a452cbcdae46
3
+ metadata.gz: 5e3830a496e84b24397137ab4b61c3a11dc0eea9
4
+ data.tar.gz: 0bd3a0aa17c384f9d8c6f8d0f30e6e8d46e535ae
5
5
  SHA512:
6
- metadata.gz: d13e6768b5ee702c5b8f0be5f6f9c5c1ebacd02759b1453611800506bbfa5e739612330bdc39dcffd65a8f144657b0ae9b617ef6d4056587e9f27bc86f25f117
7
- data.tar.gz: 08d88a90f1cfdd1647fc33d75df18f8df5b642991fbb0993cf22f98f1ccb32488e908ccc5ee360edb0ec12d52d1a9d8050a786ae88c329819264459adfc91833
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
@@ -1,3 +1,3 @@
1
1
  module ForestLiana
2
- VERSION = "1.5.22"
2
+ VERSION = "1.5.23"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: forest_liana
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.22
4
+ version: 1.5.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sandro Munda