2003-12-16 00:44:25 -05:00
|
|
|
require 'rdoc/ri/ri_descriptions'
|
|
|
|
require 'rdoc/ri/ri_writer'
|
|
|
|
require 'rdoc/markup/simple_markup/to_flow'
|
|
|
|
|
|
|
|
module RI
|
|
|
|
class RiReader
|
|
|
|
|
|
|
|
def initialize(ri_cache)
|
|
|
|
@cache = ri_cache
|
|
|
|
end
|
|
|
|
|
|
|
|
def top_level_namespace
|
|
|
|
[ @cache.toplevel ]
|
|
|
|
end
|
|
|
|
|
|
|
|
def lookup_namespace_in(target, namespaces)
|
|
|
|
result = []
|
|
|
|
for n in namespaces
|
|
|
|
result.concat(n.contained_modules_matching(target))
|
|
|
|
end
|
|
|
|
result
|
|
|
|
end
|
|
|
|
|
2003-12-18 16:08:25 -05:00
|
|
|
def find_class_by_name(full_name)
|
|
|
|
names = full_name.split(/::/)
|
|
|
|
ns = @cache.toplevel
|
|
|
|
for name in names
|
|
|
|
ns = ns.contained_class_named(name)
|
|
|
|
return nil if ns.nil?
|
|
|
|
end
|
|
|
|
get_class(ns)
|
|
|
|
end
|
|
|
|
|
2003-12-16 00:44:25 -05:00
|
|
|
def find_methods(name, is_class_method, namespaces)
|
|
|
|
result = []
|
|
|
|
namespaces.each do |ns|
|
2003-12-16 15:28:44 -05:00
|
|
|
result.concat ns.methods_matching(name, is_class_method)
|
2003-12-16 00:44:25 -05:00
|
|
|
end
|
|
|
|
result
|
|
|
|
end
|
|
|
|
|
|
|
|
# return the MethodDescription for a given MethodEntry
|
|
|
|
# by deserializing the YAML
|
|
|
|
def get_method(method_entry)
|
|
|
|
path = method_entry.path_name
|
|
|
|
File.open(path) { |f| RI::Description.deserialize(f) }
|
|
|
|
end
|
|
|
|
|
|
|
|
# Return a class description
|
|
|
|
def get_class(class_entry)
|
2004-08-30 10:22:26 -04:00
|
|
|
result = nil
|
|
|
|
for path in class_entry.path_names
|
|
|
|
path = RiWriter.class_desc_path(path, class_entry)
|
|
|
|
desc = File.open(path) {|f| RI::Description.deserialize(f) }
|
|
|
|
if result
|
|
|
|
result.merge_in(desc)
|
|
|
|
else
|
|
|
|
result = desc
|
|
|
|
end
|
|
|
|
end
|
|
|
|
result
|
2003-12-16 00:44:25 -05:00
|
|
|
end
|
|
|
|
|
2003-12-23 23:24:29 -05:00
|
|
|
# return the names of all classes and modules
|
2004-01-12 14:32:24 -05:00
|
|
|
def full_class_names
|
2003-12-23 23:24:29 -05:00
|
|
|
res = []
|
|
|
|
find_classes_in(res, @cache.toplevel)
|
|
|
|
end
|
|
|
|
|
2004-03-24 14:17:42 -05:00
|
|
|
# return a list of all classes, modules, and methods
|
|
|
|
def all_names
|
|
|
|
res = []
|
|
|
|
find_names_in(res, @cache.toplevel)
|
|
|
|
end
|
|
|
|
|
|
|
|
# ----
|
|
|
|
private
|
|
|
|
# ----
|
|
|
|
|
2003-12-23 23:24:29 -05:00
|
|
|
def find_classes_in(res, klass)
|
|
|
|
classes = klass.classes_and_modules
|
|
|
|
for c in classes
|
2004-01-12 14:32:24 -05:00
|
|
|
res << c.full_name
|
2003-12-23 23:24:29 -05:00
|
|
|
find_classes_in(res, c)
|
|
|
|
end
|
|
|
|
res
|
|
|
|
end
|
2004-03-24 14:17:42 -05:00
|
|
|
|
|
|
|
def find_names_in(res, klass)
|
|
|
|
classes = klass.classes_and_modules
|
|
|
|
for c in classes
|
|
|
|
res << c.full_name
|
|
|
|
res.concat c.all_method_names
|
|
|
|
find_names_in(res, c)
|
|
|
|
end
|
|
|
|
res
|
|
|
|
end
|
|
|
|
|
2003-12-16 00:44:25 -05:00
|
|
|
end
|
|
|
|
end
|