Method: Needle::Container#require
- Defined in:
- lib/needle/container.rb
#require(file, target_name, registration_method = :register_services) ⇒ Object
Require the given file, and then invoke the given registration method on the target module. The container will be passed as the sole parameter to the registration method. This allows you to easily decentralize the definition of services.
Usage:
container.require( "app/services", "App::Services" )
# in app/services.rb:
module App
module Services
def register_services( container )
...
end
module_function :register_services
end
end
353 354 355 356 357 358 359 360 361 362 363 364 365 366 |
# File 'lib/needle/container.rb', line 353 def require( file, target_name, registration_method=:register_services ) Kernel.require file if target_name.is_a?( Module ) target = target_name else target = Object target_name.to_s.split( /::/ ).each do |element| target = target.const_get( element ) end end target.__send__( registration_method, self ) end |