lib/yard/code_objects/base.rb in yard-0.5.2 vs lib/yard/code_objects/base.rb in yard-0.5.3
- old
+ new
@@ -127,10 +127,11 @@
class << self
# Allocates a new code object
# @return [Base]
# @see #initialize
def new(namespace, name, *args, &block)
+ raise ArgumentError, "invalid empty object name" if name.to_s.empty?
if name.to_s[0,2] == NSEP
name = name.to_s[2..-1]
namespace = Registry.root
elsif name =~ /(?:#{NSEPQ}|#{ISEPQ}|#{CSEPQ})([^#{NSEPQ}#{ISEPQ}#{CSEPQ}]+)$/
return new(Proxy.new(namespace, $`), $1, *args, &block)
@@ -343,9 +344,17 @@
else
name.to_s
end
end
alias_method :to_s, :path
+
+ # @param [Base, String] other another code object (or object path)
+ # @return [String] the shortest relative path from this object to +other+
+ def relative_path(other)
+ other = other.path if other.respond_to?(:path)
+ return other unless namespace
+ other.gsub(/^#{Regexp.quote namespace.path}(::|\.)?/, '')
+ end
# Renders the object using the {Templates::Engine templating system}.
#
# @example Formats a class in plaintext
# puts P('MyClass').format