Class: RDoc::Store
- Inherits:
-
Object
- Object
- RDoc::Store
- Defined in:
- lib/rdoc/store.rb
Overview
A set of rdoc data for a single project (gem, path, etc.).
The store manages reading and writing ri data for a project and maintains a cache of methods, classes and ancestors in the store.
The store maintains a #cache of its contents for faster lookup. After adding items to the store it must be flushed using #save_cache. The cache contains the following structures:
@cache = {
:ancestors => {}, # class name => ancestor names
:attributes => {}, # class name => attributes
:class_methods => {}, # class name => class methods
:instance_methods => {}, # class name => instance methods
:modules => [], # classes and modules in this store
:pages => [], # page names
}
– TODO need to prune classes
Defined Under Namespace
Classes: Error, MissingFileError
Instance Attribute Summary collapse
-
#c_class_variables ⇒ Object
readonly
Maps C variables to class or module names for each parsed C file.
-
#c_enclosure_classes ⇒ Object
readonly
Stores the name of the C variable a class belongs to.
-
#c_enclosure_names ⇒ Object
readonly
:nodoc:.
-
#c_singleton_class_variables ⇒ Object
readonly
Maps C variables to singleton class names for each parsed C file.
-
#cache ⇒ Object
readonly
The contents of the Store.
-
#dry_run ⇒ Object
If true this Store will not write any files.
-
#encoding ⇒ Object
The encoding of the contents in the Store.
-
#path ⇒ Object
Path this store reads or writes.
-
#rdoc ⇒ Object
The RDoc::RDoc driver for this parse tree.
-
#type ⇒ Object
Type of ri datastore this was loaded from.
Instance Method Summary collapse
-
#add_c_enclosure(variable, namespace) ⇒ Object
Adds
module
as an enclosure (namespace) for the givenvariable
for C files. -
#add_c_variables(c_parser) ⇒ Object
Adds C variables from an RDoc::Parser::C.
-
#add_file(absolute_name, relative_name = absolute_name) ⇒ Object
Adds the file with
name
as an RDoc::TopLevel to the store. -
#all_classes ⇒ Object
Returns all classes discovered by RDoc.
-
#all_classes_and_modules ⇒ Object
Returns all classes and modules discovered by RDoc.
-
#all_files ⇒ Object
All TopLevels known to RDoc.
-
#all_modules ⇒ Object
Returns all modules discovered by RDoc.
-
#ancestors ⇒ Object
Ancestors cache accessor.
-
#attributes ⇒ Object
Attributes cache accessor.
-
#cache_path ⇒ Object
Path to the cache file.
-
#class_file(klass_name) ⇒ Object
Path to the ri data for
klass_name
. -
#class_methods ⇒ Object
Class methods cache accessor.
-
#class_path(klass_name) ⇒ Object
Path where data for
klass_name
will be stored (methods or class data). -
#classes_hash ⇒ Object
Hash of all classes known to RDoc.
-
#clean_cache_collection(collection) ⇒ Object
Removes empty items and ensures item in each collection are unique and sorted.
-
#complete(min_visibility) ⇒ Object
Prepares the RDoc code object tree for use by a generator.
-
#files_hash ⇒ Object
Hash of all files known to RDoc.
-
#find_c_enclosure(variable) ⇒ Object
Finds the enclosure (namespace) for the given C
variable
. -
#find_class_named(name) ⇒ Object
Finds the class with
name
in all discovered classes. -
#find_class_named_from(name, from) ⇒ Object
Finds the class with
name
starting in namespacefrom
. -
#find_class_or_module(name) ⇒ Object
Finds the class or module with
name
. -
#find_file_named(name) ⇒ Object
Finds the file with
name
in all discovered files. -
#find_module_named(name) ⇒ Object
Finds the module with
name
in all discovered modules. -
#find_text_page(file_name) ⇒ Object
Returns the RDoc::TopLevel that is a text file and has the given
file_name
. -
#find_unique(all_hash) ⇒ Object
Finds unique classes/modules defined in
all_hash
, and returns them as an array. -
#fix_basic_object_inheritance ⇒ Object
Fixes the erroneous
BasicObject < Object
in 1.9. -
#friendly_path ⇒ Object
Friendly rendition of #path.
-
#initialize(path = nil, type = nil) ⇒ Store
constructor
Creates a new Store of
type
that will load or save topath
. -
#inspect ⇒ Object
:nodoc:.
-
#instance_methods ⇒ Object
Instance methods cache accessor.
-
#load_all ⇒ Object
Loads all items from this store into memory.
-
#load_cache ⇒ Object
Loads cache file for this store.
-
#load_class(klass_name) ⇒ Object
Loads ri data for
klass_name
and hooks it up to this store. -
#load_class_data(klass_name) ⇒ Object
Loads ri data for
klass_name
. -
#load_method(klass_name, method_name) ⇒ Object
Loads ri data for
method_name
inklass_name
. -
#load_page(page_name) ⇒ Object
Loads ri data for
page_name
. -
#main ⇒ Object
Gets the main page for this RDoc store.
-
#main=(page) ⇒ Object
Sets the main page for this RDoc store.
-
#make_variable_map(variables) ⇒ Object
Converts the variable => ClassModule map
variables
from a C parser into a variable => class name map. -
#method_file(klass_name, method_name) ⇒ Object
Path to the ri data for
method_name
inklass_name
. -
#module_names ⇒ Object
Modules cache accessor.
-
#modules_hash ⇒ Object
Hash of all modules known to RDoc.
-
#page(name) ⇒ Object
Returns the RDoc::TopLevel that is a text file and has the given
name
. -
#page_file(page_name) ⇒ Object
Path to the ri data for
page_name
. -
#remove_nodoc(all_hash) ⇒ Object
Removes from
all_hash
the contexts that are nodoc or have no content. -
#save ⇒ Object
Saves all entries in the store.
-
#save_cache ⇒ Object
Writes the cache file for this store.
-
#save_class(klass) ⇒ Object
Writes the ri data for
klass
(or module). -
#save_method(klass, method) ⇒ Object
Writes the ri data for
method
onklass
. -
#save_page(page) ⇒ Object
Writes the ri data for
page
. -
#source ⇒ Object
Source of the contents of this store.
-
#title ⇒ Object
Gets the title for this RDoc store.
-
#title=(title) ⇒ Object
Sets the title page for this RDoc store.
-
#unique_classes ⇒ Object
Returns the unique classes discovered by RDoc.
-
#unique_classes_and_modules ⇒ Object
Returns the unique classes and modules discovered by RDoc.
-
#unique_modules ⇒ Object
Returns the unique modules discovered by RDoc.
Constructor Details
#initialize(path = nil, type = nil) ⇒ Store
Creates a new Store of type
that will load or save to path
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/rdoc/store.rb', line 121 def initialize path = nil, type = nil @dry_run = false @encoding = nil @path = path @rdoc = nil @type = type @cache = { :ancestors => {}, :attributes => {}, :class_methods => {}, :c_class_variables => {}, :c_singleton_class_variables => {}, :encoding => @encoding, :instance_methods => {}, :main => nil, :modules => [], :pages => [], :title => nil, } @classes_hash = {} @modules_hash = {} @files_hash = {} @c_enclosure_classes = {} @c_enclosure_names = {} @c_class_variables = {} @c_singleton_class_variables = {} @unique_classes = nil @unique_modules = nil end |
Instance Attribute Details
#c_class_variables ⇒ Object (readonly)
Maps C variables to class or module names for each parsed C file.
79 80 81 |
# File 'lib/rdoc/store.rb', line 79 def c_class_variables @c_class_variables end |
#c_enclosure_classes ⇒ Object (readonly)
Stores the name of the C variable a class belongs to. This helps wire up classes defined from C across files.
72 73 74 |
# File 'lib/rdoc/store.rb', line 72 def c_enclosure_classes @c_enclosure_classes end |
#c_enclosure_names ⇒ Object (readonly)
:nodoc:
74 75 76 |
# File 'lib/rdoc/store.rb', line 74 def c_enclosure_names @c_enclosure_names end |
#c_singleton_class_variables ⇒ Object (readonly)
Maps C variables to singleton class names for each parsed C file.
84 85 86 |
# File 'lib/rdoc/store.rb', line 84 def c_singleton_class_variables @c_singleton_class_variables end |
#cache ⇒ Object (readonly)
The contents of the Store
111 112 113 |
# File 'lib/rdoc/store.rb', line 111 def cache @cache end |
#dry_run ⇒ Object
If true this Store will not write any files
89 90 91 |
# File 'lib/rdoc/store.rb', line 89 def dry_run @dry_run end |
#encoding ⇒ Object
The encoding of the contents in the Store
116 117 118 |
# File 'lib/rdoc/store.rb', line 116 def encoding @encoding end |
#path ⇒ Object
Path this store reads or writes
94 95 96 |
# File 'lib/rdoc/store.rb', line 94 def path @path end |
#rdoc ⇒ Object
The RDoc::RDoc driver for this parse tree. This allows classes consulting the documentation tree to access user-set options, for example.
100 101 102 |
# File 'lib/rdoc/store.rb', line 100 def rdoc @rdoc end |
#type ⇒ Object
Type of ri datastore this was loaded from. See RDoc::RI::Driver, RDoc::RI::Paths.
106 107 108 |
# File 'lib/rdoc/store.rb', line 106 def type @type end |
Instance Method Details
#add_c_enclosure(variable, namespace) ⇒ Object
Adds module
as an enclosure (namespace) for the given variable
for C files.
160 161 162 |
# File 'lib/rdoc/store.rb', line 160 def add_c_enclosure variable, namespace @c_enclosure_classes[variable] = namespace end |
#add_c_variables(c_parser) ⇒ Object
Adds C variables from an RDoc::Parser::C
167 168 169 170 171 172 173 |
# File 'lib/rdoc/store.rb', line 167 def add_c_variables c_parser filename = c_parser.top_level.relative_name @c_class_variables[filename] = make_variable_map c_parser.classes @c_singleton_class_variables[filename] = c_parser.singleton_classes end |
#add_file(absolute_name, relative_name = absolute_name) ⇒ Object
Adds the file with name
as an RDoc::TopLevel to the store. Returns the created RDoc::TopLevel.
179 180 181 182 183 184 185 186 187 |
# File 'lib/rdoc/store.rb', line 179 def add_file absolute_name, relative_name = absolute_name unless top_level = @files_hash[relative_name] then top_level = RDoc::TopLevel.new absolute_name, relative_name top_level.store = self @files_hash[relative_name] = top_level end top_level end |
#all_classes ⇒ Object
Returns all classes discovered by RDoc
192 193 194 |
# File 'lib/rdoc/store.rb', line 192 def all_classes @classes_hash.values end |
#all_classes_and_modules ⇒ Object
Returns all classes and modules discovered by RDoc
199 200 201 |
# File 'lib/rdoc/store.rb', line 199 def all_classes_and_modules @classes_hash.values + @modules_hash.values end |
#all_files ⇒ Object
All TopLevels known to RDoc
206 207 208 |
# File 'lib/rdoc/store.rb', line 206 def all_files @files_hash.values end |
#all_modules ⇒ Object
Returns all modules discovered by RDoc
213 214 215 |
# File 'lib/rdoc/store.rb', line 213 def all_modules modules_hash.values end |
#ancestors ⇒ Object
Ancestors cache accessor. Maps a klass name to an Array of its ancestors in this store. If Foo in this store inherits from Object, Kernel won’t be listed (it will be included from ruby’s ri store).
222 223 224 |
# File 'lib/rdoc/store.rb', line 222 def ancestors @cache[:ancestors] end |
#attributes ⇒ Object
Attributes cache accessor. Maps a class to an Array of its attributes.
229 230 231 |
# File 'lib/rdoc/store.rb', line 229 def attributes @cache[:attributes] end |
#cache_path ⇒ Object
Path to the cache file
236 237 238 |
# File 'lib/rdoc/store.rb', line 236 def cache_path File.join @path, 'cache.ri' end |
#class_file(klass_name) ⇒ Object
Path to the ri data for klass_name
243 244 245 246 |
# File 'lib/rdoc/store.rb', line 243 def class_file klass_name name = klass_name.split('::').last File.join class_path(klass_name), "cdesc-#{name}.ri" end |
#class_methods ⇒ Object
Class methods cache accessor. Maps a class to an Array of its class methods (not full name).
252 253 254 |
# File 'lib/rdoc/store.rb', line 252 def class_methods @cache[:class_methods] end |
#class_path(klass_name) ⇒ Object
Path where data for klass_name
will be stored (methods or class data)
259 260 261 |
# File 'lib/rdoc/store.rb', line 259 def class_path klass_name File.join @path, *klass_name.split('::') end |
#classes_hash ⇒ Object
Hash of all classes known to RDoc
266 267 268 |
# File 'lib/rdoc/store.rb', line 266 def classes_hash @classes_hash end |
#clean_cache_collection(collection) ⇒ Object
Removes empty items and ensures item in each collection are unique and sorted
274 275 276 277 278 279 280 281 282 283 284 |
# File 'lib/rdoc/store.rb', line 274 def clean_cache_collection collection # :nodoc: collection.each do |name, item| if item.empty? then collection.delete name else # HACK mongrel-1.1.5 documents its files twice item.uniq! item.sort! end end end |
#complete(min_visibility) ⇒ Object
Prepares the RDoc code object tree for use by a generator.
It finds unique classes/modules defined, and replaces classes/modules that are aliases for another one by a copy with RDoc::ClassModule#is_alias_for set.
It updates the RDoc::ClassModule#constant_aliases attribute of “real” classes or modules.
It also completely removes the classes and modules that should be removed from the documentation and the methods that have a visibility below min_visibility
, which is the --visibility
option.
See also RDoc::Context#remove_from_documentation?
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 |
# File 'lib/rdoc/store.rb', line 302 def complete min_visibility fix_basic_object_inheritance # cache included modules before they are removed from the documentation all_classes_and_modules.each { |cm| cm.ancestors } unless min_visibility == :nodoc then remove_nodoc @classes_hash remove_nodoc @modules_hash end @unique_classes = find_unique @classes_hash @unique_modules = find_unique @modules_hash unique_classes_and_modules.each do |cm| cm.complete min_visibility end @files_hash.each_key do |file_name| tl = @files_hash[file_name] unless tl.text? then tl.modules_hash.clear tl.classes_hash.clear tl.classes_or_modules.each do |cm| name = cm.full_name if cm.type == 'class' then tl.classes_hash[name] = cm if @classes_hash[name] else tl.modules_hash[name] = cm if @modules_hash[name] end end end end end |
#files_hash ⇒ Object
Hash of all files known to RDoc
342 343 344 |
# File 'lib/rdoc/store.rb', line 342 def files_hash @files_hash end |
#find_c_enclosure(variable) ⇒ Object
Finds the enclosure (namespace) for the given C variable
.
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 |
# File 'lib/rdoc/store.rb', line 349 def find_c_enclosure variable @c_enclosure_classes.fetch variable do break unless name = @c_enclosure_names[variable] mod = find_class_or_module name unless mod then loaded_mod = load_class_data name file = loaded_mod.in_files.first return unless file # legacy data source file.store = self mod = file.add_module RDoc::NormalModule, name end @c_enclosure_classes[variable] = mod end end |
#find_class_named(name) ⇒ Object
Finds the class with name
in all discovered classes
374 375 376 |
# File 'lib/rdoc/store.rb', line 374 def find_class_named name @classes_hash[name] end |
#find_class_named_from(name, from) ⇒ Object
Finds the class with name
starting in namespace from
381 382 383 384 385 386 387 388 389 390 391 392 393 394 |
# File 'lib/rdoc/store.rb', line 381 def find_class_named_from name, from from = find_class_named from unless RDoc::Context === from until RDoc::TopLevel === from do return nil unless from klass = from.find_class_named name return klass if klass from = from.parent end find_class_named name end |
#find_class_or_module(name) ⇒ Object
Finds the class or module with name
399 400 401 402 |
# File 'lib/rdoc/store.rb', line 399 def find_class_or_module name name = $' if name =~ /^::/ @classes_hash[name] || @modules_hash[name] end |
#find_file_named(name) ⇒ Object
Finds the file with name
in all discovered files
407 408 409 |
# File 'lib/rdoc/store.rb', line 407 def find_file_named name @files_hash[name] end |
#find_module_named(name) ⇒ Object
Finds the module with name
in all discovered modules
414 415 416 |
# File 'lib/rdoc/store.rb', line 414 def find_module_named name @modules_hash[name] end |
#find_text_page(file_name) ⇒ Object
Returns the RDoc::TopLevel that is a text file and has the given file_name
422 423 424 425 426 |
# File 'lib/rdoc/store.rb', line 422 def find_text_page file_name @files_hash.each_value.find do |file| file.text? and file.full_name == file_name end end |
#find_unique(all_hash) ⇒ Object
Finds unique classes/modules defined in all_hash
, and returns them as an array. Performs the alias updates in all_hash
: see ::complete. – TODO aliases should be registered by Context#add_module_alias
435 436 437 438 439 440 441 442 443 |
# File 'lib/rdoc/store.rb', line 435 def find_unique all_hash unique = [] all_hash.each_pair do |full_name, cm| unique << cm if full_name == cm.full_name end unique end |
#fix_basic_object_inheritance ⇒ Object
Fixes the erroneous BasicObject < Object
in 1.9.
Because we assumed all classes without a stated superclass inherit from Object, we have the above wrong inheritance.
We fix BasicObject right away if we are running in a Ruby version >= 1.9. If not, we may be documenting 1.9 source while running under 1.8: we search the files of BasicObject for “object.c”, and fix the inheritance if we find it.
456 457 458 459 460 461 462 463 464 |
# File 'lib/rdoc/store.rb', line 456 def fix_basic_object_inheritance basic = classes_hash['BasicObject'] return unless basic if RUBY_VERSION >= '1.9' basic.superclass = nil elsif basic.in_files.any? { |f| File.basename(f.full_name) == 'object.c' } basic.superclass = nil end end |
#friendly_path ⇒ Object
Friendly rendition of #path
469 470 471 472 473 474 475 476 477 478 479 |
# File 'lib/rdoc/store.rb', line 469 def friendly_path case type when :gem then parent = File. '..', @path "gem #{File.basename parent}" when :home then '~/.rdoc' when :site then 'ruby site' when :system then 'ruby core' else @path end end |
#inspect ⇒ Object
:nodoc:
481 482 483 |
# File 'lib/rdoc/store.rb', line 481 def inspect # :nodoc: "#<%s:0x%x %s %p>" % [self.class, object_id, @path, module_names.sort] end |
#instance_methods ⇒ Object
Instance methods cache accessor. Maps a class to an Array of its instance methods (not full name).
489 490 491 |
# File 'lib/rdoc/store.rb', line 489 def instance_methods @cache[:instance_methods] end |
#load_all ⇒ Object
Loads all items from this store into memory. This recreates a documentation tree for use by a generator
497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 |
# File 'lib/rdoc/store.rb', line 497 def load_all load_cache module_names.each do |module_name| mod = find_class_or_module(module_name) || load_class(module_name) # load method documentation since the loaded class/module does not have # it loaded_methods = mod.method_list.map do |method| load_method module_name, method.full_name end mod.method_list.replace loaded_methods loaded_attributes = mod.attributes.map do |attribute| load_method module_name, attribute.full_name end mod.attributes.replace loaded_attributes end all_classes_and_modules.each do |mod| descendent_re = /^#{mod.full_name}::[^:]+$/ module_names.each do |name| next unless name =~ descendent_re descendent = find_class_or_module name case descendent when RDoc::NormalClass then mod.classes_hash[name] = descendent when RDoc::NormalModule then mod.modules_hash[name] = descendent end end end @cache[:pages].each do |page_name| page = load_page page_name @files_hash[page_name] = page end end |
#load_cache ⇒ Object
Loads cache file for this store
544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 |
# File 'lib/rdoc/store.rb', line 544 def load_cache #orig_enc = @encoding open cache_path, 'rb' do |io| @cache = Marshal.load io.read end load_enc = @cache[:encoding] # TODO this feature will be time-consuming to add: # a) Encodings may be incompatible but transcodeable # b) Need to warn in the appropriate spots, wherever they may be # c) Need to handle cross-cache differences in encodings # d) Need to warn when generating into a cache with different encodings # #if orig_enc and load_enc != orig_enc then # warn "Cached encoding #{load_enc} is incompatible with #{orig_enc}\n" \ # "from #{path}/cache.ri" unless # Encoding.compatible? orig_enc, load_enc #end @encoding = load_enc unless @encoding @cache[:pages] ||= [] @cache[:main] ||= nil @cache[:c_class_variables] ||= {} @cache[:c_singleton_class_variables] ||= {} @cache[:c_class_variables].each do |_, map| map.each do |variable, name| @c_enclosure_names[variable] = name end end @cache rescue Errno::ENOENT end |
#load_class(klass_name) ⇒ Object
Loads ri data for klass_name
and hooks it up to this store.
585 586 587 588 589 590 591 592 593 594 595 596 |
# File 'lib/rdoc/store.rb', line 585 def load_class klass_name obj = load_class_data klass_name obj.store = self case obj when RDoc::NormalClass then @classes_hash[klass_name] = obj when RDoc::NormalModule then @modules_hash[klass_name] = obj end end |
#load_class_data(klass_name) ⇒ Object
Loads ri data for klass_name
601 602 603 604 605 606 607 608 609 610 611 |
# File 'lib/rdoc/store.rb', line 601 def load_class_data klass_name file = class_file klass_name open file, 'rb' do |io| Marshal.load io.read end rescue Errno::ENOENT => e error = MissingFileError.new(self, file, klass_name) error.set_backtrace e.backtrace raise error end |
#load_method(klass_name, method_name) ⇒ Object
Loads ri data for method_name
in klass_name
616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 |
# File 'lib/rdoc/store.rb', line 616 def load_method klass_name, method_name file = method_file klass_name, method_name open file, 'rb' do |io| obj = Marshal.load io.read obj.store = self obj.parent = find_class_or_module(klass_name) || load_class(klass_name) unless obj.parent obj end rescue Errno::ENOENT => e error = MissingFileError.new(self, file, klass_name + method_name) error.set_backtrace e.backtrace raise error end |
#load_page(page_name) ⇒ Object
Loads ri data for page_name
636 637 638 639 640 641 642 643 644 645 646 647 648 |
# File 'lib/rdoc/store.rb', line 636 def load_page page_name file = page_file page_name open file, 'rb' do |io| obj = Marshal.load io.read obj.store = self obj end rescue Errno::ENOENT => e error = MissingFileError.new(self, file, page_name) error.set_backtrace e.backtrace raise error end |
#main ⇒ Object
Gets the main page for this RDoc store. This page is used as the root of the RDoc server.
654 655 656 |
# File 'lib/rdoc/store.rb', line 654 def main @cache[:main] end |
#main=(page) ⇒ Object
Sets the main page for this RDoc store.
661 662 663 |
# File 'lib/rdoc/store.rb', line 661 def main= page @cache[:main] = page end |
#make_variable_map(variables) ⇒ Object
Converts the variable => ClassModule map variables
from a C parser into a variable => class name map.
669 670 671 672 673 674 675 676 677 |
# File 'lib/rdoc/store.rb', line 669 def make_variable_map variables map = {} variables.each { |variable, class_module| map[variable] = class_module.full_name } map end |
#method_file(klass_name, method_name) ⇒ Object
Path to the ri data for method_name
in klass_name
682 683 684 685 686 687 688 689 690 691 692 693 694 695 |
# File 'lib/rdoc/store.rb', line 682 def method_file klass_name, method_name method_name = method_name.split('::').last method_name =~ /#(.*)/ method_type = $1 ? 'i' : 'c' method_name = $1 if $1 method_name = if ''.respond_to? :ord then method_name.gsub(/\W/) { "%%%02x" % $&[0].ord } else method_name.gsub(/\W/) { "%%%02x" % $&[0] } end File.join class_path(klass_name), "#{method_name}-#{method_type}.ri" end |
#module_names ⇒ Object
Modules cache accessor. An Array of all the module (and class) names in the store.
701 702 703 |
# File 'lib/rdoc/store.rb', line 701 def module_names @cache[:modules] end |
#modules_hash ⇒ Object
Hash of all modules known to RDoc
708 709 710 |
# File 'lib/rdoc/store.rb', line 708 def modules_hash @modules_hash end |
#page(name) ⇒ Object
Returns the RDoc::TopLevel that is a text file and has the given name
715 716 717 718 719 |
# File 'lib/rdoc/store.rb', line 715 def page name @files_hash.each_value.find do |file| file.text? and file.page_name == name end end |
#page_file(page_name) ⇒ Object
Path to the ri data for page_name
724 725 726 727 728 |
# File 'lib/rdoc/store.rb', line 724 def page_file page_name file_name = File.basename(page_name).gsub('.', '_') File.join @path, File.dirname(page_name), "page-#{file_name}.ri" end |
#remove_nodoc(all_hash) ⇒ Object
Removes from all_hash
the contexts that are nodoc or have no content.
See RDoc::Context#remove_from_documentation?
735 736 737 738 739 740 |
# File 'lib/rdoc/store.rb', line 735 def remove_nodoc all_hash all_hash.keys.each do |name| context = all_hash[name] all_hash.delete(name) if context.remove_from_documentation? end end |
#save ⇒ Object
Saves all entries in the store
745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 |
# File 'lib/rdoc/store.rb', line 745 def save load_cache all_classes_and_modules.each do |klass| save_class klass klass.each_method do |method| save_method klass, method end klass.each_attribute do |attribute| save_method klass, attribute end end all_files.each do |file| save_page file end save_cache end |
#save_cache ⇒ Object
Writes the cache file for this store
770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 |
# File 'lib/rdoc/store.rb', line 770 def save_cache clean_cache_collection @cache[:ancestors] clean_cache_collection @cache[:attributes] clean_cache_collection @cache[:class_methods] clean_cache_collection @cache[:instance_methods] @cache[:modules].uniq! @cache[:modules].sort! @cache[:pages].uniq! @cache[:pages].sort! @cache[:encoding] = @encoding # this gets set twice due to assert_cache @cache[:c_class_variables].merge! @c_class_variables @cache[:c_singleton_class_variables].merge! @c_singleton_class_variables return if @dry_run marshal = Marshal.dump @cache open cache_path, 'wb' do |io| io.write marshal end end |
#save_class(klass) ⇒ Object
Writes the ri data for klass
(or module)
799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 |
# File 'lib/rdoc/store.rb', line 799 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 |
#save_method(klass, method) ⇒ Object
Writes the ri data for method
on klass
875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 |
# File 'lib/rdoc/store.rb', line 875 def save_method klass, method full_name = klass.full_name FileUtils.mkdir_p class_path(full_name) unless @dry_run cache = if method.singleton then @cache[:class_methods] else @cache[:instance_methods] end cache[full_name] ||= [] cache[full_name] << method.name return if @dry_run marshal = Marshal.dump method open method_file(full_name, method.full_name), 'wb' do |io| io.write marshal end end |
#save_page(page) ⇒ Object
Writes the ri data for page
900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 |
# File 'lib/rdoc/store.rb', line 900 def save_page page return unless page.text? path = page_file page.full_name FileUtils.mkdir_p File.dirname(path) unless @dry_run cache[:pages] ||= [] cache[:pages] << page.full_name return if @dry_run marshal = Marshal.dump page open path, 'wb' do |io| io.write marshal end end |
#source ⇒ Object
Source of the contents of this store.
For a store from a gem the source is the gem name. For a store from the home directory the source is “home”. For system ri store (the standard library documentation) the source is“ruby”. For a store from the site ri directory the store is “site”. For other stores the source is the #path.
928 929 930 931 932 933 934 935 936 |
# File 'lib/rdoc/store.rb', line 928 def source case type when :gem then File.basename File. '..', @path when :home then 'home' when :site then 'site' when :system then 'ruby' else @path end end |
#title ⇒ Object
Gets the title for this RDoc store. This is used as the title in each page on the RDoc server
942 943 944 |
# File 'lib/rdoc/store.rb', line 942 def title @cache[:title] end |
#title=(title) ⇒ Object
Sets the title page for this RDoc store.
949 950 951 |
# File 'lib/rdoc/store.rb', line 949 def title= title @cache[:title] = title end |
#unique_classes ⇒ Object
Returns the unique classes discovered by RDoc.
::complete must have been called prior to using this method.
958 959 960 |
# File 'lib/rdoc/store.rb', line 958 def unique_classes @unique_classes end |
#unique_classes_and_modules ⇒ Object
Returns the unique classes and modules discovered by RDoc. ::complete must have been called prior to using this method.
966 967 968 |
# File 'lib/rdoc/store.rb', line 966 def unique_classes_and_modules @unique_classes + @unique_modules end |
#unique_modules ⇒ Object
Returns the unique modules discovered by RDoc. ::complete must have been called prior to using this method.
974 975 976 |
# File 'lib/rdoc/store.rb', line 974 def unique_modules @unique_modules end |