Module: Rails::Mongoid
Overview
:nodoc:
Defined Under Namespace
Classes: Railtie
Instance Method Summary collapse
-
#index_children(children) ⇒ Object
Recursive function to create all the indexes for the model, then potentially and subclass of the model since both are still root documents in the hierarchy.
-
#load_models(app) ⇒ Object
Use the application configuration to get every model and require it, so that indexing and inheritance work in both development and production with the same results.
Instance Method Details
#index_children(children) ⇒ Object
Recursive function to create all the indexes for the model, then potentially and subclass of the model since both are still root documents in the hierarchy.
Note there is a tricky naming scheme going on here that needs to be revisisted. Module.descendants vs Class.descendents is way too confusing.
35 36 37 38 39 40 41 |
# File 'lib/rails/mongoid.rb', line 35 def index_children(children) children.each do |model| Logger.new($stdout).info("Generating indexes for #{model}") model.create_indexes index_children(model.descendants) end end |
#load_models(app) ⇒ Object
Use the application configuration to get every model and require it, so that indexing and inheritance work in both development and production with the same results.
14 15 16 17 18 19 20 21 |
# File 'lib/rails/mongoid.rb', line 14 def load_models(app) return unless ::Mongoid.preload_models app.config.paths["app/models"].each do |path| Dir.glob("#{path}/**/*.rb").sort.each do |file| load_model(file.gsub("#{path}/" , "").gsub(".rb", "")) end end end |