Module | Merb::Slices |
In: |
lib/merb-slices/controller_mixin.rb
lib/merb-slices/module.rb lib/merb-slices/module_mixin.rb |
VERSION | = | "0.9.8" |
activate_by_file | -> | register_and_load |
Retrieve a slice module by name
@param <to_s> The slice module to check for. @return <Module> The slice module itself.
Register a Slice by its gem/lib init file path and activate it at runtime
Normally slices are loaded using BootLoaders on application startup. This method gives you the possibility to add slices at runtime, all without restarting your app. Together with deactivate it allows you to enable/disable slices at any time. The router is reloaded to incorporate any changes. Disabled slices will be skipped when routes are regenerated.
@param slice_file<String> The path of the gem ‘init file‘
@example Merb::Slices.activate_by_file(’/path/to/gems/slice-name/lib/slice-name.rb’)
@return <Hash>
The configuration loaded from Merb.root / "config/slices.yml" or, if the load fails, an empty hash.
Deactivate a Slice module at runtime
@param slice_module<to_s> The Slice module to unregister.
Deactivate a Slice module at runtime by specifying its slice file
@param slice_file<String> The Slice location of the slice init file to unregister.
Iterate over all registered slices
By default iterates alphabetically over all registered modules. If Merb::Plugins.config[:merb_slices][:queue] is set, only the defined modules are loaded in the given order. This can be used to selectively load slices, and also maintain load-order for slices that depend on eachother.
@yield Iterate over known slices and pass in the slice module. @yieldparam module<Module> The Slice module.
A lookup for finding a Slice module‘s path
@return <Hash> A Hash mapping module names to root paths. @note Whenever a slice is deactivated, its path is removed from the lookup.
Register a Slice by its gem/lib path for loading at startup
This is referenced from gems/<slice-gem-x.x.x>/lib/<slice-gem>.rb Which gets loaded for any gem. The name of the file is used to extract the Slice module name.
@param slice_file<String> The path of the gem ‘init file’ @param force<Boolean> Whether to overwrite currently registered slice or not.
@return <Module> The Slice module that has been setup.
@example Merb::Slices::register(FILE) @example Merb::Slices::register(’/path/to/my-slice/lib/my-slice.rb’)
Reload a Slice at runtime
@param slice_module<to_s> The Slice module to reload.
Reload a Slice at runtime by specifying its slice file
@param slice_file<String> The Slice location of the slice init file to reload.
Watch all specified search paths to dynamically load/unload slices at runtime
If a valid slice is found it‘s automatically registered and activated; once a slice is removed (or renamed to not match the convention), it will be unregistered and deactivated. Runs in a Thread.
@example Merb::BootLoader.after_app_loads { Merb::Slices.start_dynamic_loader! }
@param interval<Numeric>
The interval in seconds of checking the search path(s) for changes.
Unregister a Slice at runtime
This clears the slice module from ObjectSpace and reloads the router. Since the router doesn‘t add routes for any disabled slices this will correctly reflect the app‘s routing state.
@param slice_module<to_s> The Slice module to unregister.