Class: Tapioca::Dsl::Compilers::AlchemrestRoot

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

Overview

This compiler generates RBI files for classes that inherit from ‘Alchemrest::Root`.

For example, given the following class:

class Root < Alchemrest::Root
  define_request :get_profile, Requests::GetProfile
end

This compiler will generate an RBI file ‘root.rbi` with the following content:

sig { params(params: T::Hash[Symbol, T.untyped]).returns(::Alchemrest::Result[::Profile]) }
def get_profile(params = {}); end

Constant Summary collapse

ConstantType =
type_member { { upper: T.class_of(Alchemrest::Root) } }

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.gather_constantsObject



29
30
31
# File 'lib/tapioca/dsl/compilers/alchemrest_root.rb', line 29

def self.gather_constants
  descendants_of(Alchemrest::Root)
end

Instance Method Details

#decorateObject



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/tapioca/dsl/compilers/alchemrest_root.rb', line 34

def decorate
  root.create_path(constant) do |rbi|
    constant.request_definitions.each do |name, definition|
      rbi.create_method(
        name.to_s,
        parameters: [create_opt_param('params', type: 'T::Hash[Symbol, T.untyped]', default: '{}')],
        return_type: return_type_for(definition),
      )
    end
  end
end