Module: Tapioca::Runtime::Trackers::Autoload
- Extended by:
- T::Sig, Tracker
- Defined in:
- lib/tapioca/runtime/trackers/autoload.rb
Constant Summary collapse
- NOOP_METHOD =
->(*_args, **_kwargs, &_block) {}
Class Method Summary collapse
-
.eager_load_all! ⇒ Object
: -> void.
-
.register(constant_name) ⇒ Object
: (String constant_name) -> void.
-
.with_disabled_exits(&block) ⇒ Object
: [Result] { -> Result } -> Result.
Methods included from Tracker
disable!, enabled?, extended, with_disabled_tracker
Class Method Details
.eager_load_all! ⇒ Object
: -> void
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/tapioca/runtime/trackers/autoload.rb', line 19 def eager_load_all! with_disabled_exits do until @constant_names_registered_for_autoload.empty? # Grab the next constant name constant_name = T.must(@constant_names_registered_for_autoload.shift) # Trigger autoload by constantizing the registered name Reflection.constantize(constant_name, inherit: true) end end end |
.register(constant_name) ⇒ Object
: (String constant_name) -> void
31 32 33 34 35 |
# File 'lib/tapioca/runtime/trackers/autoload.rb', line 31 def register(constant_name) return unless enabled? @constant_names_registered_for_autoload << constant_name end |
.with_disabled_exits(&block) ⇒ Object
: [Result] { -> Result } -> Result
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/tapioca/runtime/trackers/autoload.rb', line 38 def with_disabled_exits(&block) original_abort = Kernel.instance_method(:abort) original_exit = Kernel.instance_method(:exit) begin Kernel.define_method(:abort, NOOP_METHOD) Kernel.define_method(:exit, NOOP_METHOD) Tapioca.silence_warnings do block.call end ensure Kernel.define_method(:exit, original_exit) Kernel.define_method(:abort, original_abort) end end |