Class: Tapioca::Compilers::FactoryBot
- Inherits:
-
Dsl::Compiler
- Object
- Dsl::Compiler
- Tapioca::Compilers::FactoryBot
- Defined in:
- lib/tapioca/dsl/compilers/factory_bot.rb
Overview
: [ConstantType = singleton(::FactoryBot::Sorbet)]
Class Method Summary collapse
Instance Method Summary collapse
-
#decorate ⇒ Object
: -> void.
Class Method Details
.gather_constants ⇒ Object
: -> T::Enumerable
13 14 15 |
# File 'lib/tapioca/dsl/compilers/factory_bot.rb', line 13 def gather_constants [::FactoryBot::Sorbet] end |
Instance Method Details
#decorate ⇒ Object
: -> void
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/tapioca/dsl/compilers/factory_bot.rb', line 20 def decorate root.create_path(constant) do |mod| ::FactoryBot.factories.each do |factory| begin klass = factory.build_class rescue NameError next end mod.create_method(factory.name.to_s) do |method| method.add_param('strategy') method.add_rest_param('args') method.add_block_param('block') method.add_sig do |sig| sig.add_param('strategy', 'Symbol') sig.add_param('args', 'T.anything') sig.add_param('block', 'NilClass') sig.return_type = klass.to_s end method.add_sig do |sig| sig.type_params << 'R' sig.add_param('strategy', 'Symbol') sig.add_param('args', 'T.anything') sig.add_param('block', "T.proc.params(arg0: #{klass}).returns(T.type_parameter(:R))") sig.return_type = 'T.type_parameter(:R)' end end end end end |