Method: DataModels.load_models

Defined in:
lib/data_models/data_models.rb

.load_modelsArray

This method reads all models that the project hash.

Returns:

  • (Array)

    The proyect models list.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/data_models/data_models.rb', line 4

def self.load_models

   models = []   #All models will be in this list.
   models_valids = [] #This list is only to models with database table associated.
   mod = nil

   #Get all models in Model's folder
   Dir["#{RAILS_ROOT}/app/models/**/*.rb"].each do |file|
     models << file.gsub(RAILS_ROOT+'/app/models/',"").gsub('.rb','').classify
   end
   
   # Here, get the correct model's name: Singular or Plural
   models.each do |model|
     begin
       mod = eval model
       mod.columns
     rescue
       begin
         mod = eval model.pluralize
         mod.columns
       rescue
         mod = nil
       end
     end
     if mod
       models_valids << mod.to_s
     end
   end
 
   models_valids
end