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, #parent, #received_nodoc, #section, #store, #viewer

Attributes included from Text

#language

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.



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

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



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

def new_name
  @new_name
end

#old_nameObject (readonly)

Aliasee method’s name



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

def old_name
  @old_name
end

#singletonObject

Is this an alias declared in a singleton context?



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

def singleton
  @singleton
end

#textObject (readonly)

Source file token stream



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

def text
  @text
end

Instance Method Details

#<=>(other) ⇒ Object

Order by #singleton then #new_name



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

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

#arefObject

HTML fragment reference for this alias



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

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

#full_old_nameObject

Full old name including namespace



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

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

#html_nameObject

HTML id-friendly version of #new_name.



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

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

#inspectObject

:nodoc:



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

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.



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

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

#pretty_new_nameObject Also known as: pretty_name

New name with prefix ‘::’ or ‘#’.



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

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

#pretty_old_nameObject

Old name with prefix ‘::’ or ‘#’.



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

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

#to_sObject

:nodoc:



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

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