Method: Im::Loader::Config#on_load

Defined in:
lib/im/loader/config.rb

#on_load(cpath = :ANY, &block) ⇒ Object

Configure a block to be invoked once a certain constant path is loaded. Supports multiple callbacks, and if there are many, they are executed in the order in which they were defined.

loader.on_load("SomeApiClient") do |klass, _abspath|
  klass.endpoint = "https://api.dev"
end

Can also be configured for any constant loaded:

loader.on_load do |cpath, value, abspath|
  # ...
end

Raises:

  • (TypeError)


230
231
232
233
234
# File 'lib/im/loader/config.rb', line 230

def on_load(cpath = :ANY, &block)
  raise TypeError, "on_load only accepts strings" unless cpath.is_a?(String) || cpath == :ANY

  mutex.synchronize { _on_load(cpath, &block) }
end