Module: DataModels
- Defined in:
- lib/data_models/data_models.rb
Class Method Summary collapse
-
.build_models_yaml_file ⇒ Hash
Return all RDF information stored in yaml file.
-
.get_model_data(model) ⇒ Hash
Return data model.
-
.load_models ⇒ Array
This method reads all models that the project hash.
-
.model_attributes(model) ⇒ Array
This method return all model’s attributes.
-
.model_relations(model) ⇒ Hash
This method return all model’s relations.
Class Method Details
.build_models_yaml_file ⇒ Hash
Return all RDF information stored in yaml file.
60 61 62 |
# File 'lib/data_models/data_models.rb', line 60 def self.build_models_yaml_file self.models end |
.get_model_data(model) ⇒ Hash
Return data model.
67 68 69 70 71 72 73 |
# File 'lib/data_models/data_models.rb', line 67 def self.get_model_data(model) begin eval model rescue eval model.pluralize end end |
.load_models ⇒ Array
This method reads all models that the project hash.
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 |
.model_attributes(model) ⇒ Array
This method return all model’s attributes.
39 40 41 |
# File 'lib/data_models/data_models.rb', line 39 def self.model_attributes(model) model.columns.map{|att| att.name}.join(", ") end |
.model_relations(model) ⇒ Hash
This method return all model’s relations
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/data_models/data_models.rb', line 46 def self.model_relations(model) relations = {} #Build the hash with relation name and relation's type. model.reflections.each do |relation,values| relations[relation] = {"model" => values.class_name,"type" => values.macro.to_s} end relations end |