class YARD::Tags::Library

Experimental RBS support (using type sampling data from the type_fusion project).

# sig/yard/tags/library.rbs

class YARD::Tags::Library
  def tag_or_directive_method_name: (Symbol tag_name, ?String type) -> String
end

@see Directive
@see define_directive
@see define_tag
@see DefaultFactory
define_directive :method, :with_title_and_text, MethodDirective
@example Defining a custom directive
define_tag “Author”, :author
define_tag “Parameter”, :param, :with_types_and_name
@example Defining a custom tag
if you want to change the syntax of existing tags (@see, @since, etc.)
to a new class with its own parsing methods before running YARD. This is useful
object with your own by setting {Library.default_factory= Library.default_factory}
If you have specialized tag parsing needs you can substitute the {#factory}
== Adding/Changing the Tag Syntax
collide with other plugins or new built-in tags.
to namespace project specific tags, like +@yard.tag_name+, so that tags do not
In YARD 0.8.0+, tags can be namespaced using the ‘.’ character. It is recommended
== Namespaced Tags
end
MyDirective.new(tag, parser)
def mydirective_directive(tag, parser)
the method name “mydirective_directive” and returning a new {Directive} object:
Similar to tags, Directives can also be defined manually, in this case using
Directive subclass, see the {Directive} class documentation.
that performs the directive processing. For more information on creating a
data in the directive into a temporary {Tag} object) and a {Directive} subclass
the directive name, an optional tag factory parser method (to parse the
Directives can be defined by calling the {define_directive} method, taking
== Defining Custom Directives
end
Tag.new(:mytag, text)
def mytag_tag(text)
parsing:
method that returns a {Tag} object, but they will not take advantage of tag factory
You can also define tag objects manually by simply implementing a “tagname_tag”
provide a factory method to use, it will default to {DefaultFactory#parse_tag}
name and the factory method to use when creating the tag. If you do not
To define a custom tag, use {define_tag}. You should pass the tag
== Defining Custom Meta-Data Tags
syntax.
Also allows for defining of custom tags and customizing the tag parsing
Keeps track of all the registered meta-data tags and directives.

def default_factory

Other tags:
    See: DefaultFactory -
def default_factory
  @default_factory ||= DefaultFactory.new
end

def default_factory=(factory)

def default_factory=(factory)
  @default_factory = factory.is_a?(Class) ? factory.new : factory
end

def define_directive(tag, tag_meth = nil, directive_class = nil)

Other tags:
    See: define_tag -

Parameters:
  • the (Class) -- directive class that implements the
  • tag_meth (#to_s) -- the tag factory method to use when
  • tag (#to_s) -- the tag name of the directive

Overloads:
  • define_directive(tag, tag_meth = nil, directive_class)
def define_directive(tag, tag_meth = nil, directive_class = nil)
  directive_meth = directive_method_name(tag)
  if directive_class.nil?
    directive_class = tag_meth
    tag_meth = nil
  end
  class_eval <<-eof, __FILE__, __LINE__
    def #{directive_meth}(tag, parser)
      directive_call(tag, parser)
    end
  eof
  @factory_methods ||= SymbolHash.new(false)
  @factory_methods.update(tag => tag_meth)
  @directive_factory_classes ||= SymbolHash.new(false)
  @directive_factory_classes.update(tag => directive_class)
  tag
end

def define_tag(label, tag, meth = nil)

Parameters:
  • meth (#to_s, Class) -- the {Tag} factory method to call when
  • tag (#to_s) -- the tag name to create
  • label (#to_s) -- the label used when displaying the tag in templates
def define_tag(label, tag, meth = nil)
  tag_meth = tag_method_name(tag)
  if meth.is_a?(Class) && Tag > meth
    class_eval(<<-eof, __FILE__, __LINE__ + 1)
      def #{tag_meth}(text)
        #{meth}.new(#{tag.inspect}, text)
      end
    eof
  else
    class_eval(<<-eof, __FILE__, __LINE__ + 1)
      begin; undef #{tag_meth}; rescue NameError; end
      def #{tag_meth}(text)
        send_to_factory(#{tag.inspect}, #{meth.inspect}, text)
      end
    eof
  end
  @labels ||= SymbolHash.new(false)
  @labels.update(tag => label)
  @factory_methods ||= SymbolHash.new(false)
  @factory_methods.update(tag => meth)
  tag
end

def directive_call(tag, parser)

Returns:
  • (Directive) -
def directive_call(tag, parser)
  meth = self.class.factory_method_for_directive(tag.tag_name)
  if meth <= Directive
    meth = meth.new(tag, parser)
    meth.call
    meth
  else
    meth.call(tag, parser)
  end
end

def directive_create(tag_name, tag_buf, parser)

Returns:
  • (Directive) - the newly created directive

Parameters:
  • parser (DocstringParser) -- the parser object parsing the docstring
  • tag_buf (String) -- the tag data
  • tag_name (String) -- the name of the tag
def directive_create(tag_name, tag_buf, parser)
  meth = self.class.factory_method_for(tag_name)
  tag = send_to_factory(tag_name, meth, tag_buf)
  meth = self.class.directive_method_name(tag_name)
  send(meth, tag, parser)
end

def directive_method_name(tag_name)

def directive_method_name(tag_name)
  tag_or_directive_method_name(tag_name, 'directive')
end

def factory_method_for(tag)

Other tags:
    Since: - 0.6.0

Returns:
  • (nil) - if the tag is freeform text
  • (Class, Symbol) - the Tag class to use to parse the tag
  • (Symbol) - the factory method name for the tag

Parameters:
  • tag (Symbol) -- the tag name
def factory_method_for(tag)
  @factory_methods[tag]
end

def factory_method_for_directive(directive)

Other tags:
    Since: - 0.8.0

Returns:
  • (nil) - if the tag is freeform text
  • (Class, Symbol) - the Tag class to use to parse the tag or
  • (Symbol) - the factory method name for the tag

Parameters:
  • directive (Symbol) -- the directive name
def factory_method_for_directive(directive)
  @directive_factory_classes[directive]
end

def has_directive?(tag_name)

Returns:
  • (Boolean) - whether a directive by the given name is registered in

Parameters:
  • tag_name (#to_s) -- the name of the tag to look for
def has_directive?(tag_name)
  tag_name && respond_to?(self.class.directive_method_name(tag_name))
end

def has_tag?(tag_name)

Returns:
  • (Boolean) - whether a tag by the given name is registered in

Parameters:
  • tag_name (#to_s) -- the name of the tag to look for
def has_tag?(tag_name)
  tag_name && respond_to?(self.class.tag_method_name(tag_name))
end

def initialize(factory = Library.default_factory)

def initialize(factory = Library.default_factory)
  self.factory = factory
end

def instance

Returns:
  • (Library) - the main Library instance object.
def instance
  @instance ||= new
end

def send_to_factory(tag_name, meth, text)

def send_to_factory(tag_name, meth, text)
  meth = meth.to_s
  send_name = "parse_tag" + (meth.empty? ? "" : "_" + meth)
  if @factory.respond_to?(send_name)
    @factory.send(send_name, tag_name, text)
  else
    raise NoMethodError, "Factory #{@factory.class_name} does not implement factory method :#{meth}."
  end
end

def sorted_labels

Returns:
  • (Array, String) - the sorted labels as an array of the tag name and label
def sorted_labels
  labels.sort_by {|a| a.last.downcase }
end

def tag_create(tag_name, tag_buf)

Returns:
  • (Tag) - the newly created tag object
def tag_create(tag_name, tag_buf)
  send(self.class.tag_method_name(tag_name), tag_buf)
end

def tag_method_name(tag_name)

def tag_method_name(tag_name)
  tag_or_directive_method_name(tag_name)
end

def tag_or_directive_method_name(tag_name, type = 'tag')

Experimental RBS support (using type sampling data from the type_fusion project).

def tag_or_directive_method_name: (Symbol tag_name, ?String type) -> String

This signature was generated using 1 sample from 1 application.

def tag_or_directive_method_name(tag_name, type = 'tag')
  "#{tag_name.to_s.tr('.', '_')}_#{type}"
end