Sha256: db88f6442c510d760942cb618b65a0f52eb8eac521d8a51e639291d21a859f48

Contents?: true

Size: 1.94 KB

Versions: 8

Compression:

Stored size: 1.94 KB

Contents

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 ||= ""
        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, args = $1, $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

8 entries across 7 versions & 2 rubygems

Version Path
abaci-0.3.0 vendor/bundle/gems/yard-0.9.2/lib/yard/tags/overload_tag.rb
abaci-0.3.0 vendor/bundle/gems/yard-0.9.1/lib/yard/tags/overload_tag.rb
yard-0.9.5 lib/yard/tags/overload_tag.rb
yard-0.9.4 lib/yard/tags/overload_tag.rb
yard-0.9.3 lib/yard/tags/overload_tag.rb
yard-0.9.2 lib/yard/tags/overload_tag.rb
yard-0.9.1 lib/yard/tags/overload_tag.rb
yard-0.9.0 lib/yard/tags/overload_tag.rb