Sha256: e116fd176a50caa76afea46fd6a6e967c91906cc1509157d2a5601c6863c0b40

Contents?: true

Size: 1.88 KB

Versions: 7

Compression:

Stored size: 1.88 KB

Contents

# typed: strict
# frozen_string_literal: true

begin
  require "action_mailer"
rescue LoadError
  return
end

module Tapioca
  module Dsl
    module Compilers
      # `Tapioca::Dsl::Compilers::ActionMailer` generates RBI files for subclasses of
      # [`ActionMailer::Base`](https://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 compiler 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
      # ~~~
      class ActionMailer < Compiler
        extend T::Sig

        ConstantType = type_member { { fixed: T.class_of(::ActionMailer::Base) } }

        sig { override.void }
        def decorate
          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

        class << self
          extend T::Sig

          sig { override.returns(T::Enumerable[Module]) }
          def gather_constants
            descendants_of(::ActionMailer::Base).reject(&:abstract?)
          end
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
devcycle-ruby-server-sdk-2.0.0 vendor/bundle/ruby/3.0.0/gems/tapioca-0.11.1/lib/tapioca/dsl/compilers/action_mailer.rb
tapioca-0.11.1 lib/tapioca/dsl/compilers/action_mailer.rb
tapioca-0.11.0 lib/tapioca/dsl/compilers/action_mailer.rb
tapioca-0.10.5 lib/tapioca/dsl/compilers/action_mailer.rb
tapioca-0.10.4 lib/tapioca/dsl/compilers/action_mailer.rb
tapioca-0.10.3 lib/tapioca/dsl/compilers/action_mailer.rb
tapioca-0.10.2 lib/tapioca/dsl/compilers/action_mailer.rb