method
save_class
v2_5_5 -
Show latest stable
- Class:
RDoc::Store
save_class(klass)public
Writes the ri data for klass (or module)
# File lib/rdoc/store.rb, line 789
def save_class klass
full_name = klass.full_name
FileUtils.mkdir_p class_path(full_name) unless @dry_run
@cache[:modules] << full_name
path = class_file full_name
begin
disk_klass = load_class full_name
klass = disk_klass.merge klass
rescue MissingFileError
end
# BasicObject has no ancestors
ancestors = klass.direct_ancestors.compact.map do |ancestor|
# HACK for classes we don't know about (class X < RuntimeError)
String === ancestor ? ancestor : ancestor.full_name
end
@cache[:ancestors][full_name] ||= []
@cache[:ancestors][full_name].concat ancestors
attribute_definitions = klass.attributes.map do |attribute|
"#{attribute.definition} #{attribute.name}"
end
unless attribute_definitions.empty? then
@cache[:attributes][full_name] ||= []
@cache[:attributes][full_name].concat attribute_definitions
end
to_delete = []
unless klass.method_list.empty? then
@cache[:class_methods][full_name] ||= []
@cache[:instance_methods][full_name] ||= []
class_methods, instance_methods =
klass.method_list.partition { |meth| meth.singleton }
class_methods = class_methods. map { |method| method.name }
instance_methods = instance_methods.map { |method| method.name }
attribute_names = klass.attributes.map { |attr| attr.name }
old = @cache[:class_methods][full_name] - class_methods
to_delete.concat old.map { |method|
method_file full_name, "#{full_name}::#{method}"
}
old = @cache[:instance_methods][full_name] -
instance_methods - attribute_names
to_delete.concat old.map { |method|
method_file full_name, "#{full_name}##{method}"
}
@cache[:class_methods][full_name] = class_methods
@cache[:instance_methods][full_name] = instance_methods
end
return if @dry_run
FileUtils.rm_f to_delete
marshal = Marshal.dump klass
open path, 'wb' do |io|
io.write marshal
end
end Related methods
- Instance methods
- add_c_enclosure
- add_c_variables
- add_file
- all_classes
- all_classes_and_modules
- all_files
- all_modules
- ancestors
- attributes
- cache_path
- class_file
- class_methods
- class_path
- classes_hash
- clean_cache_collection
- complete
- files_hash
- find_c_enclosure
- find_class_named
- find_class_named_from
- find_class_or_module
- find_file_named
- find_module_named
- find_text_page
- find_unique
- fix_basic_object_inheritance
- friendly_path
- inspect
- instance_methods
- load_all
- load_cache
- load_class
- load_class_data
- load_method
- load_page
- main
- main=
- make_variable_map
- method_file
- module_names
- modules_hash
- page
- page_file
- remove_nodoc
- save
- save_cache
- save_class
- save_method
- save_page
- source
- title
- title=
- unique_classes
- unique_classes_and_modules
- unique_modules
- Class methods
- new