Class: YARD::APIPlugin::Tags::ArgumentTag
- Inherits:
-
Tags::Tag
- Object
- Tags::Tag
- YARD::APIPlugin::Tags::ArgumentTag
- Defined in:
- lib/yard-api/tags/argument_tag.rb
Constant Summary collapse
- RE_NAME =
/^([\S]+)/- RE_ARRAY_LITERAL =
/\[[^\]]+\]/- RE_ARRAY_TYPE =
/^#{RE_ARRAY_LITERAL}$/- RE_REQUIRED_OPTIONAL =
/required|optional/i- RE_ACCEPTED_VALUES_PREFIXES =
/ accepted\svalues | accepts | possible\svalues /imx- RE_ACCEPTED_VALUES_STR =
/ #{RE_ACCEPTED_VALUES_PREFIXES}:\s*(#{RE_ARRAY_LITERAL}) /mx
Instance Attribute Summary collapse
-
#accepted_values ⇒ Object
readonly
Returns the value of attribute accepted_values.
-
#is_required ⇒ Object
readonly
Returns the value of attribute is_required.
Instance Method Summary collapse
-
#initialize(name, buf) ⇒ ArgumentTag
constructor
A new instance of ArgumentTag.
Constructor Details
#initialize(name, buf) ⇒ ArgumentTag
Returns a new instance of ArgumentTag.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/yard-api/tags/argument_tag.rb', line 20 def initialize(name, buf) name = nil # If the name specifier is written before the types and contains brackets, # YARD will not properly parse the attributes (it doesn't even say that it # supports this syntax so), something like this: # # @argument shirt[size] [String] # # We convert the name to use underscores instead and YARD does its magic! # Once the tag is parsed, we'll use the original name. # # @since 0.1.7 if buf[0] != '[' && YARD::APIPlugin..leading_argument_name_fix arg_name = buf.match(RE_NAME).captures.first buf.sub!(arg_name, arg_name.gsub(/\W/, '_')) name = arg_name end YARD::Tags::Library.instance.tag_create(:attr, buf).tap do |tag| super(:argument, tag.text, tag.types, name || tag.name) @types ||= [] @text ||= '' @is_required = parse_is_required(@types) @accepted_values = parse_accepted_values(@types, @text) end end |
Instance Attribute Details
#accepted_values ⇒ Object (readonly)
Returns the value of attribute accepted_values.
5 6 7 |
# File 'lib/yard-api/tags/argument_tag.rb', line 5 def accepted_values @accepted_values end |
#is_required ⇒ Object (readonly)
Returns the value of attribute is_required.
5 6 7 |
# File 'lib/yard-api/tags/argument_tag.rb', line 5 def is_required @is_required end |