class Tapioca::Compilers::Dsl::ActiveJob
`Tapioca::Compilers::Dsl::ActiveJob` generates RBI
files for subclasses of [`ActiveJob::Base`](api.rubyonrails.org/classes/ActiveJob/Base.html).
For example, with the following `ActiveJob` subclass:
~~~rb class NotifyUserJob < ActiveJob::Base
sig { params(user: User).returns(Mail) } def perform(user) # ... end
end ~~~
this generator will produce the RBI
file `notify_user_job.rbi` with the following content:
~~~rbi # notify_user_job.rbi # typed: true class NotifyUserJob
sig { params(user: User).returns(T.any(NotifyUserJob, FalseClass)) } def self.perform_later(user); end sig { params(user: User).returns(Mail) } def self.perform_now(user); end
end ~~~
Public Instance Methods
decorate(root, constant)
click to toggle source
# File lib/tapioca/compilers/dsl/active_job.rb, line 44 def decorate(root, constant) return unless constant.instance_methods(false).include?(:perform) root.create_path(constant) do |job| method = constant.instance_method(:perform) parameters = compile_method_parameters_to_rbi(method) return_type = compile_method_return_type_to_rbi(method) job.create_method( "perform_later", parameters: parameters, return_type: "T.any(#{constant.name}, FalseClass)", class_method: true ) job.create_method( "perform_now", parameters: parameters, return_type: return_type, class_method: true ) end end
gather_constants()
click to toggle source
# File lib/tapioca/compilers/dsl/active_job.rb, line 69 def gather_constants descendants_of(::ActiveJob::Base) end