6 def self.class_desc_path(dir, class_desc)
7 File.join(dir, "cdesc-" + class_desc.name + ".yaml")
11 # Convert a name from internal form (containing punctuation) to an external
12 # form (where punctuation is replaced by %xx)
14 def self.internal_to_external(name)
15 if ''.respond_to? :ord then
16 name.gsub(/\W/) { "%%%02x" % $&[0].ord }
18 name.gsub(/\W/) { "%%%02x" % $&[0] }
23 # And the reverse operation
25 def self.external_to_internal(name)
26 name.gsub(/%([0-9a-f]{2,2})/) { $1.to_i(16).chr }
29 def initialize(base_dir)
33 def remove_class(class_desc)
34 FileUtils.rm_rf(path_to_dir(class_desc.full_name))
37 def add_class(class_desc)
38 dir = path_to_dir(class_desc.full_name)
39 FileUtils.mkdir_p(dir)
40 class_file_name = self.class.class_desc_path(dir, class_desc)
41 File.open(class_file_name, "w") do |f|
42 f.write(class_desc.serialize)
46 def add_method(class_desc, method_desc)
47 dir = path_to_dir(class_desc.full_name)
48 file_name = self.class.internal_to_external(method_desc.name)
49 meth_file_name = File.join(dir, file_name)
50 if method_desc.is_singleton
51 meth_file_name += "-c.yaml"
53 meth_file_name += "-i.yaml"
56 File.open(meth_file_name, "w") do |f|
57 f.write(method_desc.serialize)
63 def path_to_dir(class_name)
64 File.join(@base_dir, *class_name.split('::'))