lib/yard/handlers/ruby/struct_handler_methods.rb in yard-0.6.8 vs lib/yard/handlers/ruby/struct_handler_methods.rb in yard-0.7.0
- old
+ new
@@ -1,11 +1,11 @@
# Helper methods to parse @attr_* tags on a class.
-#
+#
# @since 0.5.6
module YARD::Handlers::Ruby::StructHandlerMethods
include YARD::CodeObjects
-
+
# Extracts the user's defined @member tag for a given class and its member. Returns
# nil if the user did not define a @member tag for this struct entry.
#
# @param [ClassObject] klass the class whose tags we're searching
# @param [String] member the name of the struct member we need
@@ -15,18 +15,18 @@
specific_tag = type == :read ? :attr_reader : :attr_writer
(klass.tags(specific_tag) + klass.tags(:attr)).find {|tag| tag.name == member}
end
# Retrieves all members defined in @attr* tags
- #
+ #
# @param [ClassObject] klass the class with the attributes
# @return [Array<String>] the list of members defined as attributes on the class
def members_from_tags(klass)
tags = klass.tags(:attr) + klass.tags(:attr_reader) + klass.tags(:attr_writer)
tags.map {|t| t.name }.uniq
end
-
+
# Determines whether to create an attribute method based on the class's
# tags.
#
# @param [ClassObject] klass the class whose tags we're searching
# @param [String] member the name of the struct member we need
@@ -36,22 +36,22 @@
return true if (klass.tags(:attr) + klass.tags(:attr_reader) + klass.tags(:attr_writer)).empty?
return true if member_tag_for_member(klass, member, type)
return !member_tag_for_member(klass, member, :write) if type == :read
return !member_tag_for_member(klass, member, :read)
end
-
+
# Gets the return type for the member in a nicely formatted string. Used
# to be injected into auto-generated docstrings.
#
# @param [ClassObject] klass the class whose tags we're searching
# @param [String] member the name of the struct member whose return type we need
# @return [String] the user-declared type of the struct member, or [Object] if
# the user did not define a type for this member.
def return_type_from_tag(member_tag)
(member_tag && member_tag.types) ? member_tag.types : "Object"
end
-
+
# Creates the auto-generated docstring for the getter method of a struct's
# member. This is used so the generated documentation will look just like that
# of an attribute defined using attr_accessor.
#
# @param [ClassObject] klass the class whose members we're working with
@@ -62,11 +62,11 @@
return_type = return_type_from_tag(member_tag)
getter_doc_text = member_tag ? member_tag.text : "Returns the value of attribute #{member}"
new_method.docstring.replace(getter_doc_text)
new_method.docstring.add_tag YARD::Tags::Tag.new(:return, "the current value of #{member}", return_type)
end
-
+
# Creates the auto-generated docstring for the setter method of a struct's
# member. This is used so the generated documentation will look just like that
# of an attribute defined using attr_accessor.
#
# @param [ClassObject] klass the class whose members we're working with
@@ -78,11 +78,11 @@
setter_doc_text = member_tag ? member_tag.text : "Sets the attribute #{member}"
new_method.docstring.replace(setter_doc_text)
new_method.docstring.add_tag YARD::Tags::Tag.new(:param, "the value to set the attribute #{member} to.", return_type, "value")
new_method.docstring.add_tag YARD::Tags::Tag.new(:return, "the newly set value", return_type)
end
-
+
# Creates and registers a class object with the given name and superclass name.
# Returns it for further use.
#
# @param [String] classname the name of the class
# @param [String] superclass the name of the superclass
@@ -91,11 +91,11 @@
register ClassObject.new(namespace, classname) do |o|
o.superclass = superclass if superclass
o.superclass.type = :class if o.superclass.is_a?(Proxy)
end
end
-
+
# Creates the setter (writer) method and attaches it to the class as an attribute.
# Also sets up the docstring to prettify the documentation output.
#
# @param [ClassObject] klass the class to attach the method to
# @param [String] member the name of the member we're generating a method for
@@ -108,11 +108,11 @@
o.source ||= "#{o.signature}\n @#{member} = value\nend"
end
add_writer_tags(klass, new_meth, member)
klass.attributes[:instance][member][:write] = new_meth
end
-
+
# Creates the getter (reader) method and attaches it to the class as an attribute.
# Also sets up the docstring to prettify the documentation output.
#
# @param [ClassObject] klass the class to attach the method to
# @param [String] member the name of the member we're generating a method for
@@ -122,10 +122,10 @@
o.source ||= "#{o.signature}\n @#{member}\nend"
end
add_reader_tags(klass, new_meth, member)
klass.attributes[:instance][member][:read] = new_meth
end
-
+
# Creates the given member methods and attaches them to the given ClassObject.
#
# @param [ClassObject] klass the class to generate attributes for
# @param [Array<String>] members a list of member names
def create_attributes(klass, members)
\ No newline at end of file