lib/yard/handlers/ruby/struct_handler_methods.rb in yard-0.9.5 vs lib/yard/handlers/ruby/struct_handler_methods.rb in yard-0.9.6
- old
+ new
@@ -1,5 +1,6 @@
+# frozen_string_literal: true
# Helper methods to parse @attr_* tags on a class.
#
# @deprecated The use of +@attr+ tags are deprecated since 0.8.0 in favour of
# the +@!attribute+ directive. This module should not be relied on.
# @since 0.5.6
@@ -13,20 +14,20 @@
# @param [String] member the name of the struct member we need
# @param [Symbol] type reader method, or writer method?
# @return [Tags::Tag, nil] the tag matching the request, or nil if not found
def member_tag_for_member(klass, member, type = :read)
specific_tag = type == :read ? :attr_reader : :attr_writer
- (klass.tags(specific_tag) + klass.tags(:attr)).find {|tag| tag.name == member}
+ (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
+ tags.map(&:name).uniq
end
# Determines whether to create an attribute method based on the class's
# tags.
#
@@ -36,20 +37,20 @@
# @return [Boolean] should the attribute be created?
def create_member_method?(klass, member, type = :read)
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)
+ !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 [Tags::Tag] member_tag the tag object to check for types
# @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"
+ 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.