Class: Tapioca::Compilers::Dsl::ActionMailer

Inherits:
Base
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/tapioca/compilers/dsl/action_mailer.rb

Overview

`Tapioca::Compilers::Dsl::ActionMailer` generates RBI files for subclasses of [`ActionMailer::Base`](api.rubyonrails.org/classes/ActionMailer/Base.html).

For example, with the following `ActionMailer` subclass:

~~~rb class NotifierMailer < ActionMailer::Base

def notify_customer(customer_id)
  # ...
end

end ~~~

this generator will produce the RBI file `notifier_mailer.rbi` with the following content:

~~~rbi # notifier_mailer.rbi # typed: true class NotifierMailer

sig { params(customer_id: T.untyped).returns(::ActionMailer::MessageDelivery) }
def self.notify_customer(customer_id); end

end ~~~

Constant Summary

Constants included from Reflection

Reflection::ANCESTORS_METHOD, Reflection::CLASS_METHOD, Reflection::CONSTANTS_METHOD, Reflection::EQUAL_METHOD, Reflection::METHOD_METHOD, Reflection::NAME_METHOD, Reflection::OBJECT_ID_METHOD, Reflection::PRIVATE_INSTANCE_METHODS_METHOD, Reflection::PROTECTED_INSTANCE_METHODS_METHOD, Reflection::PUBLIC_INSTANCE_METHODS_METHOD, Reflection::SINGLETON_CLASS_METHOD, Reflection::SUPERCLASS_METHOD

Instance Attribute Summary

Attributes inherited from Base

#errors, #processable_constants

Instance Method Summary collapse

Methods inherited from Base

#add_error, #handles?, #initialize

Methods included from Reflection

#ancestors_of, #are_equal?, #class_of, #constants_of, #descendants_of, #inherited_ancestors_of, #method_of, #name_of, #name_of_type, #object_id_of, #private_instance_methods_of, #protected_instance_methods_of, #public_instance_methods_of, #qualified_name_of, #signature_of, #singleton_class_of, #superclass_of

Constructor Details

This class inherits a constructor from Tapioca::Compilers::Dsl::Base

Instance Method Details

#decorate(root, constant) ⇒ Object


40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/tapioca/compilers/dsl/action_mailer.rb', line 40

def decorate(root, constant)
  root.create_path(constant) do |mailer|
    constant.action_methods.to_a.each do |mailer_method|
      method_def = constant.instance_method(mailer_method)
      parameters = compile_method_parameters_to_rbi(method_def)
      mailer.create_method(
        mailer_method,
        parameters: parameters,
        return_type: "::ActionMailer::MessageDelivery",
        class_method: true
      )
    end
  end
end

#gather_constantsObject


56
57
58
# File 'lib/tapioca/compilers/dsl/action_mailer.rb', line 56

def gather_constants
  descendants_of(::ActionMailer::Base).reject(&:abstract?)
end