Class: Tapioca::Dsl::Compilers::SidekiqWorker

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

Overview

‘Tapioca::Dsl::Compilers::SidekiqWorker` generates RBI files classes that include [`Sidekiq::Worker`](github.com/mperham/sidekiq/wiki/Getting-Started).

For example, with the following class that includes ‘Sidekiq::Worker`:

~~~rb class NotifierWorker

include Sidekiq::Worker
def perform(customer_id)
  # ...
end

end ~~~

this compiler will produce the RBI file ‘notifier_worker.rbi` with the following content:

~~~rbi # notifier_worker.rbi # typed: true class NotifierWorker

sig { params(customer_id: T.untyped).returns(String) }
def self.perform_async(customer_id); end

sig { params(interval: T.any(DateTime, Time), customer_id: T.untyped).returns(String) }
def self.perform_at(interval, customer_id); end

sig { params(interval: Numeric, customer_id: T.untyped).returns(String) }
def self.perform_in(interval, customer_id); end

end ~~~

Constant Summary collapse

ConstantType =
type_member(fixed: T.class_of(::Sidekiq::Worker))

Constants included from Runtime::Reflection

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

Instance Attribute Summary

Attributes inherited from Tapioca::Dsl::Compiler

#constant, #root

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Tapioca::Dsl::Compiler

#add_error, #compiler_enabled?, handles?, #initialize, processable_constants

Methods included from T::Generic::TypeStoragePatch

#[], #type_member, #type_template

Methods included from Runtime::Reflection

#ancestors_of, #are_equal?, #class_of, #constantize, #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

Methods included from Helpers::ParamHelper

#create_block_param, #create_kw_opt_param, #create_kw_param, #create_kw_rest_param, #create_opt_param, #create_param, #create_rest_param, #create_typed_param

Constructor Details

This class inherits a constructor from Tapioca::Dsl::Compiler

Class Method Details

.gather_constantsObject



76
77
78
# File 'lib/tapioca/dsl/compilers/sidekiq_worker.rb', line 76

def self.gather_constants
  all_classes.select { |c| c < Sidekiq::Worker }
end

Instance Method Details

#decorateObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/tapioca/dsl/compilers/sidekiq_worker.rb', line 49

def decorate
  return unless constant.instance_methods.include?(:perform)

  root.create_path(constant) do |worker|
    method_def = constant.instance_method(:perform)

    async_params = compile_method_parameters_to_rbi(method_def)

    # `perform_at` and is just an alias for `perform_in` so both methods technically
    # accept a datetime, time, or numeric but we're typing them differently so they
    # semantically make sense.
    at_params = [
      create_param("interval", type: "T.any(DateTime, Time)"),
      *async_params,
    ]
    in_params = [
      create_param("interval", type: "Numeric"),
      *async_params,
    ]

    generate_perform_method(worker, "perform_async", async_params)
    generate_perform_method(worker, "perform_at", at_params)
    generate_perform_method(worker, "perform_in", in_params)
  end
end