lib/rails/mongoid.rb in mongoid-2.2.6 vs lib/rails/mongoid.rb in mongoid-2.3.0
- old
+ new
@@ -34,18 +34,25 @@
# @example Load all the application models.
# Rails::Mongoid.load_models(app)
#
# @param [ Application ] app The rails application.
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
+ # Conditionally calls `Rails::Mongoid.load_models(app)` if the
+ # `::Mongoid.preload_models` is `true`.
+ #
+ # @param [ Application ] app The rails application.
+ def preload_models(app)
+ load_models(app) if ::Mongoid.preload_models
+ end
+
private
# I don't want to mock out kernel for unit testing purposes, so added this
# method as a convenience.
#
@@ -68,13 +75,15 @@
#
# @return [ Class ] The model.
#
# @since 2.1.0
def determine_model(file)
- model_path = file[0..-4].split('/')[2..-1]
- klass = model_path.map { |path| path.camelize }.join('::').constantize
- if klass.ancestors.include?(::Mongoid::Document) && !klass.embedded
- return klass
+ if file =~ /app\/models\/(.*).rb$/
+ model_path = $1.split('/')
+ klass = model_path.map { |path| path.camelize }.join('::').constantize
+ if klass.ancestors.include?(::Mongoid::Document) && !klass.embedded
+ return klass
+ end
end
end
end
end