Sha256: 133f802bbabcf91b49d23ade04fa49571a2cdec7877bafaa75608b6c0e661740

Contents?: true

Size: 1.86 KB

Versions: 10

Compression:

Stored size: 1.86 KB

Contents

# typed: strict
# frozen_string_literal: true

require "parlour"

begin
  require "action_mailer"
rescue LoadError
  return
end

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

        sig { override.params(root: Parlour::RbiGenerator::Namespace, constant: T.class_of(::ActionMailer::Base)).void }
        def decorate(root, constant)
          root.path(constant) do |k|
            constant.action_methods.to_a.each do |mailer_method|
              method_def = constant.instance_method(mailer_method)
              parameters = compile_method_parameters_to_parlour(method_def)
              create_method(
                k,
                mailer_method,
                parameters: parameters,
                return_type: '::ActionMailer::MessageDelivery',
                class_method: true
              )
            end
          end
        end

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

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
tapioca-0.4.10 lib/tapioca/compilers/dsl/action_mailer.rb
tapioca-0.4.9 lib/tapioca/compilers/dsl/action_mailer.rb
tapioca-0.4.8 lib/tapioca/compilers/dsl/action_mailer.rb
tapioca-0.4.7 lib/tapioca/compilers/dsl/action_mailer.rb
tapioca-0.4.6 lib/tapioca/compilers/dsl/action_mailer.rb
tapioca-0.4.5 lib/tapioca/compilers/dsl/action_mailer.rb
tapioca-0.4.4 lib/tapioca/compilers/dsl/action_mailer.rb
tapioca-0.4.3 lib/tapioca/compilers/dsl/action_mailer.rb
tapioca-0.4.2 lib/tapioca/compilers/dsl/action_mailer.rb
tapioca-0.4.1 lib/tapioca/compilers/dsl/action_mailer.rb