Class: RDoc::Alias

Inherits:
CodeObject show all
Defined in:
lib/rdoc/alias.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::MARKUP_FORMAT, 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, #store, #viewer

Instance Method Summary collapse

Methods inherited from CodeObject

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

Methods included from Generator::Markup

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

Methods included from Text

encode_fallback, #expand_tabs, #flush_left, #markup, #normalize_comment, #parse, #snippet, #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.


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

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


13
14
15
# File 'lib/rdoc/alias.rb', line 13

def new_name
  @new_name
end

#old_nameObject (readonly)

Aliasee method's name


20
21
22
# File 'lib/rdoc/alias.rb', line 20

def old_name
  @old_name
end

#singletonObject

Is this an alias declared in a singleton context?


25
26
27
# File 'lib/rdoc/alias.rb', line 25

def singleton
  @singleton
end

#textObject (readonly)

Source file token stream


30
31
32
# File 'lib/rdoc/alias.rb', line 30

def text
  @text
end

Instance Method Details

#<=>(other) ⇒ Object

Order by #singleton then #new_name


49
50
51
# File 'lib/rdoc/alias.rb', line 49

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

#arefObject

HTML fragment reference for this alias


56
57
58
59
# File 'lib/rdoc/alias.rb', line 56

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

#full_old_nameObject

Full old name including namespace


64
65
66
# File 'lib/rdoc/alias.rb', line 64

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

#html_nameObject

HTML id-friendly version of #new_name.


71
72
73
# File 'lib/rdoc/alias.rb', line 71

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

#inspectObject

:nodoc:


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

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.


86
87
88
# File 'lib/rdoc/alias.rb', line 86

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

#pretty_new_nameObject Also known as: pretty_name

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


100
101
102
# File 'lib/rdoc/alias.rb', line 100

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

#pretty_old_nameObject

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


93
94
95
# File 'lib/rdoc/alias.rb', line 93

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

#to_sObject

:nodoc:


106
107
108
# File 'lib/rdoc/alias.rb', line 106

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