2017-11-27 13:45:24 +03:00
|
|
|
# frozen_string_literal: true
|
2010-04-01 11:45:16 +04:00
|
|
|
##
|
|
|
|
# Represent an alias, which is an old_name/new_name pair associated with a
|
|
|
|
# particular context
|
2010-12-20 06:22:49 +03:00
|
|
|
#--
|
|
|
|
# TODO implement Alias as a proxy to a method/attribute, inheriting from
|
|
|
|
# MethodAttr
|
2010-04-01 11:45:16 +04:00
|
|
|
|
|
|
|
class RDoc::Alias < RDoc::CodeObject
|
|
|
|
|
|
|
|
##
|
2010-12-20 06:22:49 +03:00
|
|
|
# Aliased method's name
|
2010-04-01 11:45:16 +04:00
|
|
|
|
2010-12-20 06:22:49 +03:00
|
|
|
attr_reader :new_name
|
|
|
|
|
|
|
|
alias name new_name
|
2010-04-01 11:45:16 +04:00
|
|
|
|
|
|
|
##
|
2010-12-20 06:22:49 +03:00
|
|
|
# Aliasee method's name
|
2010-04-01 11:45:16 +04:00
|
|
|
|
2010-12-20 06:22:49 +03:00
|
|
|
attr_reader :old_name
|
2010-04-01 11:45:16 +04:00
|
|
|
|
|
|
|
##
|
2010-12-20 06:22:49 +03:00
|
|
|
# Is this an alias declared in a singleton context?
|
2010-04-01 11:45:16 +04:00
|
|
|
|
2010-12-20 06:22:49 +03:00
|
|
|
attr_accessor :singleton
|
2010-04-01 11:45:16 +04:00
|
|
|
|
|
|
|
##
|
|
|
|
# Source file token stream
|
|
|
|
|
2010-12-20 06:22:49 +03:00
|
|
|
attr_reader :text
|
2010-04-01 11:45:16 +04:00
|
|
|
|
|
|
|
##
|
|
|
|
# Creates a new Alias with a token stream of +text+ that aliases +old_name+
|
2010-12-20 06:22:49 +03:00
|
|
|
# to +new_name+, has +comment+ and is a +singleton+ context.
|
2010-04-01 11:45:16 +04:00
|
|
|
|
2010-12-20 06:22:49 +03:00
|
|
|
def initialize(text, old_name, new_name, comment, singleton = false)
|
2010-04-01 11:45:16 +04:00
|
|
|
super()
|
2010-12-20 06:22:49 +03:00
|
|
|
|
2010-04-01 11:45:16 +04:00
|
|
|
@text = text
|
2010-12-20 06:22:49 +03:00
|
|
|
@singleton = singleton
|
2010-04-01 11:45:16 +04:00
|
|
|
@old_name = old_name
|
|
|
|
@new_name = new_name
|
|
|
|
self.comment = comment
|
|
|
|
end
|
|
|
|
|
2010-12-20 06:22:49 +03:00
|
|
|
##
|
|
|
|
# Order by #singleton then #new_name
|
|
|
|
|
|
|
|
def <=>(other)
|
|
|
|
[@singleton ? 0 : 1, new_name] <=> [other.singleton ? 0 : 1, other.new_name]
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# HTML fragment reference for this alias
|
|
|
|
|
|
|
|
def aref
|
|
|
|
type = singleton ? 'c' : 'i'
|
|
|
|
"#alias-#{type}-#{html_name}"
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Full old name including namespace
|
|
|
|
|
|
|
|
def full_old_name
|
|
|
|
@full_name || "#{parent.name}#{pretty_old_name}"
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# HTML id-friendly version of +#new_name+.
|
|
|
|
|
|
|
|
def html_name
|
|
|
|
CGI.escape(@new_name.gsub('-', '-2D')).gsub('%','-').sub(/^-/, '')
|
|
|
|
end
|
|
|
|
|
2010-04-01 11:45:16 +04:00
|
|
|
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
|
|
|
|
|
2010-12-20 06:22:49 +03:00
|
|
|
##
|
|
|
|
# '::' for the alias of a singleton method/attribute, '#' for instance-level.
|
|
|
|
|
|
|
|
def name_prefix
|
|
|
|
singleton ? '::' : '#'
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Old name with prefix '::' or '#'.
|
|
|
|
|
|
|
|
def pretty_old_name
|
|
|
|
"#{singleton ? '::' : '#'}#{@old_name}"
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# New name with prefix '::' or '#'.
|
|
|
|
|
|
|
|
def pretty_new_name
|
|
|
|
"#{singleton ? '::' : '#'}#{@new_name}"
|
|
|
|
end
|
|
|
|
|
|
|
|
alias pretty_name pretty_new_name
|
|
|
|
|
2010-04-01 11:45:16 +04:00
|
|
|
def to_s # :nodoc:
|
2010-12-20 06:22:49 +03:00
|
|
|
"alias: #{self.new_name} -> #{self.pretty_old_name} in: #{parent}"
|
2010-04-01 11:45:16 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|