Sha256: 69281e70835b9437ff3634c62fac9e7805a53d1928f2c1c78797ea5f0bdbb417

Contents?: true

Size: 1.92 KB

Versions: 16

Compression:

Stored size: 1.92 KB

Contents

module YARD
  module Handlers
    module Ruby
      class HandlesExtension
        def initialize(name) @name = name end
        def matches?(node) raise NotImplementedError end
        protected
        attr_reader :name
      end
      
      class MethodCallWrapper < HandlesExtension
        def matches?(node)
          case node.type
          when :var_ref
            if !node.parent || node.parent.type == :list
              return true if node[0].type == :ident && node[0][0] == name
            end
          when :fcall, :command
            return true if node[0][0] == name
          when :call, :command_call
            return true if node[2][0] == name
          end
          false
        end
      end
      
      class TestNodeWrapper < HandlesExtension
        def matches?(node) !node.send(name).is_a?(FalseClass) end
      end
      
      class Base < Handlers::Base
        class << self
          include Parser::Ruby
          
          def method_call(name)
            MethodCallWrapper.new(name.to_s)
          end
          
          def meta_type(meth)
            TestNodeWrapper.new(meth.to_s + "?")
          end
          
          def handles?(node)
            handlers.any? do |a_handler| 
              case a_handler 
              when Symbol
                a_handler == node.type
              when String
                node.source == a_handler
              when Regexp
                node.source =~ a_handler
              when Parser::Ruby::AstNode
                a_handler == node
              when HandlesExtension
                a_handler.matches?(node)
              end
            end
          end
        end

        include Parser::Ruby
        
        def parse_block(inner_node, opts = {})
          push_state(opts) do
            nodes = inner_node.type == :list ? inner_node.children : [inner_node]
            parser.process(nodes)
          end
        end
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
yard-0.5.8 lib/yard/handlers/ruby/base.rb
yard-0.5.7 lib/yard/handlers/ruby/base.rb
yard-0.5.6 lib/yard/handlers/ruby/base.rb
yard-0.5.5 lib/yard/handlers/ruby/base.rb
yard-0.5.4 lib/yard/handlers/ruby/base.rb
yard-0.5.3 lib/yard/handlers/ruby/base.rb
yard-0.5.2 lib/yard/handlers/ruby/base.rb
yard-0.5.1p1 lib/yard/handlers/ruby/base.rb
yard-0.5.1 lib/yard/handlers/ruby/base.rb
yard-0.5.0 lib/yard/handlers/ruby/base.rb
yard-0.4.0 lib/yard/handlers/ruby/base.rb
yard-0.2.3.5 lib/yard/handlers/ruby/base.rb
yard-0.2.3.4 lib/yard/handlers/ruby/base.rb
yard-0.2.3.2 lib/yard/handlers/ruby/base.rb
yard-0.2.3.3 lib/yard/handlers/ruby/base.rb
yard-0.2.3 lib/yard/handlers/ruby/base.rb