diff options
author | drbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-01-08 10:18:41 +0000 |
---|---|---|
committer | drbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-01-08 10:18:41 +0000 |
commit | 3e39ade457b432a57d63e00d5a9898ca202d26f1 (patch) | |
tree | e82f30dd15c6f0e3d89fbe45c573ad755750e769 /lib/rdoc/ri/writer.rb | |
parent | 929faf7906a2f2ca7dbf5eda5670e666edddfa88 (diff) | |
download | ruby-3e39ade457b432a57d63e00d5a9898ca202d26f1.tar.gz |
Clean up namespacing of RI's classes
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14953 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rdoc/ri/writer.rb')
-rw-r--r-- | lib/rdoc/ri/writer.rb | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/lib/rdoc/ri/writer.rb b/lib/rdoc/ri/writer.rb new file mode 100644 index 0000000000..2d14942bdd --- /dev/null +++ b/lib/rdoc/ri/writer.rb @@ -0,0 +1,64 @@ +require 'fileutils' +require 'rdoc/ri' + +class RDoc::RI::Writer + + def self.class_desc_path(dir, class_desc) + File.join(dir, "cdesc-" + class_desc.name + ".yaml") + end + + ## + # Convert a name from internal form (containing punctuation) to an external + # form (where punctuation is replaced by %xx) + + def self.internal_to_external(name) + name.gsub(/\W/) { "%%%02x" % $&[0].ord } + end + + ## + # And the reverse operation + + def self.external_to_internal(name) + name.gsub(/%([0-9a-f]{2,2})/) { $1.to_i(16).chr } + end + + def initialize(base_dir) + @base_dir = base_dir + end + + def remove_class(class_desc) + FileUtils.rm_rf(path_to_dir(class_desc.full_name)) + end + + def add_class(class_desc) + dir = path_to_dir(class_desc.full_name) + FileUtils.mkdir_p(dir) + class_file_name = self.class.class_desc_path(dir, class_desc) + File.open(class_file_name, "w") do |f| + f.write(class_desc.serialize) + end + end + + def add_method(class_desc, method_desc) + dir = path_to_dir(class_desc.full_name) + file_name = self.class.internal_to_external(method_desc.name) + meth_file_name = File.join(dir, file_name) + if method_desc.is_singleton + meth_file_name += "-c.yaml" + else + meth_file_name += "-i.yaml" + end + + File.open(meth_file_name, "w") do |f| + f.write(method_desc.serialize) + end + end + + private + + def path_to_dir(class_name) + File.join(@base_dir, *class_name.split('::')) + end + +end + |