lib/yard/code_objects/proxy.rb in yard-0.8.1 vs lib/yard/code_objects/proxy.rb in yard-0.8.2

- old
+ new

@@ -23,11 +23,11 @@ # Creates a new Proxy # # @raise [ArgumentError] if namespace is not a NamespaceObject # @return [Proxy] self - def initialize(namespace, name) + def initialize(namespace, name, type = nil) namespace = Registry.root if !namespace || namespace == :root if name =~ /^#{NSEPQ}/ namespace = Registry.root name = name[2..-1] @@ -44,10 +44,11 @@ @name = name.to_sym @namespace = namespace @obj = nil @imethod ||= nil + self.type = type if @namespace.is_a?(ConstantObject) @origname = nil # forget these for a constant @orignamespace = nil @namespace = Proxy.new(@namespace.namespace, @namespace.value) @@ -88,23 +89,11 @@ # of the resolved object) def path if obj = to_obj obj.path else - if @namespace.root? - (@imethod ? ISEP : "") + name.to_s - elsif @origname - if @origname =~ /^[A-Z]/ - @origname - else - [namespace.path, @origname].join - end - elsif name.to_s =~ /^[A-Z]/ # const - name.to_s - else # class meth? - [namespace.path, name.to_s].join(CSEP) - end + proxy_path end end alias to_s path alias to_str path @@ -166,18 +155,18 @@ # @see #type= def type if obj = to_obj obj.type else - Registry.proxy_types[path] || :proxy + @type || :proxy end end # Allows a parser to infer the type of the proxy by its path. # @param [#to_sym] type the proxy's inferred type # @return [void] - def type=(type) Registry.proxy_types[path] = type.to_sym end + def type=(type) @type = type ? type.to_sym : nil end # @return [Boolean] def instance_of?(klass) self.class == klass end @@ -233,20 +222,36 @@ # registered all the way up the namespace tree. # # @return [Base, nil] the registered code object or nil def to_obj return @obj if @obj - if @obj = Registry.resolve(@namespace, (@imethod ? ISEP : '') + @name.to_s) + if @obj = Registry.resolve(@namespace, (@imethod ? ISEP : '') + @name.to_s, false, false, @type) if @origname && @origname.include?("::") && !@obj.path.include?(@origname) # the object's path should include the original proxy namespace, # otherwise it's (probably) not the right object. @obj = nil else @namespace = @obj.namespace @name = @obj.name end end @obj + end + + def proxy_path + if @namespace.root? + (@imethod ? ISEP : "") + name.to_s + elsif @origname + if @origname =~ /^[A-Z]/ + @origname + else + [namespace.path, @origname].join + end + elsif name.to_s =~ /^[A-Z]/ # const + name.to_s + else # class meth? + [namespace.path, name.to_s].join(CSEP) + end end end end end