Sha256: fbba3daa04fa736d810597899e83437f758038b5d86f89b8f92b81de3d2a516d

Contents?: true

Size: 1.9 KB

Versions: 14

Compression:

Stored size: 1.9 KB

Contents

module YARD
  class EndpointHandler < Handlers::Ruby::MethodHandler
    handles method_call(:add_endpoint)
    namespace_only

    process do
      register(
        CodeObjects::MethodObject.new(namespace, name) do |m|
          m.parameters = parameters
        end,
        CodeObjects::MethodObject.new(P("DropboxApi::Client"), name) do |m|
          m.parameters = parameters
          m.group = namespace.namespace.name.downcase
        end
      )
    end

    def name
      statement.parameters.first.jump(:tstring_content, :ident).source
    end

    def parameters
      # This method is taken from YARD, ideally we would just use it but I
      # couldn't find a way to invoke it from here, so I had to copy it over.
      # It would be nice to get rid of this method and use YARD's
      # implementation instead.
      #
      # Reference to original code:
      #   YARD gem (0.9.5): lib/yard/handlers/ruby/method_handler.rb
      #   Github: https://git.io/vMLQp
      args = statement.jump(:block_var).jump(:params)
      return [] unless args.is_a? YARD::Parser::Ruby::ParameterNode

      params = []

      if args.unnamed_required_params
        params += args.unnamed_required_params.map {|a| [a.source, nil] }
      end

      if args.unnamed_optional_params
        params += args.unnamed_optional_params.map do |a|
          [a[0].source, a[1].source]
        end
      end

      params << ['*' + args.splat_param.source, nil] if args.splat_param

      if args.unnamed_end_params
        params += args.unnamed_end_params.map {|a| [a.source, nil] }
      end

      if args.named_params
        params += args.named_params.map do |a|
          [a[0].source, a[1] ? a[1].source : nil]
        end
      end

      if args.double_splat_param
        params << ['**' + args.double_splat_param.source, nil]
      end

      params << ['&' + args.block_param.source, nil] if args.block_param

      params
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
dropbox_api-0.1.18 yardoc/endpoint_handler.rb
dropbox_api-0.1.17 yardoc/endpoint_handler.rb
dropbox_api-0.1.16 yardoc/endpoint_handler.rb
dropbox_api-0.1.15 yardoc/endpoint_handler.rb
dropbox_api-0.1.14 yardoc/endpoint_handler.rb
dropbox_api-0.1.13 yardoc/endpoint_handler.rb
dropbox_api-0.1.12 yardoc/endpoint_handler.rb
dropbox_api-0.1.11 yardoc/endpoint_handler.rb
dropbox_api-0.1.10 yardoc/endpoint_handler.rb
dropbox_api-0.1.9 yardoc/endpoint_handler.rb
dropbox_api-0.1.8 yardoc/endpoint_handler.rb
dropbox_api-0.1.7 yardoc/endpoint_handler.rb
dropbox_api-0.1.6 yardoc/endpoint_handler.rb
dropbox_api-0.1.5 yardoc/endpoint_handler.rb