class YARD::CodeObjects::Proxy
@see ProxyMethodError
@see Registry.resolve
Proxy.new(mymoduleobj, “String”)
# begin to act like the String ClassObject.
# When the String class is parsed this method will
@example Creates a Proxy to the String class from a module
not found, a warning is raised and {ProxyMethodError} might be raised.
point it does a lookup using {Registry.resolve}. If the object is
an unresolved path until a method is called on the object, at which
cases where the object may not yet exist. A proxy simply stores
The Proxy class is a way to lazily resolve code objects in
def self.===(other) other.is_a?(self) end
def self.===(other) other.is_a?(self) end
def <=>(other)
-
(Boolean)-
def <=>(other) if other.respond_to? :path path <=> other.path else false end end
def ===(other)
-
(Boolean)-
def ===(other) to_obj ? to_obj === other : self.class <= other.class end
def class
-
(Class)- the resolved object's class or +Proxy+
def class to_obj ? to_obj.class : Proxy end
def equal?(other)
-
(Boolean)-
def equal?(other) if other.respond_to? :path path == other.path else false end end
def hash; path.hash end
-
(Integer)- the object's hash value (for equality checking)
def hash; path.hash end
def initialize(namespace, name, type = nil)
-
(Proxy)- self
Raises:
-
(ArgumentError)- if namespace is not a NamespaceObject
def initialize(namespace, name, type = nil) namespace = Registry.root if !namespace || namespace == :root if name =~ /^#{NSEPQ}/ namespace = Registry.root name = name[2..-1] end if name =~ PROXY_MATCH @orignamespace = namespace @origname = name @imethod = true if name.include? ISEP namespace = Proxy.new(namespace, $`) unless $`.empty? name = $1 else @orignamespace = nil @origname = nil @imethod = nil end @name = name.to_sym @namespace = namespace @obj = nil @imethod ||= nil self.type = type if @namespace.is_a?(ConstantObject) unless @namespace.value =~ /\A#{NAMESPACEMATCH}\Z/ raise Parser::UndocumentableError, "constant mapping for " + "#{@origname} (type=#{type.inspect})" end @origname = nil # forget these for a constant @orignamespace = nil @namespace = Proxy.new(@namespace.namespace, @namespace.value) end unless @namespace.is_a?(NamespaceObject) || @namespace.is_a?(Proxy) raise ArgumentError, "Invalid namespace object: #{namespace}" end # If the name begins with "::" (like "::String") # this is definitely a root level object, so # remove the namespace and attach it to the root if @name =~ /^#{NSEPQ}/ @name.gsub!(/^#{NSEPQ}/, '') @namespace = Registry.root end end
def inspect
-
(String)- the object's #inspect method or P(OBJECTPATH)
def inspect to_obj ? to_obj.inspect : "P(#{path})" end
def instance_of?(klass)
-
(Boolean)-
def instance_of?(klass) self.class == klass end
def is_a?(klass)
-
(Boolean)-
def is_a?(klass) to_obj ? to_obj.is_a?(klass) : self.class <= klass end
def kind_of?(klass)
-
(Boolean)-
def kind_of?(klass) self.class <= klass end
def method_missing(meth, *args, &block)
-
(ProxyMethodError)- if the proxy cannot find the real object
def method_missing(meth, *args, &block) if to_obj to_obj.__send__(meth, *args, &block) else log.warn "Load Order / Name Resolution Problem on #{path}:\n" \ "-\n" \ "Something is trying to call #{meth} on object #{path} before it has been recognized.\n" \ "This error usually means that you need to modify the order in which you parse files\n" \ "so that #{path} is parsed before methods or other objects attempt to access it.\n" \ "-\n" \ "YARD will recover from this error and continue to parse but you *may* have problems\n" \ "with your generated documentation. You should probably fix this.\n" \ "-\n" begin super rescue NoMethodError raise ProxyMethodError, "Proxy cannot call method ##{meth} on object '#{path}'" end end end
def name(prefix = false)
def name(prefix = false) prefix ? "#{@imethod && ISEP}#{@name}" : @name end
def path
-
(String)- the assumed path of the proxy (or the real path
def path to_obj ? to_obj.path : proxy_path end
def proxy_path
def proxy_path if @namespace.root? (@imethod ? ISEP : "") + name.to_s elsif @origname if @origname =~ CONSTANTSTART @origname else [namespace.path, @origname].join end elsif name.to_s =~ CONSTANTSTART name.to_s else # class meth? [namespace.path, name.to_s].join(CSEP) end end
def respond_to?(meth, include_private = false)
-
(Boolean)-
def respond_to?(meth, include_private = false) to_obj ? to_obj.respond_to?(meth, include_private) : super end
def root?; false end
def root?; false end
def to_ary; nil end
- Note: - this method fixes a bug in 1.9.2: http://gist.github.com/437136
def to_ary; nil end
def to_obj
-
(Base, nil)- the registered code object or nil
def to_obj return @obj if @obj @obj = Registry.resolve(@namespace, (@imethod ? ISEP : '') + @name.to_s, false, false, @type) if @obj 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 type
- See: #type= -
Returns:
-
(Symbol)- the Proxy's type
def type to_obj ? to_obj.type : @type || :proxy end
def type=(type) @type = type ? type.to_sym : nil end
-
(void)-
Parameters:
-
type(#to_sym) -- the proxy's inferred type
def type=(type) @type = type ? type.to_sym : nil end