module Rails::Mongoid

def load_model(file)

Parameters:
  • file (String) -- The base filename.

Other tags:
    Example: Load the model. -
def load_model(file)
  begin
    require_dependency(file)
  rescue Exception => e
    Logger.new(STDERR).warn(e.message)
  end
end

def load_models(app)

Parameters:
  • app (Application) -- The rails application.

Other tags:
    Example: Load all the application models. -
def load_models(app)
  app.config.paths["app/models"].expanded.each do |path|
    preload = ::Mongoid.preload_models
    if preload.resizable?
      files = preload.map { |model| "#{path}/#{model.underscore}.rb" }
    else
      files = Dir.glob("#{path}/**/*.rb")
    end
    files.sort.each do |file|
      load_model(file.gsub("#{path}/" , "").gsub(".rb", ""))
    end
  end
end

def preload_models(app)

Parameters:
  • app (Application) -- The rails application.
def preload_models(app)
  load_models(app) if ::Mongoid.preload_models
end