lib/mongoid/association/relatable.rb
# Resolves the given class/module name in the context of the specified
# module, as Ruby would when a constant is referenced in the source.
#
# @note This method can swallow exceptions produced during class loading,
#   because it rescues NameError internally. Since this method attempts
#   to load classes, failure during the loading process may also lead to
#   there being incomplete class definitions.
Resolves the given class/module name in the context of the specified
module, as Ruby would when a constant is referenced in the source.
Resolves the given class / module name in the context of the specified module as Ruby would when a constant is referenced in the source .
def resolve_name(mod, name)
        cls = exc = nil
        parts = name.to_s.split('::')
        if parts.first == ''
          parts.shift
          hierarchy = [Object]
        else
          hierarchy = namespace_hierarchy(mod)
        end
        hierarchy.each do |ns|
          begin
            parts.each do |part|
              ns = ns.const_get(part, false)
            end
            cls = ns
            break
          rescue NameError => e
            if exc.nil?
              exc = e
            end
          end
        end
        if cls.nil?
          raise exc
        end
        cls
      end
def resolve_name ( mod , name ) cls = exc = nil parts = name . to_s . split ( '::' ) if parts . first == '' parts . shift hierarchy = [ Object ] else hierarchy = namespace_hierarchy ( mod ) end hierarchy . each do | ns | begin parts . each do | part | ns = ns . const_get ( part , false ) end cls = ns break rescue NameError => e if exc . nil? exc = e end end end if cls . nil? raise exc end cls end
Resolves the given class/module name in the context of the specified
module, as Ruby would when a constant is referenced in the source.
Resolves the given class / module name in the context of the specified module as Ruby would when a constant is referenced in the source .
# Simple const_get sometimes pulls names out of weird scopes, # perhaps confusing the receiver (ns in this case) with the # local scope. Walk the class hierarchy ourselves one node # at a time by specifying false as the second argument. # Raise the first exception, this is from the most specific namespace
mod
<not_specific>
name
<not_specific>
note
This method can swallow exceptions produced during class loading, because it rescues NameError internally. Since this method attempts to load classes, failure during the loading process may also lead to there being incomplete class definitions.
This method can swallow exceptions produced during class loading because it rescues NameError internally . Since this method attempts to load classes failure during the loading process may also lead to there being incomplete class definitions .