Class: YARD::Handlers::Ruby::MethodHandler
- Inherits:
-
Base
- Object
- YARD::Handlers::Base
- Base
- YARD::Handlers::Ruby::MethodHandler
- Defined in:
- lib/yard/handlers/ruby/method_handler.rb
Constant Summary
Constants included from YARD::CodeObjects
BUILTIN_ALL, BUILTIN_CLASSES, BUILTIN_EXCEPTIONS, BUILTIN_EXCEPTIONS_HASH, BUILTIN_MODULES, CONSTANTMATCH, CSEP, CSEPQ, ISEP, ISEPQ, METHODMATCH, METHODNAMEMATCH, NAMESPACEMATCH, NSEP, NSEPQ
Instance Method Summary
Methods inherited from Base
handles?, meta_type, method_call, #parse_block
Methods included from YARD::Parser::Ruby
Methods inherited from YARD::Handlers::Base
clear_subclasses, #ensure_loaded!, handlers, handles, handles?, #initialize, namespace_only, namespace_only?, #parse_block, #push_state, #register, subclasses
Constructor Details
This class inherits a constructor from YARD::Handlers::Base
Instance Method Details
- (Object) format_args(args)
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/yard/handlers/ruby/method_handler.rb', line 53 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 |
- (Object) method_signature(method_name)
64 65 66 67 68 69 70 |
# File 'lib/yard/handlers/ruby/method_handler.rb', line 64 def method_signature(method_name) if statement[1] "def #{method_name}(#{statement[1].jump(:params).source})" else "def #{method_name}" end end |
- (Object) process
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/yard/handlers/ruby/method_handler.rb', line 4 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 if mscope == :instance && meth == "initialize" unless obj.has_tag?(:return) obj.docstring.add_tag(YARD::Tags::Tag.new(:return, "a new instance of #{namespace.name}", namespace.name.to_s)) end elsif mscope == :class && obj.docstring.blank? && %w(inherited included extended method_added method_removed method_undefined).include?(meth) obj.docstring.add_tag(YARD::Tags::Tag.new(:private, nil)) elsif meth.to_s =~ /\?$/ if obj.tag(:return) && (obj.tag(:return).types || []).empty? obj.tag(:return).types = ['Boolean'] elsif obj.tag(:return).nil? obj.docstring.add_tag(YARD::Tags::Tag.new(:return, "", "Boolean")) end end if info = obj.attr_info if meth.to_s =~ /=$/ # writer info[:write] = obj if info[:read] else info[:read] = obj if info[:write] end end parse_block(blk, :owner => obj) # mainly for yield/exceptions end |