Sha256: 9a9a2e1c0e94a9835b791b730711703c86c5af94ab78915e08c6f873a3e05940

Contents?: true

Size: 1.46 KB

Versions: 5

Compression:

Stored size: 1.46 KB

Contents

class YARD::Handlers::Ruby::MethodHandler < YARD::Handlers::Ruby::Base
  handles :def, :defs
  
  def process
    nobj = namespace
    mscope = scope
    if statement.type == :defs
      meth = statement[2][0]
      nobj = P(namespace, statement[0].source) unless statement[0].source == "self"
      args = format_args(statement[3])
      blk = statement[4]
      mscope = :class
    else
      meth = statement[0][0]
      args = format_args(statement[1])
      blk = statement[2]
    end
    
    obj = register MethodObject.new(nobj, meth, mscope) do |o| 
      o.visibility = visibility 
      o.source = statement.source
      o.signature = method_signature(meth)
      o.explicit = true
      o.parameters = args
    end
    
    parse_block(blk, :owner => obj) # mainly for yield/exceptions
  end
  
  def format_args(args)
    args = args.jump(:params)
    params = []
    params += args.required_params.map {|a| [a.source, nil] } if args.required_params
    params += args.optional_params.map {|a| [a[0].source, a[1].source] } if args.optional_params
    params << ["*" + args.splat_param.source, nil] if args.splat_param
    params += args.required_end_params.map {|a| [a.source, nil] } if args.required_end_params
    params << ["&" + args.block_param.source, nil] if args.block_param
    params
  end
  
  def method_signature(method_name)
    if statement[1]
      "def #{method_name}(#{statement[1].jump(:params).source})"
    else
      "def #{method_name}"
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
yard-0.2.3.5 lib/yard/handlers/ruby/method_handler.rb
yard-0.2.3.4 lib/yard/handlers/ruby/method_handler.rb
yard-0.2.3.2 lib/yard/handlers/ruby/method_handler.rb
yard-0.2.3.3 lib/yard/handlers/ruby/method_handler.rb
yard-0.2.3 lib/yard/handlers/ruby/method_handler.rb