Module: BrowseModelsControl
- Defined in:
- app/controls/browse_models_control.rb
Instance Method Summary collapse
-
#all_collections ⇒ Object
Return array of all models found in application.
-
#all_fields ⇒ Object
List field definition for single model.
-
#collections ⇒ Object
List all collections.
Instance Method Details
#all_collections ⇒ Object
Return array of all models found in application.
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/controls/browse_models_control.rb', line 32 def all_collections collections = [] DrgCms.paths(:forms).each do |path| models_dir = File.("../models", path) Dir["#{models_dir}/*.rb"].each do |model_file| model_file =~ /(.*)\/(.*).rb/ # check if model exists collection = $2.camelize.constantize.new rescue nil collections << collection.class.to_s.underscore if collection&.respond_to?(:_id) end end collections.sort end |
#all_fields ⇒ Object
List field definition for single model
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'app/controls/browse_models_control.rb', line 62 def all_fields @records = [] model = params[:id].classify.constantize document = model.new document.attribute_names.each do |attribute_name| = model.fields[attribute_name]. description = I18n.t("helpers.help.#{params[:id]}.#{attribute_name}") description = I18n.t("helpers.label.#{params[:id]}.#{attribute_name}") if description.match('missing:') description = attribute_name if description.match('missing:') @records << DcMemory.new({id: attribute_name, 'collection' => params[:id], 'field' => attribute_name, 'type' => [:type], 'description' => description, '_default' => [:default] }) end # embedded documents document..each do || = .last description = I18n.t("helpers.help.#{params[:id]}.#{.key}") description = I18n.t("helpers.label.#{params[:id]}.#{.key}") if description.match('missing:') description = .key if description.match('missing:') @records << DcMemory.new({ id: .key, 'collection' => params[:id], 'field' => .key, 'type' => 'Embedded:' + .class_name, 'description' => description }) end @records end |
#collections ⇒ Object
List all collections
49 50 51 52 53 54 55 56 57 |
# File 'app/controls/browse_models_control.rb', line 49 def collections @records = [] all_collections.each do |collection| next if params[:filter] && !collection.match(/#{params[:filter]}/i) @records << DcMemory.new({'id' => collection, 'description' => t("helpers.label.#{collection}.tabletitle") }) end @records end |