Module: Merb::Slices

Module | Merb::Slices
In: | lib/merb-slices/controller_mixin.rb lib/merb-slices/module.rb lib/merb-slices/module_mixin.rb

### Methods

[] activate activate_by_file config deactivate deactivate_by_file each_slice exists? filename2module files named_routes paths register register_slices_from_search_path! reload reload_by_file slice_files_from_search_path slice_names slices start_dynamic_loader! stop_dynamic_loader! unregister

### Classes and Modules

Module Merb::Slices::ControllerMixin
Module Merb::Slices::ModuleMixin
Module Merb::Slices::Support
Class Merb::Slices::Activate
Class Merb::Slices::DynamicLoader
Class Merb::Slices::Initialize
Class Merb::Slices::Loader

### Constants

VERSION | = | "0.9.8"

### External Aliases

activate_by_file | -> | register_and_load

### Public Class methods

[](module_name)

Retrieve a slice module by name

@param <to_s> The slice module to check for. @return <Module> The slice module itself.

activate(slice_module)

Activate a Slice module at runtime

Looks for previously registered slices; then searches :search_path for matches.

@param slice_module<to_s> Usually a string of version of the slice module name.

activate_by_file(slice_file)

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’)

config()

@return <Hash>

      The configuration loaded from Merb.root / "config/slices.yml" or, if
      the load fails, an empty hash.

deactivate(slice_module)

Deactivate a Slice module at runtime

@param slice_module<to_s> The Slice module to unregister.

deactivate_by_file(slice_file)

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.

each_slice(&block)

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.

exists?(module_name)

Check whether a Slice exists

@param <to_s> The slice module to check for.

filename2module(slice_file)

Helper method to transform a slice filename to a module Symbol

files()

A lookup for finding a Slice module‘s slice file path

@return <Hash> A Hash mapping module names to slice files. @note This is unaffected by deactivating a slice; used to reload slices by name.

named_routes()

@return <Hash[Hash]>

      A Hash mapping between slice identifiers and non-prefixed named routes.

paths()

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(slice_file, force = true)

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’)

register_slices_from_search_path!()

Look for any slices in Merb.root / ‘slices’ (the default) or if given, Merb::Plugins.config[:merb_slices][:search_path] (String/Array)

reload(slice_module)

Reload a Slice at runtime

@param slice_module<to_s> The Slice module to reload.

reload_by_file(slice_file)

Reload a Slice at runtime by specifying its slice file

@param slice_file<String> The Slice location of the slice init file to reload.

slice_files_from_search_path()

Slice file locations from all search paths; this default to host-app/slices.

Look for any slices in those default locations or if given, Merb::Plugins.config[:merb_slices][:search_path] (String/Array). Specify files, glob patterns or paths containing slices.

slice_names()

All registered Slice module names

@return <Array[String]> A sorted array of all slice module names.

slices()

All registered Slice modules

@return <Array[Module]> A sorted array of all slice modules.

start_dynamic_loader!(interval = nil)

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.

stop_dynamic_loader!()

Stop watching search paths to dynamically load/unload slices at runtime

unregister(slice_module)

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.

[Validate]