Sha256: ee3d0f1dacd7f2007c4afa7af10e76959ad716118b8deed1328b870ccb18af5c

Contents?: true

Size: 2 KB

Versions: 63

Compression:

Stored size: 2 KB

Contents

# frozen_string_literal: true
module YARD
  module Tags
    class OverloadTag < Tag
      attr_reader :signature, :parameters, :docstring

      def initialize(tag_name, text)
        super(tag_name, nil)
        parse_tag(text)
        parse_signature
      end

      def tag(name) docstring.tag(name) end
      def tags(name = nil) docstring.tags(name) end
      def has_tag?(name) docstring.has_tag?(name) end

      def object=(value)
        super(value)
        docstring.object = value
        docstring.tags.each {|tag| tag.object = value }
      end

      def name(prefix = false)
        return @name unless prefix
        object.scope == :class ? @name.to_s : "#{object.send(:sep)}#{@name}"
      end

      def method_missing(*args, &block)
        object.send(*args, &block)
      end

      def type
        object.type
      end

      def is_a?(other)
        object.is_a?(other) || self.class >= other.class || false
      end
      alias kind_of? is_a?

      private

      def parse_tag(text)
        @signature, text = *text.split(/\r?\n/, 2)
        @signature.strip!
        text ||= String.new("")
        numspaces = text[/\A(\s*)/, 1].length
        text.gsub!(/^[ \t]{#{numspaces}}/, '')
        text.strip!
        @docstring = Docstring.new(text, nil)
      end

      def parse_signature
        if signature =~ /^(?:def\s)?\s*(#{CodeObjects::METHODMATCH})(?:(?:\s+|\s*\()(.*)(?:\)\s*$)?)?/m
          meth = $1
          args = $2
          meth.gsub!(/\s+/, '')
          # FIXME: refactor this code to not make use of the Handlers::Base class (tokval_list should be moved)
          toks = YARD::Parser::Ruby::Legacy::TokenList.new(args)
          args = YARD::Handlers::Ruby::Legacy::Base.new(nil, nil).send(:tokval_list, toks, :all)
          args = args.map do |a|
            k, v = *a.split(/:|=/, 2)
            [k.strip.to_s + (a[k.size, 1] == ':' ? ':' : ''), (v ? v.strip : nil)]
          end if args
          @name = meth.to_sym
          @parameters = args
        end
      end
    end
  end
end

Version data entries

63 entries across 62 versions & 9 rubygems

Version Path
kinetic_sdk-5.0.29 gems/yard-0.9.36/lib/yard/tags/overload_tag.rb
kinetic_sdk-5.0.28 gems/yard-0.9.36/lib/yard/tags/overload_tag.rb
direct7-0.0.18 vendor/bundle/ruby/2.7.0/gems/yard-0.9.34/lib/yard/tags/overload_tag.rb
direct7-0.0.17 vendor/bundle/ruby/2.7.0/gems/yard-0.9.34/lib/yard/tags/overload_tag.rb
direct7-0.0.16 vendor/bundle/ruby/2.7.0/gems/yard-0.9.34/lib/yard/tags/overload_tag.rb
yard-0.9.37 lib/yard/tags/overload_tag.rb
kinetic_sdk-5.0.27 gems/yard-0.9.36/lib/yard/tags/overload_tag.rb
kinetic_sdk-5.0.26 gems/yard-0.9.36/lib/yard/tags/overload_tag.rb
kinetic_sdk-5.0.25 gems/yard-0.9.25/lib/yard/tags/overload_tag.rb
kinetic_sdk-5.0.24 gems/yard-0.9.25/lib/yard/tags/overload_tag.rb
direct7-0.0.13 vendor/bundle/ruby/2.7.0/gems/yard-0.9.34/lib/yard/tags/overload_tag.rb
yard-0.9.36 lib/yard/tags/overload_tag.rb
yard-0.9.35 lib/yard/tags/overload_tag.rb
direct7-0.0.12 vendor/bundle/ruby/2.7.0/gems/yard-0.9.34/lib/yard/tags/overload_tag.rb
kinetic_sdk-5.0.23 gems/yard-0.9.25/lib/yard/tags/overload_tag.rb
getargv-0.3.3-universal-darwin vendor/bundle/ruby/3.3.0/gems/yard-0.9.34/lib/yard/tags/overload_tag.rb
direct7-0.0.11 vendor/bundle/ruby/2.7.0/gems/yard-0.9.34/lib/yard/tags/overload_tag.rb
kinetic_sdk-5.0.22 gems/yard-0.9.25/lib/yard/tags/overload_tag.rb
kinetic_sdk-5.0.21 gems/yard-0.9.25/lib/yard/tags/overload_tag.rb
yard-0.9.34 lib/yard/tags/overload_tag.rb