Module: Rails::Mongoid

Extended by:
Mongoid
Included in:
Mongoid
Defined in:
lib/rails/mongoid.rb,
lib/mongoid/railtie.rb

Overview

:nodoc:

Defined Under Namespace

Classes: Railtie

Instance Method Summary collapse

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.

Examples:

Index the children.

Rails::Mongoid.index_children(classes)

Parameters:

  • children (Array<Class>)

    The child model classes.



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.

Examples:

Load all the application models.

Rails::Mongoid.load_models(app)

Parameters:

  • app (Application)

    The rails application.



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