Class: RDoc::Alias

Inherits:
CodeObject show all
Includes:
Generator::Markup
Defined in:
lib/rdoc/alias.rb,
lib/rdoc/generator/markup.rb

Overview

Represent an alias, which is an old_name/new_name pair associated with a particular context -- TODO implement Alias as a proxy to a method/attribute, inheriting from

MethodAttr

Constant Summary

Constants included from Text

Text::TO_HTML_CHARACTERS

Instance Attribute Summary collapse

Attributes inherited from CodeObject

#comment, #document_children, #document_self, #done_documenting, #file, #force_documentation, #line, #metadata, #offset, #parent, #received_nodoc, #section, #viewer

Instance Method Summary collapse

Methods included from Generator::Markup

#aref_to, #as_href, #cvs_url, #description, #formatter

Methods inherited from CodeObject

#display?, #documented?, #each_parent, #file_name, #full_name=, #ignore, #ignored?, #parent_file_name, #parent_name, #record_location, #start_doc, #stop_doc

Methods included from Text

encode_fallback, #expand_tabs, #flush_left, #markup, #normalize_comment, #parse, #strip_hashes, #strip_newlines, #strip_stars, #to_html, #wrap

Constructor Details

#initialize(text, old_name, new_name, comment, singleton = false) ⇒ Alias

Creates a new Alias with a token stream of text that aliases old_name to new_name, has comment and is a singleton context.



38
39
40
41
42
43
44
45
46
# File 'lib/rdoc/alias.rb', line 38

def initialize(text, old_name, new_name, comment, singleton = false)
  super()

  @text = text
  @singleton = singleton
  @old_name = old_name
  @new_name = new_name
  self.comment = comment
end

Instance Attribute Details

#new_nameObject (readonly) Also known as: name

Aliased method's name



15
16
17
# File 'lib/rdoc/alias.rb', line 15

def new_name
  @new_name
end

#old_nameObject (readonly)

Aliasee method's name



22
23
24
# File 'lib/rdoc/alias.rb', line 22

def old_name
  @old_name
end

#singletonObject

Is this an alias declared in a singleton context?



27
28
29
# File 'lib/rdoc/alias.rb', line 27

def singleton
  @singleton
end

#textObject (readonly)

Source file token stream



32
33
34
# File 'lib/rdoc/alias.rb', line 32

def text
  @text
end

Instance Method Details

#<=>(other) ⇒ Object

Order by #singleton then #new_name



51
52
53
# File 'lib/rdoc/alias.rb', line 51

def <=>(other)
  [@singleton ? 0 : 1, new_name] <=> [other.singleton ? 0 : 1, other.new_name]
end

#arefObject

HTML fragment reference for this alias



58
59
60
61
# File 'lib/rdoc/alias.rb', line 58

def aref
  type = singleton ? 'c' : 'i'
  "#alias-#{type}-#{html_name}"
end

#full_old_nameObject

Full old name including namespace



66
67
68
# File 'lib/rdoc/alias.rb', line 66

def full_old_name
  @full_name || "#{parent.name}#{pretty_old_name}"
end

#html_nameObject

HTML id-friendly version of #new_name.



73
74
75
# File 'lib/rdoc/alias.rb', line 73

def html_name
  CGI.escape(@new_name.gsub('-', '-2D')).gsub('%','-').sub(/^-/, '')
end

#inspectObject

:nodoc:



77
78
79
80
81
82
83
# File 'lib/rdoc/alias.rb', line 77

def inspect # :nodoc:
  parent_name = parent ? parent.name : '(unknown)'
  "#<%s:0x%x %s.alias_method %s, %s>" % [
    self.class, object_id,
    parent_name, @old_name, @new_name,
  ]
end

#name_prefixObject

'::' for the alias of a singleton method/attribute, '#' for instance-level.



88
89
90
# File 'lib/rdoc/alias.rb', line 88

def name_prefix
  singleton ? '::' : '#'
end

#pretty_new_nameObject Also known as: pretty_name

New name with prefix '::' or '#'.



102
103
104
# File 'lib/rdoc/alias.rb', line 102

def pretty_new_name
  "#{singleton ? '::' : '#'}#{@new_name}"
end

#pretty_old_nameObject

Old name with prefix '::' or '#'.



95
96
97
# File 'lib/rdoc/alias.rb', line 95

def pretty_old_name
  "#{singleton ? '::' : '#'}#{@old_name}"
end

#to_sObject

:nodoc:



108
109
110
# File 'lib/rdoc/alias.rb', line 108

def to_s # :nodoc:
  "alias: #{self.new_name} -> #{self.pretty_old_name} in: #{parent}"
end