summaryrefslogtreecommitdiff
path: root/lib/rdoc/attr.rb
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-12-20 03:22:49 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-12-20 03:22:49 +0000
commit2ef9c50c6e405717d06362787c4549ca4f1c6485 (patch)
treeee99486567461dd5796f3d6edcc9e204187f2666 /lib/rdoc/attr.rb
parentd7effd506f5b91a636f2e6452ef1946b923007c7 (diff)
Import RDoc 3
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30249 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rdoc/attr.rb')
-rw-r--r--lib/rdoc/attr.rb142
1 files changed, 36 insertions, 106 deletions
diff --git a/lib/rdoc/attr.rb b/lib/rdoc/attr.rb
index 9b8c4562c2..97fac3222d 100644
--- a/lib/rdoc/attr.rb
+++ b/lib/rdoc/attr.rb
@@ -1,104 +1,71 @@
-require 'rdoc/code_object'
+require 'rdoc/method_attr'
##
# An attribute created by \#attr, \#attr_reader, \#attr_writer or
# \#attr_accessor
-class RDoc::Attr < RDoc::CodeObject
+class RDoc::Attr < RDoc::MethodAttr
- MARSHAL_VERSION = 0 # :nodoc:
+ MARSHAL_VERSION = 1 # :nodoc:
##
- # Name of the attribute
-
- attr_accessor :name
-
- ##
- # Is the attribute readable, writable or both?
+ # Is the attribute readable ('R'), writable ('W') or both ('RW')?
attr_accessor :rw
##
- # Source file token stream
+ # Creates a new Attr with body +text+, +name+, read/write status +rw+ and
+ # +comment+. +singleton+ marks this as a class attribute.
- attr_accessor :text
+ def initialize(text, name, rw, comment, singleton = false)
+ super text, name
- ##
- # public, protected, private
-
- attr_accessor :visibility
-
- def initialize(text, name, rw, comment)
- super()
- @text = text
- @name = name
@rw = rw
- @visibility = :public
+ @singleton = singleton
self.comment = comment
end
##
- # Attributes are ordered by name
-
- def <=>(other)
- self.name <=> other.name
- end
-
- ##
- # Attributes are equal when their names and rw is identical
+ # Attributes are equal when their names, singleton and rw are identical
def == other
self.class == other.class and
self.name == other.name and
- self.rw == other.rw
+ self.rw == other.rw and
+ self.singleton == other.singleton
end
##
- # Returns nil, for duck typing with RDoc::AnyMethod
+ # Add +an_alias+ as an attribute in +context+.
- def arglists
- end
-
- ##
- # Returns nil, for duck typing with RDoc::AnyMethod
+ def add_alias(an_alias, context)
+ new_attr = self.class.new(self.text, an_alias.new_name, self.rw,
+ self.comment, self.singleton)
- def block_params
+ new_attr.record_location an_alias.file
+ new_attr.visibility = self.visibility
+ new_attr.is_alias_for = self
+ @aliases << new_attr
+ context.add_attribute new_attr
+ new_attr
end
##
- # Returns nil, for duck typing with RDoc::AnyMethod
+ # The #aref prefix for attributes
- def call_seq
+ def aref_prefix
+ 'attribute'
end
##
- # Partially bogus as Attr has no parent. For duck typing with
- # RDoc::AnyMethod.
+ # Returns attr_reader, attr_writer or attr_accessor as appropriate.
- def full_name
- @full_name ||= "#{@parent ? @parent.full_name : '(unknown)'}##{name}"
- end
-
- ##
- # An HTML id-friendly representation of #name
-
- def html_name
- @name.gsub(/[^a-z]+/, '-')
- end
-
- def inspect # :nodoc:
- attr = case rw
- when 'RW' then :attr_accessor
- when 'R' then :attr_reader
- when 'W' then :attr_writer
- else
- " (#{rw})"
- end
-
- "#<%s:0x%x %s.%s :%s>" % [
- self.class, object_id,
- parent_name, attr, @name,
- ]
+ def definition
+ case @rw
+ when 'RW' then 'attr_accessor'
+ when 'R' then 'attr_reader'
+ when 'W' then 'attr_writer'
+ end
end
##
@@ -111,11 +78,12 @@ class RDoc::Attr < RDoc::CodeObject
@rw,
@visibility,
parse(@comment),
+ singleton,
]
end
##
- # Loads this AnyMethod from +array+. For a loaded AnyMethod the following
+ # Loads this Attr from +array+. For a loaded Attr the following
# methods will return cached values:
#
# * #full_name
@@ -127,51 +95,13 @@ class RDoc::Attr < RDoc::CodeObject
@rw = array[3]
@visibility = array[4]
@comment = array[5]
+ @singleton = array[6] || false # MARSHAL_VERSION == 0
@parent_name = @full_name
end
- ##
- # Name of our parent with special handling for un-marshaled methods
-
- def parent_name
- @parent_name || super
- end
-
- ##
- # For duck typing with RDoc::AnyMethod, returns nil
-
- def params
- nil
- end
-
- ##
- # URL path for this attribute
-
- def path
- "#{@parent.path}##{@name}"
- end
-
- ##
- # For duck typing with RDoc::AnyMethod
-
- def singleton
- false
- end
-
def to_s # :nodoc:
- "#{type} #{name}\n#{comment}"
- end
-
- ##
- # Returns attr_reader, attr_writer or attr_accessor as appropriate
-
- def type
- case @rw
- when 'RW' then 'attr_accessor'
- when 'R' then 'attr_reader'
- when 'W' then 'attr_writer'
- end
+ "#{definition} #{name} in: #{parent}"
end
end