module YARDSorbet::TagUtils
Helper methods for working with `YARD` tags
Public Class Methods
find_tag(docstring, tag_name, name)
click to toggle source
# File lib/yard-sorbet/tag_utils.rb, line 14 def self.find_tag(docstring, tag_name, name) docstring.tags.find { |t| t.tag_name == tag_name && t.name == name } end
upsert_tag(docstring, tag_name, types = nil, name = nil, text = '')
click to toggle source
# File lib/yard-sorbet/tag_utils.rb, line 28 def self.upsert_tag(docstring, tag_name, types = nil, name = nil, text = '') tag = find_tag(docstring, tag_name, name) if tag return unless types # Updating a tag in place doesn't seem to work, so we'll delete it, add the types, and re-add it docstring.delete_tag_if { |t| t == tag } # overwrite any existing type annotation (sigs should win) tag.types = types tag.text = text unless text.empty? else tag = YARD::Tags::Tag.new(tag_name, text, types, name) end docstring.add_tag(tag) end