2008-01-08 05:18:41 -05:00
|
|
|
require 'rdoc/ri'
|
2003-12-16 00:44:25 -05:00
|
|
|
|
2008-01-08 05:18:41 -05:00
|
|
|
##
|
2003-12-16 00:44:25 -05:00
|
|
|
# Break argument into its constituent class or module names, an
|
|
|
|
# optional method type, and a method name
|
|
|
|
|
2008-01-08 05:18:41 -05:00
|
|
|
class RDoc::RI::NameDescriptor
|
2003-12-16 00:44:25 -05:00
|
|
|
|
|
|
|
attr_reader :class_names
|
|
|
|
attr_reader :method_name
|
2003-12-16 15:28:44 -05:00
|
|
|
|
2008-01-08 05:18:41 -05:00
|
|
|
##
|
2003-12-16 15:28:44 -05:00
|
|
|
# true and false have the obvious meaning. nil means we don't care
|
2008-01-08 05:18:41 -05:00
|
|
|
|
2003-12-16 00:44:25 -05:00
|
|
|
attr_reader :is_class_method
|
|
|
|
|
2008-01-08 05:18:41 -05:00
|
|
|
##
|
|
|
|
# +arg+ may be
|
|
|
|
#
|
|
|
|
# 1. A class or module name (optionally qualified with other class or module
|
|
|
|
# names (Kernel, File::Stat etc)
|
|
|
|
# 2. A method name
|
|
|
|
# 3. A method name qualified by a optionally fully qualified class or module
|
|
|
|
# name
|
2003-12-16 00:44:25 -05:00
|
|
|
#
|
|
|
|
# We're fairly casual about delimiters: folks can say Kernel::puts,
|
2008-01-08 05:18:41 -05:00
|
|
|
# Kernel.puts, or Kernel\#puts for example. There's one exception: if you
|
|
|
|
# say IO::read, we look for a class method, but if you say IO.read, we look
|
|
|
|
# for an instance method
|
2003-12-16 00:44:25 -05:00
|
|
|
|
|
|
|
def initialize(arg)
|
|
|
|
@class_names = []
|
2003-12-16 15:28:44 -05:00
|
|
|
separator = nil
|
2003-12-16 00:44:25 -05:00
|
|
|
|
2003-12-16 15:28:44 -05:00
|
|
|
tokens = arg.split(/(\.|::|#)/)
|
2003-12-16 00:44:25 -05:00
|
|
|
|
|
|
|
# Skip leading '::', '#' or '.', but remember it might
|
|
|
|
# be a method name qualifier
|
|
|
|
separator = tokens.shift if tokens[0] =~ /^(\.|::|#)/
|
|
|
|
|
|
|
|
# Skip leading '::', but remember we potentially have an inst
|
|
|
|
|
|
|
|
# leading stuff must be class names
|
2008-01-08 05:18:41 -05:00
|
|
|
|
2003-12-16 00:44:25 -05:00
|
|
|
while tokens[0] =~ /^[A-Z]/
|
|
|
|
@class_names << tokens.shift
|
|
|
|
unless tokens.empty?
|
|
|
|
separator = tokens.shift
|
2004-03-24 13:59:27 -05:00
|
|
|
break unless separator == "::"
|
2003-12-16 00:44:25 -05:00
|
|
|
end
|
|
|
|
end
|
2008-01-08 05:18:41 -05:00
|
|
|
|
|
|
|
# Now must have a single token, the method name, or an empty array
|
2003-12-16 00:44:25 -05:00
|
|
|
unless tokens.empty?
|
|
|
|
@method_name = tokens.shift
|
|
|
|
# We may now have a trailing !, ?, or = to roll into
|
|
|
|
# the method name
|
|
|
|
if !tokens.empty? && tokens[0] =~ /^[!?=]$/
|
|
|
|
@method_name << tokens.shift
|
|
|
|
end
|
|
|
|
|
|
|
|
if @method_name =~ /::|\.|#/ or !tokens.empty?
|
2009-03-05 22:56:38 -05:00
|
|
|
raise RDoc::RI::Error.new("Bad argument: #{arg}")
|
2003-12-16 00:44:25 -05:00
|
|
|
end
|
2003-12-18 22:58:57 -05:00
|
|
|
if separator && separator != '.'
|
2003-12-16 15:28:44 -05:00
|
|
|
@is_class_method = separator == "::"
|
|
|
|
end
|
2003-12-16 00:44:25 -05:00
|
|
|
end
|
|
|
|
end
|
2004-01-06 23:05:25 -05:00
|
|
|
|
2008-01-08 05:18:41 -05:00
|
|
|
# Return the full class name (with '::' between the components) or "" if
|
|
|
|
# there's no class name
|
2004-01-06 23:05:25 -05:00
|
|
|
|
|
|
|
def full_class_name
|
|
|
|
@class_names.join("::")
|
|
|
|
end
|
2008-01-08 05:18:41 -05:00
|
|
|
|
2003-12-16 00:44:25 -05:00
|
|
|
end
|
2008-01-08 05:18:41 -05:00
|
|
|
|