Class | RDoc::Context |
In: |
code_objects.rb
|
Parent: | CodeObject |
aliases | [R] | |
attributes | [R] | |
constants | [R] | |
in_files | [R] | |
includes | [R] | |
method_list | [R] | |
name | [R] | |
requires | [R] | |
sections | [R] | |
visibility | [R] |
# File code_objects.rb, line 163 163: def initialize 164: super() 165: 166: @in_files = [] 167: 168: @name ||= "unknown" 169: @comment ||= "" 170: @parent = nil 171: @visibility = :public 172: 173: @current_section = Section.new(nil, nil) 174: @sections = [ @current_section ] 175: 176: initialize_methods_etc 177: initialize_classes_and_modules 178: end
# File code_objects.rb, line 247 247: def add_alias(an_alias, ignore_case=nil) 248: meth = find_instance_method_named(an_alias.old_name, ignore_case) 249: if meth 250: new_meth = AnyMethod.new(an_alias.text, an_alias.new_name) 251: new_meth.is_alias_for = meth 252: new_meth.singleton = meth.singleton 253: new_meth.params = meth.params 254: new_meth.comment = "Alias for \##{meth.name}" 255: meth.add_alias(new_meth) 256: add_method(new_meth) 257: else 258: add_to(@aliases, an_alias) 259: end 260: end
# File code_objects.rb, line 243 243: def add_attribute(an_attribute) 244: add_to(@attributes, an_attribute) 245: end
# File code_objects.rb, line 229 229: def add_class(class_type, name, superclass) 230: add_class_or_module(@classes, class_type, name, superclass) 231: end
# File code_objects.rb, line 279 279: def add_class_or_module(collection, class_type, name, superclass=nil) 280: cls = collection[name] 281: if cls 282: puts "Reusing class/module #{name}" if $DEBUG 283: else 284: cls = class_type.new(name, superclass) 285: puts "Adding class/module #{name} to #@name" if $DEBUG 286: # collection[name] = cls if @document_self && !@done_documenting 287: collection[name] = cls if !@done_documenting 288: cls.parent = self 289: cls.section = @current_section 290: end 291: cls 292: end
# File code_objects.rb, line 266 266: def add_constant(const) 267: add_to(@constants, const) 268: end
# File code_objects.rb, line 262 262: def add_include(an_include) 263: add_to(@includes, an_include) 264: end
# File code_objects.rb, line 237 237: def add_method(a_method) 238: puts "Adding #@visibility method #{a_method.name} to #@name" if $DEBUG 239: a_method.visibility = @visibility 240: add_to(@method_list, a_method) 241: end
# File code_objects.rb, line 233 233: def add_module(class_type, name) 234: add_class_or_module(@modules, class_type, name, nil) 235: end
Requires always get added to the top-level (file) context
# File code_objects.rb, line 271 271: def add_require(a_require) 272: if self.kind_of? TopLevel 273: add_to(@requires, a_require) 274: else 275: parent.add_require(a_require) 276: end 277: end
# File code_objects.rb, line 294 294: def add_to(array, thing) 295: array << thing if @document_self && !@done_documenting 296: thing.parent = self 297: thing.section = @current_section 298: end
map the class hash to an array externally
# File code_objects.rb, line 181 181: def classes 182: @classes.values 183: end
Return true if at least part of this thing was defined in file
# File code_objects.rb, line 225 225: def defined_in?(file) 226: @in_files.include?(file) 227: end
# File code_objects.rb, line 370 370: def each_attribute 371: @attributes.each {|a| yield a} 372: end
find a module at a higher scope
# File code_objects.rb, line 354 354: def find_enclosing_module_named(name, ignore_case=nil) 355: parent && parent.find_module_named(name, ignore_case) 356: end
Look up the given filename.
# File code_objects.rb, line 397 397: def find_file(file, method=nil, ignore_case=nil) 398: find_file_named(file, method, ignore_case) 399: end
# File code_objects.rb, line 450 450: def find_local_symbol(symbol, ignore_case=nil) 451: res = find_method_named(symbol, ignore_case) || 452: find_constant_named(symbol, ignore_case) || 453: find_attribute_named(symbol, ignore_case) || 454: find_module_named(symbol, ignore_case) 455: end
Find a named module
# File code_objects.rb, line 328 328: def find_module_named(name, ignore_case=nil) 329: res = nil 330: if !ignore_case 331: return self if self.name == name 332: else 333: return self if self.name.upcase == name.upcase 334: end 335: if !ignore_case 336: res = @modules[name] || @classes[name] 337: else 338: @modules.each{ |n, v| 339: if n.upcase == name.upcase 340: res = v ; break 341: end 342: } 343: @classes.each{ |n, v| 344: if n.upcase == name.upcase 345: res = v ; break 346: end 347: } if !res 348: end 349: return res if res 350: find_enclosing_module_named(name, ignore_case) 351: end
Look up the given symbol. If method is non-nil, then we assume the symbol references a module that contains that method
# File code_objects.rb, line 404 404: def find_symbol(symbol, method=nil, ignore_case=nil) 405: result = nil 406: case symbol 407: when /^::(.*)/ 408: result = toplevel.find_symbol($1, nil, ignore_case) 409: when /::/ 410: modules = symbol.split(/::/) 411: unless modules.empty? 412: module_name = modules.shift 413: result = find_module_named(module_name, ignore_case) 414: if result 415: modules.each do |module_name| 416: result = result.find_module_named(module_name, ignore_case) 417: break unless result 418: end 419: end 420: end 421: else 422: # if a method is specified, then we're definitely looking for 423: # a module, otherwise it could be any symbol 424: if method 425: result = find_module_named(symbol, ignore_case) 426: else 427: result = find_local_symbol(symbol, ignore_case) 428: if result.nil? 429: if symbol =~ /^[A-Z]/ || 430: symbol =~ /^[A-Za-z]/ && ignore_case 431: result = parent 432: while result && result.name != symbol 433: result = result.parent 434: end 435: end 436: end 437: end 438: end 439: if result && method 440: if !result.respond_to?(:find_local_symbol) 441: p result.name 442: p method 443: fail 444: end 445: result = result.find_local_symbol(method, ignore_case) 446: end 447: result 448: end
# File code_objects.rb, line 471 471: def include_includes?(name, ignore_case=nil) 472: self.includes.each{|i| 473: if i.name == name || 474: i.name.upcase == name.upcase && ignore_case 475: return true 476: end 477: } 478: return false 479: end
# File code_objects.rb, line 457 457: def include_requires?(name, ignore_case=nil) 458: if self.kind_of? TopLevel 459: self.requires.each{|r| 460: if r.name == name || 461: r.name.upcase == name.upcase && ignore_case 462: return true 463: end 464: } 465: return false 466: else 467: parent.include_requires?(name) 468: end 469: end
# File code_objects.rb, line 322 322: def initialize_classes_and_modules 323: @classes = {} 324: @modules = {} 325: end
# File code_objects.rb, line 308 308: def initialize_methods_etc 309: @method_list = [] 310: @attributes = [] 311: @aliases = [] 312: @requires = [] 313: @includes = [] 314: @constants = [] 315: end
map the module hash to an array externally
# File code_objects.rb, line 186 186: def modules 187: @modules.values 188: end
Record the file that we happen to find it in
# File code_objects.rb, line 220 220: def record_location(toplevel) 221: @in_files << toplevel unless @in_files.include?(toplevel) 222: end
If a class‘s documentation is turned off after we‘ve started collecting methods etc., we need to remove the ones we have
# File code_objects.rb, line 304 304: def remove_methods_etc 305: initialize_methods_etc 306: end
Handle sections
# File code_objects.rb, line 483 483: def set_current_section(title, comment) 484: @current_section = Section.new(title, comment) 485: @sections << @current_section 486: end
Given an array methods of method names, set the visibility of the corresponding AnyMethod object
# File code_objects.rb, line 198 198: def set_visibility_for(methods, vis, singleton=false) 199: count = 0 200: @method_list.each do |m| 201: if methods.include?(m.name) && m.singleton == singleton 202: m.visibility = vis 203: count += 1 204: end 205: end 206: 207: return if count == methods.size || singleton 208: 209: # perhaps we need to look at attributes 210: 211: @attributes.each do |a| 212: if methods.include?(a.name) 213: a.visibility = vis 214: count += 1 215: end 216: end 217: end