forked from mongodb/mongoid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mongoid.rb
33 lines (31 loc) · 1.07 KB
/
mongoid.rb
1
2
3
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
# encoding: utf-8
module Rails #:nodoc:
module Mongoid #:nodoc:
class << self
# 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.
def load_models(app)
app.config.paths['app/models'].each do |path|
Dir.glob("#{path}/**/*.rb").sort.each do |file|
require_dependency(file)
end
end
end
# 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.
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
end
end
end