Class: Tapioca::Dsl::Compilers::GrapeEndpoints

Inherits:
Tapioca::Dsl::Compiler
  • Object
show all
Extended by:
T::Sig
Includes:
Helpers::GrapeConstantsHelper
Defined in:
lib/tapioca/dsl/compilers/grape_endpoints.rb

Overview

‘Tapioca::Compilers::GrapeEndpoints` decorates RBI files for subclasses of `Grape::API::Instance`.

For example, with the following ‘Grape::API::Instance` subclass:

~~~rb class API < Grape::API::Instance

helpers Helpers

end ~~~

this compiler will produce the RBI file ‘api.rbi` with the following content: ~~~rbi # api.rbi # typed: true

class API

extend GeneratedRoutingMethods

module GeneratedRoutingMethods
  sig { params(args: T.untyped, blk: T.nilable(T.proc.bind(PrivateEndpoint).void)).void }
  def get(*args, &blk); end

  # ...

  sig do
    params(
      param: Symbol,
      options: T.nilable(T::Hash[Symbol, T.untyped]),
      blk: T.nilable(T.proc.bind(T.class_of(PrivateAPIInstance)).void)
    ).void
  end
  def route_param(param, options = nil, &blk); end
end

class PrivateAPIInstance < ::Grape::API::Instance
  extend GeneratedRoutingMethods
end

class PrivateEndpoint < ::Grape::Endpoint
  include Helpers
end

end ~~~

Constant Summary collapse

ConstantType =
type_member { { fixed: T.class_of(::Grape::API::Instance) } }
CALLBACKS_METHODS =
T.let(
  [:before, :before_validation, :after_validation, :after, :finally].freeze,
  T::Array[Symbol],
)
HTTP_VERB_METHODS =
T.let(
  [:get, :post, :put, :patch, :delete, :head, :options].freeze,
  T::Array[Symbol],
)

Constants included from Helpers::GrapeConstantsHelper

Helpers::GrapeConstantsHelper::APIInstanceClassName, Helpers::GrapeConstantsHelper::CallbacksMethodsModuleName, Helpers::GrapeConstantsHelper::EndpointClassName, Helpers::GrapeConstantsHelper::RequestResponseMethodsModuleName, Helpers::GrapeConstantsHelper::RoutingMethodsModuleName

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.gather_constantsObject



80
81
82
# File 'lib/tapioca/dsl/compilers/grape_endpoints.rb', line 80

def gather_constants
  ::Grape::API::Instance.descendants
end

Instance Method Details

#decorateObject



68
69
70
71
72
73
74
# File 'lib/tapioca/dsl/compilers/grape_endpoints.rb', line 68

def decorate
  create_classes_and_includes

  create_callbacks_methods
  create_request_response_methods
  create_routing_methods
end