lib/rails/mongoid.rb
# Given the provided file name, determine the model and return the class.
#
# @example Determine the model from the file.
#   Rails::Mongoid.determine_model("app/models/person.rb")
#
# @param [ String ] file The filename.
#
# @return [ Class ] The model.
#
# @since 2.1.0
Given the provided file name, determine the model and return the class.
Given the provided file name determine the model and return the class .
def determine_model(file, logger)
      return nil unless file =~ /app\/models\/(.*).rb$/
      return nil unless logger
      model_path = $1.split('/')
      begin
        parts = model_path.map { |path| path.camelize }
        name = parts.join("::")
        klass = name.constantize
      rescue NameError, LoadError
        logger.info("MONGOID: Attempted to constantize #{name}, trying without namespacing.")
        klass = parts.last.constantize rescue nil
      end
      klass if klass && klass.ancestors.include?(::Mongoid::Document)
    end
def determine_model ( file , logger ) return nil unless file =~ / app \/ models \/ (.*).rb$ / return nil unless logger model_path = $1 . split ( '/' ) begin parts = model_path . map { | path | path . camelize } name = parts . join ( "::" ) klass = name . constantize rescue NameError , LoadError logger . info ( "MONGOID: Attempted to constantize #{name}, trying without namespacing." ) klass = parts . last . constantize rescue nil end klass if klass && klass . ancestors . include? ( :: Mongoid :: Document ) end
Given the provided file name, determine the model and return the class.
Given the provided file name determine the model and return the class .
None
 Class 
file
<not_specific>
logger
<not_specific>
<not_specific>
file The filename.
file The filename .
example
Determine the model from the file. Rails::Mongoid.determine_model("app/models/person.rb")
Determine the model from the file . Rails :: Mongoid . determine_model ( " app / models / person . rb " )
since
None